CSE 326: Data Structures
CSE 326: Data Structures
Introduction
front back
enqueue(Object x) {
Q[back] = x ;
back = (back + 1) % size
}
dequeue() {
x = Q[front] ;
front = (front + 1) % size;
return x ;
}
Data Structures - Introduction 14
Linked List Queue Data Structure
b c d e f
front back
Asymptotic Analysis
2 3 5 16 37 50 73 75 126
}
What algorithm would you
choose to implement this code
Data Structures - Introduction 31
snippet?
Analyzing Code
Asymptotic Analysis
38
Fast Computer vs. Smart Programmer
(round 1)
39
Fast Computer vs. Smart Programmer
(round 2)
40
Asymptotic Analysis
• Asymptotic analysis looks at the order of
the running time of the algorithm
– A valuable tool when the input gets “large”
– Ignores the effects of different machines or
different implementations of an algorithm
f(n) = n3 + 2n2
g(n) = 100n2 + 1000
Example:
100n2 + 1000 5 (n3 + 2n2) for all n 19
So g(n) O( f(n) )
Data Structures - Introduction 46
Order Notation: Example
– Bound Flavor
• Upper bound (O, o)
• Lower bound (, )
• Asymptotically tight ()
– Analysis Case
• Worst Case (Adversary)
• Average Case
• Best Case
• Amortized Data Structures - Introduction 55
16n3log8(10n2) + 100n2 = O(n3log n)