1 / 8

Algoritma dan Struktur Data

Algoritma dan Struktur Data. Sorting. SORTING ( Pengurutan Data). Pengurutan data dapat dilakukan dengan urutan menaik (Ascending ) atau Menurun (Descending) !!! EXAMPLE DataAwal : 3 1 5 10 2 Pengurutan ASCENDING : 1 2 3 5 10

chelsi
Download Presentation

Algoritma dan Struktur Data

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. AlgoritmadanStruktur Data Sorting

  2. SORTING (Pengurutan Data) Pengurutan data dapatdilakukandenganurutanmenaik (Ascending ) atauMenurun (Descending) !!! EXAMPLE DataAwal : 3 1 5 10 2 PengurutanASCENDING : 1 2 3 5 10 PengurutanDESCENDING : 10 5 3 2 1 METODE : MetodePenyisipan (Insertion Sort) MetodeSeleksi (Selection Sort) MetodeGelembung (Bubble Sort)

  3. INSERTION SORT MenggunakanTeknikPenyisipan data Example : Jelaskanproseslogika yang terjadiuntukmengurutkan data dibawahinidenganmenggunakan INSERTION SORT Ascending ! ! ! 10 81 2 15 1 Answer : Mis P = Proses P=1 10 81 2 15 1 P=2 10 81 2 15 1 P=3 2 10 81 15 1 P=4 2 10 15 81 1 P=4 1 2 10 15 81

  4. {urut data} for k=2 to 5 do y=A[k]; j=k-1; ketemu FALSE while(j > 1 ) and (notketemu) if y < A[j] then A[j+1]  A[j] {geser} j  j -1 else ketemu TRUE endif end while A[j+1]  y en dfor INSERTION SORT AlgoritmaContohInsertion {Contohpenggunaan insertion Sort} Deklarasi A : array [1.. 5] ofinteger; y,j : integer ketemu : boolean Deskripsi A[1]10 A[2] 81 A[3]2 A[4]15 A[5]1 K=2 10 81 2 15 1 (y=81) (A[2] 81) K=3 10 81 2 15 1 (y=2) 10 81 81 15 1 10 10 81 15 1 2 10 81 15 1 (A[1]  y) K=4 2 10 81 15 1 (y=15) 2 10 81 81 1 2 10 15 81 1 (A[3]  y) K=5 2 10 15 811 (y=1) 2 10 15 8181 2 10 15 151 2 10 10 811 2 2 15 811 1 2 15 811 (A[3]  y) PROSES ALGORITMA

  5. SELECTION SORT MenggunakanTeknikPenukaran Data Example : Jelaskanproseslogika yang terjadiuntukmengurutkan data dibawahinidenganmenggunakan SELECTION SORT Ascending ! ! ! 10 81 2 15 1 Answer : Mis P = Proses P=1 10 81 2 15 1 P=2 1 81 2 15 10 P=3 1 2 81 15 10 P=4 1 2 10 15 81 1 2 10 15 81

  6. {urut data} for k=1 to 4 do indeks k {perulanganmencarinilai minimum} for jk+1 to 5 do if k[indeks] > k[j] thenindeks j endif en dfor {pertukaran data} tempA[k] A[k] A[indeks] A[indeks]temp en dfor SELECTION SORT AlgoritmaContohInsertion {Contohpenggunaan insertion Sort} Deklarasi A : array [1.. 5] ofinteger; j,k,indeks : integer temp : integer Deskripsi A[1]10 A[2] 81 A[3]2 A[4]15 A[5]1 K=1 10 81 2 15 1 (indeks=1) j=2 indeks=1 j=3 indeks=3 j=4 indeks=3 j=5 indeks=5 K=2 1 81 2 15 10 (indeks =2) j=3 indeks=3 j=4 indeks=3 j=5 indeks=3 K=3 1 2 81 15 10 (indeks =3) j=4 indeks=4 j=5 indeks=5 P=4 1 2 10 15 81 (indeks =4) j=5 indeks=4 PROSES ALGORITMA

  7. LATIHAN Jelaskanproseslogikadanprosesalgortima yang terjadiuntukmengurutkan data dibawahinidenganmenggunakan : INSERTION SORT Ascending ! ! ! INSERTION SORT Descending ! ! ! 17 90 25 56 12 78 59 1 8

  8. LATIHAN Jelaskanproseslogikadanprosesalgortima yang terjadiuntukmengurutkan data dibawahinidenganmenggunakanmetode : SELECTION SORT Ascending ! ! ! SELECTION SORT Descending ! ! ! 77 2 31 21 11 5 66 9 99

More Related