Professional Documents
Culture Documents
Solution Manual For Introduction To Algorithms, Third Edition by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein
Solution Manual For Introduction To Algorithms, Third Edition by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein
Cormen, Charles E
Expressing
algorithms
Pseudocode is similar to C, C++, Pascal, and Java. If you know any of these
languages, you should be able to understand pseudocode.
Pseudocode is designed for expressing algorithms to humans. Software
en- gineering issues of data abstraction, modularity, and error handling are
often ignored.
We sometimes embed English statements into pseudocode. Therefore, unlike
for “real” programming languages, we cannot create a compiler that translates
pseudocode to machine code.
Insertion sort
Pseudocode
We use a procedure I NSERTION -S ORT.
Takes as parameters an array and the length of the
array. As in Pascal, we use “ ” to denote a range within an array.
length
length
The array is sorted in place: the numbers are rearranged within the
array, with at most a constant number outside the array at any time.
2-3 Lecture
Lecture
Notes
Notes
forfor
Chapter
Chapter
2: 2:
Getting
Getting
Started
Started 2-3
while and
key key
Example
j j j
51 22 43 64 15 36 21 52 43 64 15 36 21 42 53 64 15 36
j j
21 42 53 64 15 36 11 22 43 54 65 36
11 22 33 44 55 66
Correctness
Pseudocode conventions