r/leetcode • u/Bhavanashankarabs • 6h ago
Discussion Started learning DSA in Python – Completed Binary Search
Hi everyone,
I'm currently learning Data Structures and Algorithms (DSA) using Python. Today, I completed the Binary Search topic and learned:
What Binary Search is.
Why it only works on sorted arrays.
How left, right, and mid pointers work.
The iterative implementation in Python.
Time Complexity: O(log n).
Space Complexity: O(1).
I also solved LeetCode 704 (Binary Search) to reinforce the concept.
My goal is to build a strong foundation in DSA for coding interviews and internships. I'm following a structured roadmap and practicing problems regularly.
What topic should I study next after Binary Search? Any advice or recommended problems would be greatly appreciated
3
u/BriefStar6068 5h ago
the advice to hammer 10 problems before moving on is solid. binary search seems trivial when you're just looking for a target in a sorted list, but the real skill comes when the problem doesn't look like binary search at first glance. things like finding the minimum in a rotated sorted array or splitting chocolate bars with minimum sweetness force you to think about what you're actually searching for.
i'd add that you should get comfortable with the left < right vs left <= right loop conditions early. mixing those up leads to off by one errors or infinite loops, and debugging that in an interview is a time sink. after binary search, two pointers is a natural next step. it shows up everywhere and often pairs with sorted arrays in ways that feel like a cousin to the search you just learned.
1
1
6h ago
[removed] — view removed comment
1
u/AutoModerator 6h ago
Your comment has been removed as it was in Hindi. Please use English only as r/leetcode is a global subreddit. You may use r/LeetcodeDesi instead.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Moist-Feed-2533 5h ago
I'll advice go deeper into binary search, trust me there are use case of binary search h except finding value in a sort led array
Do u know when to use <= or just <
When to use binary search to find best possible answer when you don't know what you are looking for , but u want the best answer you can find?
When to do r = mid and r = mid - 1
Checkout 1011. Capacity To Ship Packages Within D Days
- Koko Eating Bananas
This might be a bit hard rn but it shows there are other use cases of binary search except finding in a sorted array and I'll advice locking this concept down probably before moving forward
1
u/Plane-Blacksmith-600 4h ago
Follow kunal kushwaha playlist and his road map , you will be able to cover basics of dsa and become strong in foundation
1
u/b3pvbmUzMTQ 4h ago
Nice work. Binary search is cool, fast, and easy to implement once you learn it. Now learn about conditional/boundary binary search where you can find the first or last occurrence of something in a monotone sequence!
6
u/Junior-Platform2814 6h ago
Now do at least 10 problems in this topic to strengthen your understanding.
Don’t just be done after one question. You need to know the applications of it before moving on to other topics.
Here is a link to a popular binary search template and how to solve popular binary search problems with it.
https://leetcode.com/discuss/post/786126/python-powerful-ultimate-binary-search-t-rwv8/