Sequential Search Algorithm
Sequential Search Algorithm
Any suggestions
Program Ends
Program Ends
Program Ends
(BEST + WORST)/2
Think about it
When do you think it would be the best case scenario to sort a list in ascending order? a) When the (input) list given is already sorted in descending order b) When the (input) list given is already sorted in ascending order c) When the (input) list is not sorted in either of the two orders
BACK TO GCD
The *very slow* algorithm: generate all divisors and find the greatest common one GCD(m, n) will take m+n seconds, *Assuming each mod will take one second
BACK TO GCD
Ill call this: GCD Min Algorithm The *very slow, but better* algorithm: generate all divisors and find the greatest common one, starting with minimum(m, n) GCD(m, n) will take 2*min(m, n) seconds *Assuming each mod will take one second Note here that we are generating divisors for m and n independently; for simplicity
BACK TO GCD
Ill call this: GCD Half-once Algorithm The *very slow, but better* algorithm: generate all divisors and find the greatest common one, starting with minimum(m, n) GCD(m, n) will take 2*min(m, n)/2 = min(m, n) seconds *Assuming each mod will take one second Again, we are generating divisors for m and n independently; for simplicity
BACK TO GCD
For two very large number, min(m, n) is not that great Can we do better?
EUCLIDS ELEMENTS
Many consider Euclid of Alexandria a non-mathematician 13 books were written more than 2000 years ago Books used to be small, so they were merged into one (only ! ~100 page) book now Mostly geometry, but few volumes of the 13 books (or sections) were about number theory (topics such as GCD)
EUCLIDS ALGORITHM
Pseudocode function gcd(a, b)! while b " 0! t := b! b := a mod b! a := t! return a! Example on board