Makalah Bubble Sort Dan Merge Sort
Makalah Bubble Sort Dan Merge Sort
Disusun Oleh:
Calvin Effendi Victory 1461700048
1
1. Pseudocode Bubble Sort
Program BubbleSort
Deklarasi
int data[5]
int i, j, tmp, jumlah
Langkah
jumlah = 0
for (i = 0; i < 5; i++)
Input data[i]
endfor
Program MergeSort
Deklarasi
int a[50], b[50]
int num, i, h, j, k, mid
Langkah
for(i = 1;i <= num; i++)
Input a[i]
endfor
2
h = low, i = low, j = mid + 1
while((h <= mid) && (j <= high))
if(a[h] <= a[j])
b[i] = a[h]
h++
else
b[i] = a[j]
j++
endif
i++
endwhile
if(h > mid)
for(k = j; k <= high; k++)
b[i] = a[k]
i++
endfor
else
for(k = h; k <= mid; k++)
b[i] = a[k]
i++
endfor
endif
for (k = low; k <= high; k++)
a[k]=b[k]
endfor
if(low<high)
mid=(low+high)/2
merge_sort(low,mid)
merge_sort(mid+1,high)
merge(low,mid,high)
endif
3. Analysis Asymtotic
a. Algoritma Bubble Sort
Big Oh “Ο”
f ( n )=n2
Considering g ( n )=n2
f ( n ) ≤ 2. g (n) for all the values of n>2
3
Hence, the complexity of f (n) can be represented as Ο( g ( n ) ) , i. e . Ο(n 2)
Big Omega “Ω”
f ( n )=n2
Considering g ( n )=n2
f ( n ) ≥ 1. g (n) for all the values of n> 0
Hence, the complexity of f (n) can be represented as Ω( g ( n ) ) , i. e . Ω( n2)
Big Theta “Ө”
f ( n )=n2
Considering g ( n )=n2
1. g ( n ) ≤ f (n)≤ 2 . g( n) for all the large values of n
Hence, the complexity of f (n) can be represented as Ө( g ( n ) ) , i. e . Ө(n2)
Little Oh “ο”
f ( n )=n2
Considering g ( n )=n3
n2
lim
n→∞ ( )
n3
=0
4
4. g ( n ) ≤ f ( n ) ≤5. g(n) for all the large values of n
Hence, the complexity of f (n) can be represented as Ө( g ( n ) ) , i. e . Ө( n)
Little Oh “ο”
f ( n )=4. n
Considering g ( n )=n2
4.n
lim
n→∞ ( ) n2
=0