CS 201 Lecture 13 - Algorithms
CS 201 Lecture 13 - Algorithms
Kholoud Nairoukh
Department of Computer Science
German-Jordanian University
Lecture 13
• The foundation of computer programming.
Example:
procedure maximum(L: list of integers)
[statements defining maximum…]
Dr. Kholoud Nairoukh
• An assignment statement evaluates the
expression expression, then reassigns the
expression value to the variable variable.
if condition
begin
statement
if condition
begin
statement
…(continue infinite nested if’s)
end
end
Solution:
procedure sum(a1, a2, …, an: integers)
s := 0 {sum of elements so far}
for i := 1 to n {go through all elements}
s := s + ai {add current item}
{at this point s is the sum of all items}
return s
Dr. Kholoud Nairoukh
• Sorting is a common operation in many
applications.
– Example: spreadsheets and databases.