Perhatikan data dibawah ini, buatlah langkah-langkah untuk mengurutkan data tersebut

Berikut ini adalah pertanyaan dari usmanhidayat045 pada mata pelajaran TI untuk jenjang Sekolah Menengah Atas

Perhatikan data dibawah ini, buatlah langkah-langkah untuk mengurutkan data tersebut secara descending (nilai terbesar ke nilai terkecil) dengan menggunakan metode buble sort. [Bobot: 20] 36 90 18 72 81 45​

Jawaban dan Penjelasan

Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.

Hasil pengurutan dengan bubble sort (descending) adalah 90, 81, 72, 45, 36, 18. Urutan langkahnya dijelaskan di bawah ini.

Pembahasan

Bubble sort adalah metode pengurutan dengan cara membandingkan elemen-elemen data yang bersebelahan, dan menukar sesuai jenis pengurutan (ascending atau descending). Algoritma Bubble Sort biasa (tanpa optimasi) secara descending, dengan parameter input array \tt a, dengan indeks elemen awal = 1 dan banyak elemen array = \tt n, adalah sebagai berikut.

for i ←1 to n–1 do

   for j ←1 to n-i do

       if a[j] < a[j+1] then

           tukar(a[j], a[j+1])

       endif

   endfor

endfor

Langkah-langkah Pengurutan

Iterasi utama: i = 1 to 6.

Iterasi ke-1: i = 1, j = 1 to 5

  • (j = 1)
  • \large\text{$\begin{array}{c}\boxed{\bf36}\boxed{\bf90}\boxed{18}\boxed{72}\boxed{81}\boxed{45}\\\\36 < 90\\\Downarrow\\\\\boxed{\bf90}\boxed{\bf36}\boxed{18}\boxed{72}\boxed{81}\boxed{45}\end{array}$}
  • (j = 2)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{\bf36}\boxed{\bf18}\boxed{72}\boxed{81}\boxed{45}\\\\36 \not < 18\\\Downarrow\\\\\boxed{90}\boxed{\bf36}\boxed{\bf18}\boxed{72}\boxed{81}\boxed{45}\end{array}$}
  • (j = 3)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{36}\boxed{\bf18}\boxed{\bf72}\boxed{81}\boxed{45}\\\\18 < 72\\\Downarrow\\\\\boxed{90}\boxed{36}\boxed{\bf72}\boxed{\bf18}\boxed{81}\boxed{45}\end{array}$}
  • (j = 4)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{36}\boxed{72}\boxed{\bf18}\boxed{\bf81}\boxed{45}\\\\18 < 81\\\Downarrow\\\\\boxed{90}\boxed{36}\boxed{72}\boxed{\bf81}\boxed{\bf18}\boxed{45}\end{array}$}
  • (j = 5)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{36}\boxed{72}\boxed{81}\boxed{\bf18}\boxed{\bf45}\\\\18 < 45\\\Downarrow\\\\\boxed{90}\boxed{36}\boxed{72}\boxed{81}\boxed{\bf45}\boxed{\bf18}\end{array}$}

Iterasi ke-2: i = 2, j = 1 to 4

  • (j = 1)
  • \large\text{$\begin{array}{c}\boxed{\bf90}\boxed{\bf36}\boxed{72}\boxed{81}\boxed{45}\boxed{18}\\\\90 \not < 36\\\Downarrow\\\\\boxed{\bf90}\boxed{\bf36}\boxed{72}\boxed{81}\boxed{45}\boxed{18}\end{array}$}
  • (j = 2)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{\bf36}\boxed{\bf72}\boxed{81}\boxed{45}\boxed{18}\\\\36 < 72\\\Downarrow\\\\\boxed{90}\boxed{\bf72}\boxed{\bf36}\boxed{81}\boxed{45}\boxed{18}\end{array}$}
  • (j = 3)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{72}\boxed{\bf36}\boxed{\bf81}\boxed{45}\boxed{18}\\\\36 < 81\\\Downarrow\\\\\boxed{90}\boxed{72}\boxed{\bf81}\boxed{\bf36}\boxed{45}\boxed{18}\end{array}$}
  • (j = 4)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{72}\boxed{81}\boxed{\bf36}\boxed{\bf45}\boxed{18}\\\\36 < 45\\\Downarrow\\\\\boxed{90}\boxed{72}\boxed{81}\boxed{\bf45}\boxed{\bf36}\boxed{18}\end{array}$}

Iterasi ke-3: i = 3, j = 1 to 3

  • (j = 1)
  • \large\text{$\begin{array}{c}\boxed{\bf90}\boxed{\bf72}\boxed{81}\boxed{45}\boxed{36}\boxed{18}\\\\90\not < 72\\\Downarrow\\\\\boxed{\bf90}\boxed{\bf72}\boxed{81}\boxed{45}\boxed{36}\boxed{18}\end{array}$}
  • (j = 2)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{\bf72}\boxed{\bf81}\boxed{45}\boxed{36}\boxed{18}\\\\72 < 81\\\Downarrow\\\\\boxed{90}\boxed{\bf81}\boxed{\bf72}\boxed{45}\boxed{36}\boxed{18}\end{array}$}
  • (j = 3)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{81}\boxed{\bf72}\boxed{\bf45}\boxed{36}\boxed{18}\\\\81\not < 45\\\Downarrow\\\\\boxed{90}\boxed{81}\boxed{\bf72}\boxed{\bf45}\boxed{36}\boxed{18}\end{array}$}

Iterasi ke-4: i = 4, j = 1 to 2

  • (j = 1)
  • \large\text{$\begin{array}{c}\boxed{\bf90}\boxed{\bf81}\boxed{72}\boxed{45}\boxed{36}\boxed{18}\\\\90\not < 81\\\Downarrow\\\\\boxed{\bf90}\boxed{\bf81}\boxed{72}\boxed{45}\boxed{36}\boxed{18}\end{array}$}
  • (j = 2)
  • \large\text{$\begin{array}{c}\boxed{90}\boxed{\bf81}\boxed{\bf72}\boxed{45}\boxed{36}\boxed{18}\\\\81\not < 72\\\Downarrow\\\\\boxed{90}\boxed{\bf81}\boxed{\bf72}\boxed{45}\boxed{36}\boxed{18}\end{array}$}

Iterasi ke-5: i = 5, j = 1

  • (j = 1)
  • \large\text{$\begin{array}{c}\boxed{\bf90}\boxed{\bf81}\boxed{72}\boxed{45}\boxed{36}\boxed{18}\\\\90\not < 81\\\Downarrow\\\\\boxed{\bf90}\boxed{\bf81}\boxed{72}\boxed{45}\boxed{36}\boxed{18}\end{array}$}

Selesai. Hasil akhir:

\large\text{$\begin{aligned}\boxed{\bf90}\boxed{\bf81}\boxed{\bf72}\boxed{\bf45}\boxed{\bf36}\boxed{\bf18}\end{aligned}$}

Semoga dengan pertanyaan yang sudah terjawab oleh henriyulianto dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.

Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact

Last Update: Tue, 18 Oct 22