Lab: Binary Search, Quick sort, Merge Sort
Site: | DIU Blended Learning Center |
Course: | Algorithms Design & Analysis Lab (Spring 2022) |
Book: | Lab: Binary Search, Quick sort, Merge Sort |
Printed by: | Guest user |
Date: | Sunday, 24 November 2024, 7:09 PM |
Binary Search
function binary_search(A, n, searchItem)
L := 0
R := n − 1
while L ≤ R do
m := floor((L + R) / 2)
if A[m] < searchItem then
L := m + 1
else if A[m] > searchItem then
R := m - 1
else:
return m
return unsuccessful