1 / 27

Searching

Searching. Oleh : Tim Teaching Bernadus Anggo Seno Aji, S.Kom., M.Kom Farah Zakiyah Rahmanti, S.ST., M.T. Agustus 2018. Bahan kajian Mata kuliah. Notasi Algoritmik, Tipe Dasar, Nilai , Percabangan Percabangan Perulangan Fungsi UTS. Prosedur Array dan String Searching Sorting

ronaldm
Download Presentation

Searching

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. Searching Oleh : Tim Teaching Bernadus Anggo Seno Aji, S.Kom., M.Kom Farah Zakiyah Rahmanti, S.ST., M.T. Agustus 2018

  2. Bahankajian Mata kuliah • Notasi Algoritmik, Tipe Dasar, Nilai, Percabangan • Percabangan • Perulangan • Fungsi • UTS • Prosedur • Array dan String • Searching • Sorting • UAS

  3. Find the maximum / minimum • Maximum = 10 • Maximum = 3

  4. Find the maximum / minimum • Logic : • Asumsielemenpertamaadalahnilaimaksimum • Kemudianbacaelemensisanya • Bandingkan dengan nilaimaksimum yang kita punya saat ini. • Jikanilai dari elemen yang kita proses lebihbesar dari nilaimaksimum, makagantinilaimaksimum yang kita miliki

  5. Find the maximum / minimum Minimum?

  6. Find Where is the maximum / minimum • Dalam proses pencarian suatu nilaididalam array, lokasi/indeknilaitersebutdidalam array lebihpentingdibandingnilai yang dicari itu sendiri. • Karena, jikaindek dari nilaitersebutdiketahui,nilai yang dicari juga bisa didapatkan • Buatalgoritma untuk menampikanposisinilaimaksimum • Maximum position = 3

  7. Find Where is the maximum / minimum

  8. Find a Number Create an algorithm to search a number within an array • Search = 5, output : found • Search = 3, output : not found

  9. Find a Number • Logic : • Read from first to the last element or until the first value found • Example x = 8 X = 8 X = 8 X = 8 X = 8 X = 8

  10. Find a Number • Logic : • Read from first to the last element or until the first value found • Example x = 6 X = 6 X = 6 X = 6 X = 6 X = 6 . . . .

  11. Find a Number (Sequential Search)

  12. Searching in an Ordered Value • Logic : • Read each element until the value is greater or equal to the searched value • Example x = 6 X = 6 X = 6 X = 6 X = 6 X = 6 X = 6 X = 6 No need to search the rest

  13. Searching in an Ordered Value

  14. Binary Search

  15. Binary Search • Logic : • Assume the array is ordered by ascending • Look at the middle value of the array • If the searched value is less than the middle value, then the value, if any, must be at the first half of the array; discard the second half of the array • If the searched value is greater than the middle value, then the value, if any, must be at the second half of the array; discard the first half of the array • Repeat the process until the value found or the array is exhausted

  16. Binary Search • Example x = 51

  17. Binary Search • Example x = 51 • Bottom index = 1 • Top index = 10 • Middle index = ( 1 + 10 ) div 2 = 5 • X > middle  the value, if any, must be at the second half • New bottom index  middle + 1 X = 51

  18. Binary Search • Example x = 51 • Bottom index = 6 • Top index = 10 • Middle index = ( 6 + 10 ) div 2 = 8 • X < middle  the value, if any, must be at the first half • New top index  middle - 1 X = 51

  19. Binary Search • Example x = 51 • Bottom index = 6 • Top index = 7 • Middle index = ( 6 + 7 ) div 2 = 6 • X = middle  value found X = 51

  20. Binary Search • Example x = 25 • Bottom index = 1 • Top index = 10 • Middle index = ( 1 + 10 ) div 2 = 5 • X < middle  the value, if any, must be at the first half • New Top index  middle - 1 X = 25

  21. Binary Search • Example x = 25 • Bottom index = 1 • Top index = 4 • Middle index = ( 1 + 4 ) div 2 = 2 • X > middle  the value, if any, must be at the second half • New Bottom index  middle + 1 X = 25

  22. Binary Search • Example x = 25 • Bottom index = 3 • Top index = 4 • Middle index = ( 3 + 4 ) div 2 = 3 • X < middle  the value, if any, must be at the first half • New Top index  middle - 1 X = 25

  23. Binary Search • Example x = 25 • Bottom index = 3 • Top index = 3 • Middle index = ( 3 + 3 ) div 2 = 3 • X < middle  the value, if any, must be at the first half • New Top index  middle - 1 X = 25

  24. Binary Search • Example x = 25 • Bottom index = 3 • Top index = 2 • Top < bottom, array exhausted, value not found

  25. Question?

  26. Terima Kasih

More Related