Sorting & Searching

Sorting & Searching

Sorting adalah mengurutkan array yang berisi angka

-) Mengurangi kompleks

Bubble Sort

-) For di dalam For

-) While

-) Tergolong di solting yang Kompleks

Selection Sort

Selection sort adalah memastikan data kecil dan data besar

-) Menyimpan indeks

-) Yang di cek nilai indeks, bukan nilai indeks yang kecil, tapi tetap ada pada tempatnya sendiri

-) Kompleksitas n2

Insertion Sort

-) Disisipkan

Misal dibandingkan dengan data 1

-) Tidak memastikan buatannya terkecil

-) Bandingkan indeks yang dipilih dengan indeks yang lain.

-) Kompleksitas n2

Quick Sort

-) Menggunakan teknik recursive

-) Memanggil dirinya sendiri

Merge Sort

-) Data dipecah menjadi dua – dua

-) Terdapat kelipatan 2,4,8

-) Lebih tepatnya 2n

Terdiri dari 2 array misal : Array X

Array Y

Yang dipecah menjadi 4

Kemudian array x yang lebih kecil masuk ke array

Teknik Merge Sort:

-) Divide

-) Recursive

-) Conquer

Searching

Untuk mempermudah serching

Key = data yang kita cari

Teknik Searching:

-) Linear search {data kecil}

Algorithm:

  1. n : total record of array x.
  2. For each x[i], 0 £ i £ n-1, check whether x[i] = key.
  3. If x[i] = key, then the searched data is found in index=i. Finished.
  4. If x[i] ¹ key, then continue searching until the last data which is i = n-1.
  5. If i= n-1 and x[i] ¹ key, it means the data is not exist in the list, and set index = -1. Finished.

-) Binary search {data besar}

Algorithm:

  1. n : total record of array x.
  2. left=0, right= n-1.
  3. mid =(int) (left + right)/2.
  4. If x[mid]=key then index = mid. Finished.
  5. If x[mid]<key then left = mid+1.
  6. If x[mid]>key then right = mid-1.
  7. If left £ right and x[mid] ¹ key, then repeat point 3.
  8. If x[mid] ¹ key then index = -1. Finished.

-) Interpolation search {data besar}

 

  1. In the interpolation search, we’ll split the data according to the following formula:Mid =     kunci ― data[min]           *(max   ―   min )  + min

     

    Data[max]  ― data[min]

  2. .If data[mid] = sought data, data has been found, searching is stopped and return mid.
  3. .If data[mid]!= sought data, repeat point **

**Searching is continued while sought data > data[min] and sought data < data[max].

Leave a Reply

Your email address will not be published. Required fields are marked *