01-intro
01-intro
ALGORITHMS
THEORY OF ALGORITHMS
1. Predict running time of an
algorithm based on input size
(Analysis).
How long to sort 300 million names ?
2
Answer
3
How long does f(100) take ?
1 unsigned f(unsigned n)
2 {
3 if (n == 0)
4 return 0;
5 return 1 + f(n-1) + f(n-1);
6 }
4
Answer
2100
≈ 957 times universe age
(3 · 109 )(31536000)(14 · 109 )
5
Which algorithm is faster ?
Try: a = 3210987654; b = 2109876543
6
2. Given a problem, design an
algorithm to solve it.
Design an algorithm for this problem
7
Answer
8
Design an algorithm for this problem
9
Answer
Use recursion:
(b(e /2) )2 if e is even
be =
b · be −1 otherwise.
10
Design an algorithm for this problem
11
Answer
lcm(a, b) = gcdab
(a, b)
.
12
3. Determine the minimum time
required to solve a given problem
Sorting
13
Answer
14