Algoritma Bucket Sort
Procedure BucketSort ( Input/Output T: array[1..n] of integer, b: integer Output T: Array[1..n], Input n,max_n:integer)
{procedure untuk mengurutkan T array secara ascending, dengan asumsi jumlah data dan nilai terbesar diketahui}
Kamus
range : integer {rentang nilai bucket}
x,y, i, j : integer
baris, kolom : integer
isi_bucket : array [1..b] of integer {penyimpan nilai isi tiap bucket}
lengh_bucket : array [1..n] of integer {kapasitas bucket menyimpan nilai}
bucket : array [1..b] of lengh_bucket {bucket; kumpulan lengh_bucket}
Algoritma
x ß max_n div b
y ß max_n mod b
if (y > 0) then
range ß x + 1
else {menentukan interval @bucket}
range ß x
endif
for i = 1 to b do
isi_bucket[i] ß 0 {inisialisasi isi @bucket = 0}
endfor
for i = 1 to n do
x ß T[i] div range
y ß T[i] mod range
if (y > 0) then
x ß x + 1 {loop; membagi nilai T ke dalam @bucket}
endif
isi_bucket[x] ß isi_bucket[x] + 1
baris ß x
kolom ß isi_bucket[x]
bucket[m, n] ßT[i]
endfor
for i = 1 to b do
{pengurutan @ bucket dengan algoritma pengurutan tertentu}
Endfor
n ß 1
for i = 1 to b do
for j = 1 to isi_bucket[i] do
T[n] ß bucket[i,j] {penggabungan bucket}
n ß n + 1
endfor
endfor
No comments:
Post a Comment