In computer science, algorithms are usually represented as pseudocode. Pseudocode is close enough to
a real programming language that it can represent the tasks the computer must perform in executing the algorithm.
Pseudocode is also independent of any particular language, and uncluttered by details of syntax, which
characteristics make it attractive for conveying to humans the essential operations of an algorithm.
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:
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
No comments:
Post a Comment