Week 1 - Complexity Analysis
Week 1 - Complexity Analysis
Complexity Analysis
Week 1
Program Studi Teknik Informatika
Fakultas Teknik – Universitas Surabaya
Syllabus and Class Rules
Class Rules
2 if (myArray[i] == key) 1
3 return (i); 1
4 return (-1); 0
Example: n=3
3 return (i); 1
4 return (-1); 0
3 return (i); 0
4 return (-1); 1
Big-Oh = O (n2)
RUNNING TIME IN ORDER
• O (1) : constant
– Real world case : Checks whether a number is odd or
even.
– Programming case : Retrieve the value in an array
• O (log n) : logarithmic
– Real world case : Look up the translation of the word "car"
in the dictionary
– Programming case : Binary search
RUNNING TIME IN ORDER
• O (n): linear
– Real world case : Move items one by one.
– Programming case : make a program that prints numbers
from 1-10.
• O (n log n): Linearithmic
– Real world case : Assemble puzzles.
– Programming case : Merge sort.
RUNNING TIME IN ORDER
• O (nk) : polynomial
– Real world case : Separating apples and pears, then
separating which fruits are unripe, ripe, and rotten.
– Programming case : Selection sort.
• O (2n) : exponential
– Real world case : Looking for a combination of the several
options available.
– Programming case : Searches for a subset of the array.
TIME NEEDED TO FINISH THE PROGRAM