Hello Everyone!
Today was another great day of exploring Binary Search, having to deal with problems which I had to pay close attention to lower and upper bounds. They all made me realize how flexible binary search is and how bringing it in different settings can make what seems to be very tough to handle, very easy. That’s how it felt; like moving minor pieces on a chessboard and yet achieving major impacts.
Today’s Challenges
-
Either work on finding first and last index of a nod in sorted linked list or you can find it using below mentioned easy and medium difficulty questions:-
- Task: Find out where a specific element of a given sorted array can begin in the process of searching and where it ends.
-
Approach:
- Performed binary search twice: , they need to be used once to locate the first match, and then again to locate the last match. – Exited the search moderately to make sure that desirable positions are not left out.
- What I Enjoyed: Staging the problem into two parts made the solution look well-arranged and very logical. I found it quite rewarding after both ends were reduced further until the results emerged.
-
Minimum in Rotated Sorted Array (Medium Level)
- Task: Find the smallest element of a sorted array with rotation, the rotation point of which is unknown.
- Approach: Hence for this particular linked list, used binary search to find out where the rotation was made. Decided which segment contained the number to explore further by comparing the middle element with the last element in the current range.
- What I Enjoyed: It was like opening a treasure chest for the next segment when the rotation point was identified – this is something exciting as the centre of gravity of the logic narrows in at the minimum value.
Day Summary Kyle Wood assists me in compiling a daily breakdown of issues that make the day exceptional and presents a new summary of the day’s events.
Focus on Boundaries:
Both problems demanded specific reflections on eventual search limitations in order not to miss any case. It also struck more at the issue of precision in binary search.Adaptability of Binary Search:
As expected each of the problems introduced a different approach to binary search, emphasizing how versitile the technique is withEfficiency and Simplicity:
While both problems are fun to think about, they also demonstrated how coming up with an efficient solution using a logarithmic time complexity is as simple with binary search.
Key Learnings
Dual Searches for Precision:
Occasionally, double binary search, used in problems such as Find First and Last Position, is a good approach to range-based problems.Pivot Points in Rotations:
Knowing how rotations shift arranged arrays makes it easier to look for an element, such as the minimum or to ascertain a rotation’s position.Boundary Management is Crucial:
This is because failure in updating the search limits correctly leads to some elements being missed or obtaining incorrect results.
Reflections
The Find First and Last Position of Element problem helped me improve in boundaries management and addressing a problem as a set of subtasks. However, Find Minimum in Rotated Sorted Array was a good practice to trace deeper into the array for some kind of pattern. Both of these challenges allowed me to understand binar search not only as an application of the algorithm, but as a granted technique that can be used in case of different problems.
What’s Next?
The next one will be Binary Search and Heap Problems with the themes: Kth Largest Element in an Array and Median of Two Sorted Arrays. These tasks will involve combining of different concepts, the idea here will be to challenge me to come up with a more refined solution.
That’s all I have for today, hope you enjoyed the ride. Oh well, let’s work it out some more and expand our solutions together.
Top comments (0)