1 / 14

Pertemuan 21 Merge Sort

Pertemuan 21 Merge Sort. Matakuliah : T0456 ~ Algoritma dan Metode Object Oriented Programming Tahun : 2005 Versi : 5. Learning Outcomes. Pada akhir pertemuan ini, diharapkan: Mahasiswa dapat Menjelaskan kembali algoritma merge sort. Outline Materi. Algoritma Merge Sort

emory
Download Presentation

Pertemuan 21 Merge Sort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pertemuan 21Merge Sort Matakuliah : T0456 ~ Algoritma dan Metode Object Oriented Programming Tahun : 2005 Versi : 5

  2. Learning Outcomes Pada akhir pertemuan ini, diharapkan: Mahasiswa dapat Menjelaskan kembali algoritma merge sort

  3. Outline Materi • Algoritma Merge Sort • Penerapan Merge Sort

  4. Sorting Sorting merupakan proses mengurutkan data sesuai aturan tertentu: Ascending: dari terkecil sampai terbesar Descending: dari terbesar sampai terkecil Tujuan sorting adalah untuk mempercepat proses pencarian (searching) data

  5. Sorting Teknik pengurutan sederhana: Bubble sort Selection sort Insertion sort Teknik pengurutan lanjut: Quick sort Merge sort

  6. Merge sort Pada tahap awal, semua data dibagi menjadi bagian/kelompok data terkecil. Kemudian tiap dua data digabungkan menjadi 1 kelompok data gabungan. Penggabungan data diteruskan sampai semua data terintegrasi menjadi satu

  7. Merge sort (Putaran 1) [5] [6] [7] [8] [9] [0] [1] [2] [3] [4] 22 51 52 12 14 40 9 38 69 18 22 51 52 12 14 40 9 38 69 18 Gabung Gabung Gabung Gabung Gabung 22 9 12 52 14 69 51 38 40 18

  8. Merge sort (Putaran 2) 22 9 12 52 14 69 51 38 40 18 Gabung Gabung 18 22 12 40 14 69 51 38 52 9

  9. Merge sort (Putaran 3) 12 40 18 22 69 14 52 51 38 9 Gabung 9 12 51 52 22 14 18 69 38 40

  10. Merge sort (Putaran 4) 14 38 9 12 51 52 22 18 69 40 Gabung 9 12 38 40 18 52 14 51 69 22

  11. Merge sort 1 Void merge (int *a, int *t, int PKr, int PMid, int PKn){ int i, l1, u1, l2, u2, k; l1 = PKr; u1 = PMid-1; l2 = PMid; U2 = PKn; k = PKr; while ((l1 <= u1) && (l2 <=u2)) t[k++] = (a[l1]<a[l2])?a[l1++:a[l2++]; while (l1<=u1) t[k++] = a[l1++]; while (l2<=u2) t[k++] = a[l2++]; for (i=Pkr; i<=PKn; i++) a[i]=t[i]; }

  12. Merge sort 2 Void m_sort (int *a, int *t, int Kr, int Kn){ int mid; if (Kr < Kn) { mid = (Kr+Kn)/2; m_sort(a, t, Kr, mid); m_sort(a, t, mid+1, Kn); merge(a, t, Kr, mid+1, kn); } }

  13. Merge sort 3 Void mergeSort (int *Dt, int n){ int *temp; temp = (int *) malloc ((n+1)*sizeof(int)); m_sort(Dt, temp, 0, n-1); free(temp); }

  14. Penutup • Untuk dapat Menjelaskan kembali algoritma merge sort, mahasiswa membahas tugas pertemuan 21 no 1, 2, dan 3. (diskusikan dalam kelompok)

More Related