

































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to algorithmic complexity, focusing on efficiency, benchmarking, and asymptotic analysis. It covers the concept of measuring efficiency through time and space, the advantages and disadvantages of benchmarking, and the approach to asymptotic analysis. The document also includes examples of linear and binary search algorithms and their analysis.
Typology: Study notes
1 / 41
This page cannot be seen from the preview
Don't miss anything!


































Algorithm Efficiency
Amount of resources used by algorithm
Time, space
Benchmarking Asymptotic analysis
Benchmarking
Precise information for given configuration
Implementation, hardware, inputs
Affected by configuration
Data sets (usually too small) Hardware Software
Affected by special cases (biased inputs) Does not measure
intrinsic
efficiency
Asymptotic Analysis
Mathematically analyze efficiency Calculate time as function of input size
n
O[ f(
n
T is on the order of f(
n
“Big O” notation
Measures intrinsic efficiency Dominates efficiency for large input sizes
Linear Search Algorithm
Guess number = 1
If incorrect, increment guess by 1
Repeat until correct
Given number between 1…100 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
Example
Given number between 1…100 Pick 20 Guesses =
= 25, Answer = too large, subtract
= 12 , Answer = too large, subtract
Answer = too small, add
Answer = too small, add
Answer = too large, subtract
Answer = too large, subtract
Required 7 guesses
Binary Search Algorithm
If number = n/2, requires 1 guess If number = 1, requires log
2
( n ) guesses
If number = n, requires log
2
( n ) guesses
On average, needs log
2
( n ) guesses
Time = O( log
2
( n ) ) =
Log
time
Asymptotic Complexity
4n+
n/
Running Time
Size
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
Comparing two functions
log
2
( n )
and
5 * log
2
( n ) + 3
behave similarly
Run time roughly increases by constant as input sizedoubles Run time increases
logarithmically
with input size
For large values of n
Time(2n) – Time(n) approaches constant Base of logarithm does not matter
Simply a multiplicative factor
log
a
N = (log
b
N) / (log
b
a)
Both are O(
log(n)
) programs
Asymptotic Complexity
2 n
2
n
2
Running Time
Size
Big-O Notation
Upper bound on number of steps in algorithm Intrinsic efficiency of algorithm for large inputs
Formal Definition of Big-O
For some positive constants M, N
0
g(n)
f(n), for all n
0
For some coefficient M & all data sizes
0
g(n) is always greater than f(n)