Prev | Current Page 76 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"


REVIEW QUESTIONS
2.1 Write pseudocode for an algorithm for finding the square root of a number.
2.2 Write pseudocode for finding the mean of a set of numbers.
2.3 Count the primitive operations in your algorithm to find the mean. What is the order of growth of your
mean algorithm?
2.4 Write pseudocode for finding the median of a set of numbers.
2.5 What is the order of growth of your algorithm to find the median?
2.6 Suppose that your algorithm to find the mean is ??(n), and that your algorithm to find the median is ??(n lg n),
what will be the execution speed ratio between your algorithm for the mean and your algorithm for the
median when the number of values is 1,000,000?
2.7 A sort routine which is easy to program is the bubble sort. The program simply scans all of the elements
to be sorted repeatedly. On each pass, the program compares each element with the one next to it, and
reorders the two, if they are in inverse order. For instance, to sort the following list:
6 7 3 1 4
CHAP. 2] ALGORITHMS 29
Bubble sort starts by comparing 6 and 7. They are in the correct order, so it then compares 7 and 3. They
are in inverse order, so bubble sort exchanges 7 and 3, and then compares 7 and 1. The numbers 7 and 1
are in reverse order, so bubble sort swaps them, and then compares 7 and 4.


Pages:
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
biuro rachunkowe łódź Pozycjonowanie implanty łódź noclegi sem