1 / 3

Searching

Searching. Example: Express the linear search algorithm as a recursive procedure. Recursive Algorithms (the linear search algorithm ). ALGORITHM 5 A Recursive Linear Search Algorithm . procedure search ( i,j,x : i,j,x integers, 1 <=i<=n , 1 <=j<=n) if a i = x then location := i

vaughan
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

  2. Example: Express the linear search algorithm as a recursive procedure. Recursive Algorithms (the linear search algorithm ) ALGORITHM 5 A Recursive Linear Search Algorithm. procedure search(i,j,x: i,j,x integers, 1 <=i<=n, 1<=j<=n) if ai = x then location := i else if i = j then location : = 0 else search(i+1,j, x) 2 Lecturer: Shaykhah

  3. Example: Construct a recursive version of a binary search algorithm Recursive Algorithms (the binary search algorithm ) ALGORITHM 6 A Recursive Binary Search Algorithm. procedure binarySearch(i,j,x: i,j,x integers, 1 <= i <= n, 1<= j <= n) m := if x = am then location := m else if (x < am and i < m ) then binarySearch( x, i, m-1) else if (x > am and j > m ) then binarySearch(x, m+1, j) else location := 0 3 Lecturer: Shaykhah

More Related