




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































The Power of Algorithms
Inspiration and Examples in Everyday Life
123
Editors Giorgio Ausiello Dip. di Informatica e Sistemistica Università di Roma “La Sapienza” Rome, Italy
Rossella Petreschi Dipartimento di Informatica Università di Roma “La Sapienza” Rome, Italy
First published in Italian in 2010 by Mondadori Education S.p.A., Milano as “L’informatica invisibile: Come gli algoritmi regolano la nostra vita : : : e tutto il resto”
ISBN 978-3-642-39651-9 ISBN 978-3-642-39652-6 (eBook) DOI 10.1007/978-3-642-39652- Springer Heidelberg New York Dordrecht London
Library of Congress Control Number: 2013952981
© Springer-Verlag Berlin Heidelberg 2013 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Printed on acid-free paper
Springer is part of Springer Science+Business Media (www.springer.com)
vi Preface
In any case, it was the advent of computers and computer science that led to the word ‘algorithm’ becoming known to a wide range of people, so much so that even in 1977 Donald Knuth (one of the founding fathers of computer science) wrote:
Until ten years ago the word algorithm was unknown to the vast majority of educated people and, to tell the truth, there was little need for it anyway. The furiously rapid development of computer science, whose primary focus is the study of algorithms, has changed this situation: today the word algorithm is indispensable. Formalizing a problem as an algorithm thus leads to a better grasp of the argument to be dealt with, compared to tackling it using traditional reasoning. Indeed, a person who knows how to handle algorithms acquires a capacity for introspection that she/he will find useful not only in writing good programs for a computer, but also in achieving improved understanding of many other kinds of problem in other fields. Knuth, again, in his book “The Art of Computer Programming”, asserts that:
If it is true that one doesn’t truly understand a problem in depth until one has to teach it to someone else, it is even truer that nothing is understood more completely than something one has to teach to a machine, that is, than something which has to be expressed by way of an algorithm.
Unfortunately, the precision demanded by the algorithmic approach (the algorithm has to be independent of the data to which it is applied and the rules it employs have to be elementary, that is, very simple and unambiguous), although useful as a means of mental development, limits the types of problem for which it can be adopted. To convince oneself of this just think of the fact that no algorithm exists for teaching “how to live a happy life”. Alternatively, as a more rigorous demonstration of these limitations, we cite one of the most important findings of twentieth century logic, whereby Alan Turing (in the wake of Gödel’s incompleteness proof) showed that no algorithm exists that would be capable of deciding whether or not a logical formula asserting a property of arithmetic is a theorem (see Chaps. 1 and 3). For every algorithm two fundamental components can be identified: the determi- nation of the appropriate algorithmic design technique (based on the structure of the problem) and the clear understanding of the mathematical nucleus of the problem. These two components interact closely with each other, thus it is not so much that algorithmic ideas just find solutions to well-stated problems, as that they function as a language that enables a particular problem to be expressed in the first place. It is for this reason that David Harel, in his 1987 book “Algorithmics: The Spirit of Computing” was able, without fear of contradiction, to define the algorithm as “the soul of computer science”. The earliest algorithms can be traced back as far as 2000 BCE; Mesopotamian clay tablets and Egyptian papyrus have been found bearing the first examples of procedures for calculation defined in fairly rigorous ways. Over the successive millennia thereafter humans made ever-increasing use of algorithms to solve problems arising in widely diverse fields: from measurements of land areas to astronomy, from trade to finance, and from the design of civil engineering projects
Preface vii
to the study of physical phenomena. All of these significantly contributed, in the eighteenth and nineteenth centuries, to the first products of the industrial revolution. Notwithstanding this, it was not until the twentieth century that the formal definition of the concept of algorithm began to be tackled. This was done pri- marily by mathematical logicians, such as Alonzo Church and the already-cited Alan Turing, in a series of theoretical investigations which turned out to be the indispensable groundwork for subsequent development of the first programmable electronic computer and the first computer programming languages. As mentioned earlier, it was with the advent of computers and computer science that algorithms really began to play a central role, initially only in military and scientific fields, and then ever increasingly in the fields of commerce and management. Today we can say that algorithms are an indispensable part of our everyday lives—and it seems they are destined to become even more pervasive in the future. Nevertheless, despite this massive influence of algorithms on the world around us, the majority of users remain totally ignorant of their role and importance in securing the performance of the computer applications with which they are most familiar, or, at best, consider them technical matters of little concern to them. Instead quite the opposite is the case: in reality it is the power, the precision, the reliability and the speed of execution which these same users have been demanding with ever- increasing pressure that have transformed the design and construction of algorithms from a highly skilled “niche craft” into a full-fledged science in its own right. This book is aimed at all those who, perhaps without realizing it, exploit the results of this new science, and it seeks to give them the opportunity to see what otherwise would remain hidden. There are ten chapters, of which nine are divided into two parts. Part I (Chaps. 1–3) introduces the reader to the properties and techniques upon which the design of an efficient algorithm is based and shows how the intrinsic complexity of a problem is tackled. Part II (Chaps. 4–9) presents six different applications (one for each chapter) which we encounter daily in our work or leisure routines. For each of these applications the conceptual and scientific bases upon which the algorithm used is grounded are revealed and it is shown how these bases are decisive as regards the validity of the applications dealt with. The book concludes with a different format, that of the dialogue. Chapter 10 illustrates how randomness can be exploited in order to solve complex problems, and its dialogue format has been deliberately chosen to show how discussions of such issues are part of the daily life of those who work in this field. As an aid to readers whose educational background may not include particularly advanced mathematics there are clear indications in the text as to which sections containing more demanding mathematics may be skipped without fear of losing the thread of the main argument. Moreover, in almost every chapter, boxes covering specific mathematical or technical concepts have been inserted, and those readers wishing to get a general sense of the topic can avoid tackling these, at least on a first reading. In fact, an overriding aim of the authors is to make the role of algorithms in today’s world readily comprehensible to as wide a sector of the public as possible. To this end a simple, intuitive approach that keeps technical concepts to a
Giorgio Ausiello Dipartimento di Ingegneria Informatica, Automatica e Gestionale, Sapienza Università di Roma, Roma, Italy
Vincenzo Bonifaci Istituto di Analisi dei Sistemi ed Informatica “Antonio Ruberti”, Consiglio Nazionale delle Ricerche, Roma, Italy
Camil Demetrescu Dipartimento di Ingegneria Informatica, Automatica e Gestionale, Sapienza Università di Roma, Roma, Italy
Paolo Ferragina Dipartimento di Informatica, Università di Pisa, Pisa, Italy
Raffaele Giancarlo Dipartimento di Matematica ed Informatica, Università di Palermo, Palermo, Italy
Giuseppe F. Italiano Dipartimento di Ingegneria Civile e Ingegneria Informatica, Università di Roma “Tor Vergata”, Roma, Italy
Stefano Leonardi Dipartimento di Ingegneria Informatica, Automatica e Gestionale, Sapienza Università di Roma, Roma, Italy
Alberto Marchetti-Spaccamela Dipartimento di Ingegneria Informatica, Automatica e Gestionale, Sapienza Università di Roma, Roma, Italy
Alessandro Panconesi Dipartimento di Informatica, Sapienza Università di Roma, Roma, Italy
Rossella Petreschi Dipartimento di Informatica, Sapienza Università di Roma, Roma, Italy
Fabrizio Rossi Dipartimento di Informatica, Università dell’Aquila, Coppito (AQ), Italy
Antonio Sassano Dipartimento di Ingegneria Informatica, Automatica e Gestionale, Sapienza Università di Roma, Roma, Italy
Riccardo Silvestri Dipartimento di Informatica, Sapienza Università di Roma, Roma, Italy
xiii
Finding One’s Way in a World
of Algorithms
Giorgio Ausiello
Abstract The design of algorithms for land measurement, financial transactions and astronomic computations goes back to the third millennium BCE. First exam- ples of algorithms can be found in Mesopotamian tablets and in Egyptians scrolls. An important role in the development of numerical algorithms was played in the ninth century by the Persian mathematician al-Khwarizmi, who introduced the Indian numeration systems to the Arab world and from whom we derived the name ‘algorithm’ to denote computing procedures. In the Middle Ages algorithms for commercial transactions were widely used, but it was not until the nineteenth century that the problem of characterizing the power of algorithms was addressed. The precise definition of ‘algorithm’ and of the notion of computability were established by A.M. Turing in the 1930s. His work is also considered the beginning of the history of Computer Science.
The ability to define algorithms for numerical computations or, more generally, as we would say today, for data processing, starts to appear in the history of mankind a few millennia before Christ. Among the most ancient examples of this ability are some tools used for taking note of the results of computations and, especially, the first calendars designed in ancient Egypt. In this chapter, far from attempting a history of algorithms, an effort that would require several volumes by itself, we want to show meaningful examples of algorithms, both numerical and non-numerical, that have been designed, studied and used throughout various historical ages. In the choice and illustration of such examples, there are two most relevant aspects that
G. Ausiello () Dipartimento di Ingegneria Informatica, Automatica e Gestionale, Sapienza Università di Roma, via Ariosto 25, 00185 Roma, Italy e-mail: [email protected]
G. Ausiello and R. Petreschi (eds.), The Power of Algorithms , DOI 10.1007/978-3-642-39652-6__1, © Springer-Verlag Berlin Heidelberg 2013
3
1 Algorithms, An Historical Perspective 5
The number is 4; 10. What is its inverse? Proceed as follows. Compute the inverse of 10. You will find 6. Multiply 6 by 4. You will find 24. Add 1. You will find 25. Compute the inverse of 25. You will find 2; 24. Multiply 2; 24 by 6. You will find 14; 24. The inverse is 14; 24. This is the way to proceed.
Fig. 1.1 Algorithm for the inversion of the number 4 I 10 (that is 250 ). It is easy to check that 14 I 24 is the inverse of 4 I 10 since .4 60 C 10/ .14 60 ^2 C 24 60 ^3 / D 1
The number is x. What is its inverse? Proceed as follows. [Let y and z be two numbers such that x = y + z] Compute the inverse of y. You will find y′. Multiply y′^ by z. You will find t. Add 1. You will find u. Compute the inverse of u. You will find u′. Multiply u′^ by y′. You will find v. The inverse is v. This is the way to proceed.
Fig. 1.2 Algorithm for the inversion of the number x. The algorithm is derived from the example in Fig. 1.1 by replacing the numbers appearing in the example with variables
What we can argue is that such tablets were used to teach algorithms to students, that is, to present them with the lists of elementary operations to be performed for each specific numerical example. The general rule (although not explicitly presented) could then be inductively derived from the examples. In the tablets various problems are addressed: square root computations, resolution of second- degree equations, computation of the inverse of a given number, etc. Let’s look at one of the examples in detail. This will also offer us the possibility to observe the Babylonian number system more closely. The problem consists in inverting a given number and, as we said above, the algorithm (Fig. 1.1) does not refer to a generic number denoted by a variable x as we would do today (and as we actually do in Fig. 1.2 in order to illustrate the computation executed by the algorithm), but to a specific value. Let us remember that the inverse of a number x is the number y D 1=x that multiplied by x gives as result the number 1. For example, the inverse of 2 is 30 since choosing a suitable power of the basis 60 we have 2 30 60 ^1 D 1. Computing the inverse is an important basic operation and, in particular, it was an important operation at that time, since the division operation was performed by multiplying the dividend by the inverse of the divisor. For simple numbers tables of inverses were available. In order to explain the algorithm we have to specify that, in the original text, numbers are represented in cuneiform characters and are expressed in mixed decimal and sexagesimal base. Every number consists of a sequence
6 G. Ausiello
of values between 1 and 59 , each one expressed in base 10 that here, for the sake of clarity, we present separated by the symbol “;”. The number zero simply corresponds to an empty space. The sequence 2 I 4 I 10 , for example, denotes the number 2 60 2 C 4 60 C 10 D 7;200 C 240 C 10 D 7;450. Which powers of 60 were used depended on the context, therefore the same sequence might represent the number 2 60 3 C 4 60 2 C 10 60. In particular, and this has to be regarded as one of the advanced characteristics of Babylonian mathematics, the same notation might be used to express decimal numbers. For example, the above-mentioned sequence 2 I 4 I 10 might as well represent the number 2 C 4 60 ^1 C 10 60 ^2. In Fig. 1.1 we can see how the hypothetical Babylonian teacher could present the algorithm for the computation of the inverse of the number 4 I 10 (corresponding to 250 ) to his students. The presentation starts as follows: “The number is 4 I 10. What is its inverse?” In the same tablet the algorithm is presented several times, each time applied to different numbers expressed in sexagesimal notation. For example, “The number is 8 I 20. What is its inverse?”, “The number is 1 I 13 I 20. What is its inverse?”, etc. It is interesting to pay attention to the last sentence in the presentation of the algorithm: “This is the way to proceed.” This sentence shows that the person writing the text was conscious of having discovered a computation procedure, in other words an algorithm, to solve the general problem. In fact, the procedure always followed the same steps, independently from the input values. By means of a simple abstraction process it is easy for us to derive the underlying algorithm from the examples (see Fig. 1.2). The computation method is based on the expression 1=x D 1=.y C z / D 1=y 1=. z 1=y C 1/ and consists in reducing the computation of the inverse of a given number x to the computation of the inverse of the two smaller numbers y and u D z 1=y C 1 until we reach numbers for which the inverse is already known (or can be found in precomputed tables of inverses^2 ). A very similar approach in the presentation of algorithms can be found in a famous Egyptian papyrus belonging to the first centuries of the second millennium BCE. The scroll is known as the “Rhind papyrus” from the name of a Scottish traveler who bought some of its fragments, or the “Ahmes papyrus” from the name of the scribe who copied it from an older document. This papyrus is currently held in the British Museum (with the name pBM 10057) and, together with the so-called “Moscow papyrus” and a leather scroll also held in the British Museum, is one of the few documents that provide us with information about the mathematical knowledge in ancient Egypt. Despite its ambitious title, “Accurate reckoning for inquiring into the nature and into the knowledge of all things, all mysteries, all secrets”, the document just contains a collection of examples showing how the computation should be carried out in particular cases. Again, as in the case of the Babylonian tablets, the general computation rules (the algorithms) are not explicitly provided in the document, but we can easily infer them from the examples as we did above for the computation of the inverse. The examples provided in the papyrus concern
(^2) Babylonians left several tables of simple inverses.