Professional Documents
Culture Documents
“Big-O”
Analyzing Efficiency
⬣ Measure both time and space
efficiency
⬣ Platform/hardware independent
⬣ High level description of
algorithm
⬣ Performance scales in relation
to the input sizes
⬣ The complexity of an algorithm
is how efficient the algorithm is
in terms of input sizes
High Level Description
⬣ Primitive operations:
⬣ Assign Value
⬣ Arithmetic operation
⬣ Comparing two entities
⬣ Method call or return from
method
⬣ Access element or follow a
reference
Big-O Review
Common Complexities (Closer look)
Log-Linear O(nlog(n))
Big-O Review
Example: 100 operations with 1000 inputs
Algorithm
N = 1000 O(2n) O(n3)
Complexity
O(1) constant
O(log(n)) 0.09966
4 O(n2)
O(n) 10
O(nlog(n)) 99.66
Big-O Review
Big-O Conventions
Big-O Review
O(1) – Constant Complexity
Can always 5 1 3 2 4
immediately
access first
1 4 2 9 4 2 1 3 3 7
element.
Big-O Review
O(n) – Linear Complexity
5 1 3 2 4
1 4 2 9 4 2 1 3 3 7
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
5
Big-O Review
O(n) – Linear Complexity
5 1 3 2 4
1 4 2 9 4 2 1 3 3 7
7
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
16
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
20
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
22
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
23
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
26
Big-O Review
O(n) – Linear Complexity
1 4 2 9 4 2 1 3 3 7
29
Big-O Review
O(n) – Linear Complexity
Big-O Review
O(log(n)) – Logarithmic Complexity
Big-O Review