0% found this document useful (0 votes)
94 views5 pages

Makalah Bubble Sort Dan Merge Sort

The document discusses Bubble Sort and Merge Sort algorithms. It provides pseudocode for Bubble Sort and Merge Sort. It also analyzes the asymptotic complexity of both algorithms. Bubble Sort is analyzed to have a time complexity of Θ(n^2) while Merge Sort has a time complexity of Θ(n). The document was submitted as an assignment for the Algorithm Analysis course.

Uploaded by

Calvin Effendi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views5 pages

Makalah Bubble Sort Dan Merge Sort

The document discusses Bubble Sort and Merge Sort algorithms. It provides pseudocode for Bubble Sort and Merge Sort. It also analyzes the asymptotic complexity of both algorithms. Bubble Sort is analyzed to have a time complexity of Θ(n^2) while Merge Sort has a time complexity of Θ(n). The document was submitted as an assignment for the Algorithm Analysis course.

Uploaded by

Calvin Effendi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MAKALAH

BUBBLE SORT DAN MERGE SORT


Diajukan sebagai tugas mata kuliah
Analisis Algoritma

Disusun Oleh:
Calvin Effendi Victory 1461700048

PROGRAM STUDI TEKNIK INFORMATIKA


FAKULTAS TEKNIK
UNIVERSITAS 17 AGUSTUS 1945 SURABAYA
2018

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

for ( i = 0; i < 5; i++)


for (j = i + 1; j < 5; j++)
if (data[i] > data[j])
tmp = data[i]
data[i] = data[j]
data[j] = tmp
endif
endfor
endfor

for (i = 0; i < 5; i++)


Output data[i]
endfor

2. Pseudocode Merge Sort

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

for(i = 1; i <= num; i++)


Output a[i]
endfor

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

Hence, the complexity of f (n) can be represented as ο( g ( n ) ) , i. e . ο (n3 )


 Little Omega “ω”
f ( n )=n2
Considering g ( n )=n
n2
lim
n→∞ n
( )
=∞

Hence, the complexity of f (n) can be represented as ω ( g ( n ) ) , i. e .ω (n)

b. Algoritma Merge Sort


 Big Oh “Ο”
f ( n )=4. n
Considering g ( n )=n
f ( n ) ≤ 5 . g(n) for all the values of n>2
Hence, the complexity of f (n) can be represented as Ο( g ( n ) ) , i. e . Ο(n)
 Big Omega “Ω”
f ( n )=4. n
Considering g ( n )=n
f ( n ) ≥ 4 . g( n) for all the values of n> 0
Hence, the complexity of f (n) can be represented as Ω( g ( n ) ) , i. e . Ω(n)
 Big Theta “Ө”
f ( n )=4. n
Considering g ( n )=n

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

Hence, the complexity of f (n) can be represented as ο( g ( n ) ) , i. e . ο (n2 )


 Little Omega “ω”
f ( n )=4. n
Considering g ( n )=4
4.n
lim
n→∞
( ) 4
=∞

Hence, the complexity of f (n) can be represented as ω ( g ( n ) ) , i. e .ω (4 )

You might also like