DSA: Journey into Binary Search (Part 1)

Binary Search

Β·

5 min read

DSA: Journey into Binary Search (Part 1)

It's been over a week since my last update, and I'm excited to share the progress of my Data Structures and Algorithms (DSA) journey. I've officially taken the plunge into the world of DSA, starting with the fascinating topic of binary search. Let me take you through my experiences so far.

Ah, the nostalgia of B-tech sem 3 – I had a solid grasp of the DSA basics, or so I thought. It would be pretty easy for me to solve, right? Rewind a few months, and there I was, conquering competitive challenges like a champ, particularly filtering out questions by companies like Amazon on GFG.

But now, when I've started again, I feel like I'm starting from zero. Every time I try to solve a problem, I hit a roadblock. It's like that puzzled feeling when something seems strangely unfamiliar. Yep, that was me – staring at those binary search questions as if I haven't seen them before πŸ₯².

Enter the heroes of the digital world 🦾 – YouTube tutorials and articles. These reliable guides became my trusty companions, leading me through the binary search questions initially. It was like having a virtual map that pointed me in the right direction. πŸ—ΊοΈπŸ§­

Now, let's see specifically into Binary Search.

It's like a quest for hidden treasures in the world of coding. Picture this: a mountain array. It's nature's masterpiece, starting with a gentle climb, reaching a breathtaking peak, and then descending gracefully like a beautiful dance.

Now, imagine you're a coding adventurer, just like Indiana Jones but with a keyboard. Your daring mission, if you choose to accept it, is to conquer these digital mountain peaks. You're like a brave explorer equipped with your coding gear, scaling the heights to find the ultimate prize – the highest element or index that reigns over this digital mountain range.

For instance, check out this mountain array: [1, 3, 5, 8, 10, 6, 2]. See that impressive 10 towering above the rest? It's like the king of the mountain, demanding attention and respect from its numerical subjects.

Now, let's look at the magic of search spaces, and trust me, it's as cool as following a treasure map to find hidden riches. Imagine problem-solving as a vast, unexplored ocean, teeming with all sorts of solutions. This ocean of possibilities is what we call the search space.

But here's where the real adventure begins – minimizing the search space. It's like navigating through a mind-bending maze. Every wrong turn you eliminate brings you closer to the hidden treasure chest. Think of Sherlock Holmes narrowing down suspects to uncover the truth. Minimizing the search space means you're zooming in on the best solution, ignoring distractions, and focusing on what really matters.

Imagine you're deep inside a challenging maze, searching for the quickest way out. As you cross off wrong paths, you're narrowing down your choices, getting closer to that elusive exit. Similarly, in the world of algorithms, minimizing the search space guides you to the smartest solution, helping you crack those head-scratching puzzles like a seasoned pro. But here's the twist – forget the regular (start + end) / 2 trick, because we've got something even cooler. Say hello to start + ((end - start) / 2) – the superhero formula that comes to the rescue, especially when dealing with those big, wild numbers.

Why the change? Imagine you're an intrepid explorer hacking your way through a dense jungle. By using this slick formula, you're making sure your calculations stay within the limits of your data type, avoiding those annoying number overflows.

Once I got the hang of these ideas, I started solving those binary search problems on my own 😏. I must have tackled a few of them – easy ones, tough ones, you name it. And guess what? I began to see a pattern in the way these problems were set up. It's like they were dropping hints, telling me when to use binary search.

Speaking of techniques, I have a secret weapon in my toolkit 🫣 – an old-fashioned notebook. Before even touching the keyboard, I scribble down rough code snippets, approaches, and strategies on paper. This methodical way acts as a blueprint, structuring my thought process before translating it into digital reality. And it helps me a lot in debugging the code with test cases.

And let's not forget about my playgrounds. Initially, I stuck with my DSA pal, GeeksforGeeks (GFG). It was like training wheels for my coding bicycle. But as I gained confidence and flexed my mental muscles, I ventured into the exciting realm of LeetCode. It was like transitioning from guided learning to a full-blown adventure.

I'm not rushing this adventure. Nope, I'm taking it slow and steady, like a tortoise 🐒 on a quest for wisdom. You see, college life and a side project are a little much to fit alongside my DSA. That's why I'm keeping it to a maximum of two questions a day to balance my limited time. Quality over quantity, my friends.

Even when I conquer just one question, I make sure to squeeze out every drop of insight from it. I'm like a detective investigating a crime scene, looking for hidden clues and alternate paths. I even take it a step further – I explain my approach to myself as if I'm talking to an interviewer. Who knows, maybe someday I'll turn those explanations into killer YouTube videos. But for now, time is my sneaky nemesis.

Well, I've gathered all the questions that I've solved in a cozy corner of the internet – my Notion page. Head over there to peek at the puzzles I've cracked and maybe even join the fun!

So, my friends, stay close. Keep those notifications on because soon I will be sharing my side projects, college life, and some small achievements that I have got.

Β