2
GCD ( a, b ) Function name and arguments
While b ! = 0 { ! = means ???not equal???
indentation shows what to do while b ! = 0
r <-- a modulo b set r = a modulo b ( = remainder a/b)
a <-- b set a = original b
b <-- r set b = r (i.e., the remainder)
} border of the ???while??? repetition
return a when b = 0, return value of a as the GCD
There is no standard pseudocode form, and many computer scientists develop a personal style of pseudocode
that suits them and their tasks. We will use the following pseudocode style to represent the GCD algorithm:
ANALYZING ALGORITHMS
If we know how long each statement takes to execute, and we know how many names are in the list, we
can calculate the time required for the algorithm to execute. However, the important thing to know about an
algorithm is usually not how long it will take to solve any particular problem. The important thing to know is
how the time taken to solve the problem will vary as the size of the problem changes.
The sequential search algorithm will take longer as the number of comparisons becomes greater. The real
work of the algorithm is in comparing each name to the search name. Most other statements in the algorithm get
executed only once, but as long as the while condition remains true, the comparisons occur again and again.
Pages:
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53