Algorithm-I, Day 1
Topic: Binary Search
Q704 Binary Search
Q278 First Bad Version
Q35 Search Insert Position
A searching algorithm which finds an element's position in a sequential(sorted) and comparable array.
In this method, the element is always searched in the middle of a portion of an array sliced in halves.
This method do follow the divide-and-conquer approach.
Iteration Method
1 | ## Do until the pointers L(Low/Left) and R(High/Right) meet each other, |
Recursion Method
1 | ## Define a function and calle itself within definition. |
Time Complexities
- Best Case Complexity: O(1)
- Worst Case Complexity: O(log n)
- Average Case Complexity: O(log n)
Space Complexities
- O(1)
Footnotes
In Q278 First Bad Version:
Pointer L
represents the location of the first bad
version.
In Q35 Search Insert Position:
Pointer L
represents the location of the target insert
position.