






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Asymptotic analysis Data structures Linear Hierarchical Unstructured
Collections Threads
So far
Coming up
Algorithm Efficiency
Amount of resources used by algorithm Time, space
Benchmarking Asymptotic analysis
Benchmarking
Pick some desired inputs Actually run implementation of algorithm Measure time & space needed
SPEC – CPU performance MySQL – Database applications WinStone – Windows PC applications MediaBench – Multimedia applications Linpack – Numerical scientific applications
Search Example
Pick a number between 1…n Guess a number Answer “correct”, “too high”, “too low” Repeat guesses until correct number guessed
Linear Search Algorithm
Given number between 1… Pick 20 Guess sequence = 1, 2, 3, 4 … 20 Required 20 guesses
Linear Search Algorithm
If number = 1, requires 1 guess If number = n, requires n guesses On average, needs n/2 guesses Time = O( n ) = Linear time
Binary Search Algorithm
Search Comparison
Simple algorithm = 50 steps Binary search algorithm = log 2 ( n ) = 7 steps
Simple algorithm = 50,000 steps Binary search algorithm = log 2 ( n ) = 77 steps
Asymptotic Complexity
n/2 4n+
Size Running Time
Asymptotic Complexity
n/2 and 4n+3 behave similarly Run time roughly doubles as input size doubles Run time increases linearly with input size
Time(2n) / Time(n) approaches exactly 2
Asymptotic Complexity
log 2 ( n ) 5 * log 2 ( n ) + 3
Size Running Time
Asymptotic Complexity
n^2 and 2 n^2 + 8 behave similarly Run time roughly increases by 4 as input size doubles Run time increases quadratically with input size
Time(2n) / Time(n) approaches 4
Observations
O(log(n)) O(n) O(n^2 )
Any O(log(n)) algorithm is faster than O(n) Any O(n) algorithm is faster than O(n^2 )
Comparison of Complexity