write an algorithm to search an element in an array using binary search
Answers
Answered by
10
Answer:
Algorithm: Binary_search(A,ele,N)
Explanation:
Step 1: low = 0 Step 2: high = n-1 Step 3: while (low <= high) repeat step 4 through step 6 Step 4: mid = (low + high) / 2 Step 5: Is ( ele = = a[mid]) then Loc = mid goto step 7 Otherwise Step 6: is ( ele < a[mid])? then high = mid – 1 otherwise low = mid + 1 [end while – step 3] Step 7: Is ( Loc >= 0 ) ? then Print “search element found at location “, loc Otherwise Print “search element not found".
Mark it as brainliest
follow me
Similar questions