Bifalgorithm post
Hello everyone and welcome to day 3 of 30 days of DSN. In today's video we are going to look at the binary search algorithm. Let's suppose you are given a shorted array in increasing order and there are 9 elements and you want to tell whether element with value 6 is present in the array or not. So what you can do is you can pick up the middle value of the array and compare it with 6. Now since the middle value is 5 which is less than 6 and since the array is shorter so all the values on the left hand side of 5 will also be less than 6. So what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5 including 5. Now for the remaining array what we can do is we can ignore the complete part on the left hand side of 5 including 5. Now for the remaining array what we can do is again pick up the middle element and compare it with 6. Now here it is 7 which is greater than 6. So what we can do is starting from 7 we can ignore all the elements which are on the right hand side because they will also be greater than 6. Now there is only one element left which is 6 and that is equal to the value which we are looking for and hence we will return true. In case if it was not equal to 6 we would have written false. Now since here we are dividing the array in half of the size at every step so the time complexity required to do complete binary search will be log n.
Hello everyone and welcome to day 3 of 30 days of DSN. In today's video we are going to look at the binary search algorithm. Let's suppose you are given a shor…
Ideas in this flowchart
- Binary Search Algorithm
- Initial Setup
- Given sorted array
- Target value: 6
- Binary Search Process
- Pick middle value
- Compare middle value with 6
- Middle value < 6
- Ignore left side
- Middle value > 6
- Ignore right side
- Middle value = 6
- Return true
- Array Halving
- Time Complexity: O(log n)