ALGORITHMS
Professor: Roberto Aburto
Definition
An algorithm is an step by
step method of solving some
problem.
This approach to problem
solving derives from the name
of the ninth-century Persian
mathematician Al-Khwrizm.
Nowadays, Algorithm refers to
a solution that can be
executed by a computer.
Introduction
Algorithms typically have the following characteristics:
Input: the algorithm receives input.
Output: The algorithm produces output.
Precision: The steps are precisely stated.
Determinism: the intermediate results of each step of
execution are unique and are determined only by the
inputs and the results of the preceding steps.
Finiteness: The algorithm terminates; that is, it stops after
finitely many instructions have been executed
Introduction
Correctness: The output produced by the algorithm is
correct; that is, the algorithm correctly solves the
problem.
Generality: the algorithm applies to a set of inputs.
Example
Consider the following algorithm that finds
the maximum of three numbers a, b, and c:
1. = .
2. If b>large, then large=b.
3. If c>large, then large=c.
Finding the Maximum of Three Numbers.
This algorithm finds the largest of the numbers a, b, and c.
Input: a, b, c
Output: large (the largest of a, b, and c)
1. max3(a, b, c) {
2. arge= a
3. If (b> large) // if b is larger than large, update large
4. large= b
5. If (c> large) // if c is larger than large, update large
6. large= c
7. Return large
8. }
Finding the Maximum Value in a Sequence
The algorithm finds the largest of the numbers 1 , 2 , ,
Inputs: s, n
Output: large (the largest value in a sequence s)
max(s, n) {
large= 1
for i= 2 to n
If ( > )
large=
return large
}
Thanks
References
Johnsonbaugh, Richard. Discrete
mathematics. Pearson/Prentice Hall, 2014.