You are on page 1of 3
Algorithm Design and Programming Techniques Lecture 7 1* class Asst. Lecture Omar Nowfal © Searching algorithms The searching problem deals with finding a given value, called a search key, in a given set. Type of Searching Algorithm 1, Sequential Search 2. Binary Search Sequential Search It searches for a given item (some search key K) in a list of n elements by checking successive elements of the list until either a match with the search key is found (successful search) or the list is exhausted without finding a match (unsuccessful search). Sequential Search Algorithm: Alg Begin ie0 while ( K) do ici+] if (iA[m]: 64 Algorithm Design and Programming Techniques Lecture 7 T¥class Asst. Lecture Omar Nowfal K + A[O]... Alm —1] Alm] Alm +1]... A[n — 1]. here if, Example1: By using Binary Search searching for the key K=70 in the following array: 55 | 70] 74 [81 [85 [93 [98] (3 [14 [2731 [3942 Solution: 0 1 2 + 4 5 o 7 8 9 10 ll 12 3 14 27 31 39 42 55 70 74 81 85 93 98 7 8 9 10 af 12 70 74 81 85 93 98 IT M R 70 74 Algorithm Design and Programming Techniques Lecture 7 1" class Asst. Lecture Omar Nowfal Binary Search Algorith Algorithm BinarySearch (A[0..100].n,K) Begin 1-0 Rel while I <=R do M<(+R)/2 if (K = A[M)) then return M else if (K

You might also like