Binary Search Flashcards
Learn all about searching and sorting algorithms in C++
Step 1
Read the search element from the user
Step 2
Find the middle element in the sorted list
Step 3
Compare, the search element with the middle element in the sorted list.
Step 4
“If both are matching, then display ““Given element found!!!”” and terminate the function”
Step 5
If both are not matching, then check whether the search element is smaller or larger than middle element.
Step 6
If the search element is smaller than middle element, then repeat steps 2, 3, 4 and 5 for the left sub-list of the middle element.
Step 7
If the search element is larger than middle element, then repeat steps 2, 3, 4 and 5 for the right sub-list of the middle element.
Step 8
Repeat the same process until we find the search element in the list or until sub-list contains only one element.
Step 9
“If that element also doesn’t match with the search element, then display ““Element not found in the list!!!”” and terminate the function.”