Professional Documents
Culture Documents
Last Lectures
First attempt to define the central word algorithm An algorithm is any well-defined computational procedure that takes some value, or set of values as input and produces some value, or set of values as output. Definition of algorithm used in this lecture An algorithm is a finite sequence of instructions that can be carried out by a real machine. The sequence of instructions causes a defined input/output behavior on the machine. A deterministic algorithm is described by a partial function from the set of possible inputs to the set Algorithms and Data Structures Dr. Andreas Nchter 123 of 15, 2011 possible outputs. September
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
124
Donald E. Knuth
Beware of bugs in the above code; I have only proved it correct, not tried it. Donald Knuth His program TeX is considered as error free. I use the version 3.1415926 (frozen in March 2008) Donald Knuth offers monetary awards to people who find
and report a bug in TeX. The award per bug started at $2.56 (one "hexadecimal dollar") and doubled every year until it was frozen at its current value of $327.68. Knuth, however, has lost relatively little money as there have been very few bugs claimed. In addition, recipients have been known to frame their check as proof that they found a bug in TeX rather than cashing it. [wikipedia]
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
125
Last Lecture
We dicussed an Euclids algorithm for computing the gcd
1. comment
2. comment
3. comment
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
126
Last Lecture
Definition:
127
Last Lecture
Proof that the program for computing the greatest common divisor (gcd) is correct Analyzing algorithms
Input vs. input length Testing und running the program for several inputs Counting # of operations, e.g., modulo operations (gcd), comparisons (sorting/searching), additions and multiplications (math programs)
Landau / Big-Oh-Notation
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
128
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
129
Landau Notation
Example: Estimation for When analyzing algorithms we need often the upper and lower bound of . Since
we have
Therefore
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
130
Landau Notation
Proposition: Proof: Lets look at the power series of the exponential function:
we have
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
131
Landau Notation
Application (Sketch): Lets look at sorting algorithms, that use one comparison operation in one step. Lets call the minimal number of comparison operation to sort elements. Binary tree-like search gives Hence
132
Landau Notation
Theorem: Suppose to be a monotonic growing unbounded function, i.e., and assume then it holds: ,
With other words: An exponential function grows faster that a polynomial one. Proof: Exercise!
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
133
Landau Notation
The importance of the asymptotical considerations becomes clear when looking at the following table. Run times for fixed input length are listed for differently efficient algorithms and differently fast computers
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
134
135
where A more visual way to understand this problem is to image that is the height of the ith telephone pole in a sequence, and if we shoot a bullet horizontally to the left from the top of the ith pole, we want to know which pole we will hit first.
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
136
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
137
138
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
139
An interesting question to consider at this point is, what would the average-case running time be if the elements of the array were random values. Note that if is large, it seems that it would be quite unlikely to go through all iterations of the inner while loop, because the chances of coming across a larger element would seem pretty high. But how many iterations would you expect on average?
Algorithms and Data Structures Dr. Andreas Nchter September 15, 2011
140