Professional Documents
Culture Documents
02 Notasi Big O
02 Notasi Big O
Growth of Function
• Function = algoritma
• Bagaimana pertumbuhan algoritma
relatif terhadap jumlah data?
• Pertumbuhan
– Waktu yg diperlukan
– Space yg diperlukan
Teori ttg Notasi Big O
Analysis of Algorithms
Analysis of Algorithms 4
Running Time (§3.1)
• Most algorithms transform best case
Running Time
80
the input size.
60
• Average case time is often
difficult to determine. 40
running time. 0
1000 2000 3000 4000
– Easier to analyze Input Size
– Crucial to applications such a
s games, finance and robotics
Analysis of Algorithms 5
Experimental Studies
Time (ms)
mposition 5000
• Use a method like System. 4000
currentTimeMillis() to get an 3000
accurate measure of the a
2000
ctual running time
1000
• Plot the results
0
0 50 100
Input Size
Analysis of Algorithms 6
Limitations of Experiments
Analysis of Algorithms 7
Theoretical Analysis
• Uses a high-level description of the al
gorithm instead of an implementation
• Characterizes running time as a functi
on of the input size, n.
• Takes into account all possible inputs
• Allows us to evaluate the speed of an
algorithm independent of the hardwar
e/software environment
Analysis of Algorithms 8
Pseudocode (§3.2)
Example: find max eleme
• High-level description nt of an array
of an algorithm
• More structured than Algorithm arrayMax(A, n)
English prose Input array A of n integers
Output maximum element of A
• Less detailed than a p
currentMax A[0]
rogram
for i 1 to n 1 do
• Preferred notation for if A[i] currentMax then
describing algorithms currentMax A[i]
• Hides program design return currentMax
issues
Analysis of Algorithms 9
Pseudocode Details
Analysis of Algorithms 10
Primitive Operations (time unit)
Analysis of Algorithms 11
Counting Primitive Operatio
ns (§3.4)
• By inspecting the pseudocode, we can determine the
maximum number of primitive operations executed by
an algorithm, as a function of the input size
Analysis of Algorithms 13
Growth Rate of Running Time
Analysis of Algorithms 14
n logn n nlogn n2 n3 2n
4 2 4 8 16 64 16
8 3 8 24 64 512 256
Analysis of Algorithms 16