KEMBAR78
Binary search in data structure | PPTX
OBJECTIVE OF PRESENTATION
• Define Binary search.
• Example and solve with Binary search.
Binary search
• Binary search is a fast search algorithm with run-time complexity.
• This search algorithm works on the principle of divide and conquer.
• For this algorithm to work properly, the data collection should be in the
sorted form.
• Binary search looks for a particular item by comparing the middle most
item of the collection.
Algorithm of Binary search
It can be done by the following step:
1. get the middle element
MID= INT((BEG+END)/2)
2. if the middle element equals to the searched value, the algorithm stops.
3.Otherwise
a)If Item<DATA[MID],then appear left half
DATA[BEG]…….DATA[MID-1]
b)If item>DATA[MID],then appear right half
DATA[BEG]…….DATA[MID+1]
EXAMPLE
Let DATA be the following sorted 10 element array:
DATA: 2,5,8,12,16,23,38,56,72,91
Find ITEM=23.
End of the presentation
Thank You

Binary search in data structure

  • 1.
    OBJECTIVE OF PRESENTATION •Define Binary search. • Example and solve with Binary search.
  • 2.
    Binary search • Binarysearch is a fast search algorithm with run-time complexity. • This search algorithm works on the principle of divide and conquer. • For this algorithm to work properly, the data collection should be in the sorted form. • Binary search looks for a particular item by comparing the middle most item of the collection.
  • 3.
    Algorithm of Binarysearch It can be done by the following step: 1. get the middle element MID= INT((BEG+END)/2) 2. if the middle element equals to the searched value, the algorithm stops. 3.Otherwise a)If Item<DATA[MID],then appear left half DATA[BEG]…….DATA[MID-1] b)If item>DATA[MID],then appear right half DATA[BEG]…….DATA[MID+1]
  • 4.
    EXAMPLE Let DATA bethe following sorted 10 element array: DATA: 2,5,8,12,16,23,38,56,72,91 Find ITEM=23.
  • 5.
    End of thepresentation Thank You