📓 Cabinet of Ideas

How I Mastered Data Structures and Algorithms

How I Mastered Data Structures and Algorithms #

Excerpt #

#16 How I mastered DSA


[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb93edef-9bb2-45f5-a0cd-fd44f23e44f0_1728x1046.png)

Getting good at Data Structures and Algorithms (DSA) helped me clear interviews at Amazon, Google and Microsoft.

But, mastering DSA was not an easy task.

I tried everything from books, courses (both free and paid ones), and spent thousands of hours solving LeetCode problems.

Looking back, I realized I spent a lot of time on things that didn’t really help me get better at DSA. Had I focused on the right things, my journey would have been a lot easier.

In this article, I’ll share tips that will help you master DSA more efficiently without feeling overwhelmed.

I’ll discuss the key topics to focus on and the right order to learn them, how to start learning a new topic, resources you can use and how to scale your DSA knowledge.

I’ll also share an effective revision strategy so that you don’t forget the problems you’ve already solved.

1. Must Know Topics #

First things first, let’s talk about the key topics you need to focus on.

The three main pillars of DSA are Data Structures, Algorithms, and Problem-Solving Techniques.

[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F136f3541-297f-42d9-8276-8b5aca17dd69_3764x2176.png)

There are other topics like Segment Trees, Fenwick Trees but they are rarely asked in coding interviews.

✅ In the beginning, focus on the most common topics.

2. Learn one topic at a time #

Trying to learn multiple topics simultaneously can be overwhelming and lead to confusion.

Focusing on one topic at a time makes the learning process more manageable and less stressful.

You should start with easy topics first and gradually move to difficult topics.

Begin with linear data structures like arrays, linked lists, stack, queues before moving on to more complex ones like trees, heaps or graphs.

Here is an order you can follow:

[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5771ec15-e86b-4c28-b00a-0477442e7ff8_3240x2056.png)

Now, lets talk about how to start learning a new topic.

3. How to start learning a new topic? #

  • Start with Basics: Start by learning what it is, how it’s represented in code, different operations you can perform on it and their time/space complexities.

    • Example: For binary search trees, understand how it’s represented and learn common operations like inserting a node, deleting a node, and searching for a node.
  • Real-world applications: Understand where and how it is used in real-world scenarios.

    • Example: Graphs are used in routing algorithms to find the shortest path between nodes in a network, such as in GPS navigation systems.
  • Use Pen and Paper: Visualizing concepts on pen and paper helps in better understanding and retention. Draw diagrams, flowcharts, and write pseudocode to visualize how the data structure or algorithm works.

    • Example: For linked lists, draw nodes and pointers to see how nodes are connected and how operations like insertion and deletion are performed.
  • Implement it from Scratch: Write code to implement the data structure or algorithm from scratch. Implementing it yourself reinforces your understanding and helps you grasp the underlying mechanics.

    • Example: Implement a stack using arrays or linked lists. Write functions for push, pop, and peek operations.
  • Learn the Inbuilt Library Functions: Learn how to use standard libraries in your programming language that provide data structures and algorithms.

    • Example: In Python, learn how to use lists, sets, and dictionaries. In Java, get familiar with ArrayList, HashMap, and TreeSet.
  • Solve Simple Problems: Just reading about a topic or watching tutorials is not enough. Practice simple problems related to the topic to build confidence and reinforce learning.

    • Solve 4-5 easy problems on LeetCode from the topic you are currently learning.

4. Resources #

There are many great resources available online.

Here are some that I personally found quite useful to build a solid foundation in DSA:

[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28cfbae-8264-4840-822f-ada0853aa115_5320x2040.png)

You can find more DSA resources in this GitHub repository.

5. How to scale your DSA knowledge? #

After you have learned the basics, you are ready to go deep.

Prioritize solving problems over theory #

While theoretical understanding is important in the beginning, the real learning happens when you apply that knowledge to solve problems.

The more problems you solve, the more you’ll reinforce your understanding of data structures and algorithms.

Challenge yourself #

Getting good at DSA is similar to building muscles in the gym.

Lifting the same weights everyday won’t make you stronger. You need to slowly lift heavier weights to build muscle.

Likewise, to get better at DSA, you should slowly tackle harder problems.

Example: If you can comfortably solve most easy problems, move to medium problems.

Understand, don’t memorize #

When learning DSA, focus on understanding the underlying concepts and principles rather than just memorizing code or solutions.

Memorization may help you solve specific problems, but it limits your ability to adapt and apply your knowledge to new scenarios.

[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203ccae2-378e-40ff-b9e2-d5bed55a1980_1896x1000.png)

Think in Patterns #

Many problems share underlying patterns. Recognizing these patterns can help you quickly identify the right approach to solve new problems, reducing the time spent on trial and error.

As you solve more problems, take note of recurring techniques and approaches. Group similar problems together and identify the common strategies used.

Understanding patterns enables you to adapt solutions to different but related problems.

Some of the common problem-solving patterns are:

[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff87e25d5-c74a-4b7a-b1d4-da91b6129132_2568x2280.png)

You can find more patterns in this GitHub repository.

6. Retain what you Learn #

Mastering DSA requires not only learning new concepts and solving problems but also retaining that knowledge over time.

Repetition is key #

Repetition is key to transferring knowledge from short-term to long-term memory.

By revisiting concepts and problems regularly, you reinforce your understanding and make it easier to recall the information later.

Regularly revisit problems you found challenging and try to solve them again without looking at solutions.

Create Revision List #

On LeetCode, you can make lists.

[

]( https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab20cd74-1d74-4146-a63d-803e51f14eb1_2696x1608.png)

I found this to be an effective approach for the problems I couldn’t solve in the first attempt.

Bookmark anything important #

Having quick access to high-quality resources saves time and helps you revisit important concepts and solutions.

Use browser bookmarks or tools like Google Drive, Notion to save links to useful articles, tutorials, and problem-solving guides. Tag and organize bookmarks by category for easy access.

You can find my most important resources in this GitHub repository.

7. Be Consistent #

Learning DSA takes time.

Some topics might take weeks or months to master. Be patient with yourself.

And, it’s normal to feel stuck or frustrated when solving a challenging problem or trying to understand a complex topic.

Keep going.

If a problem seems too hard, take a break, then try again.

If you need help, check hints or use the LeetCode discussion forum.

Thank you so much for reading.

If you found it valuable, hit a like ❀ and consider subscribing for more such content every week.

If you have any questions or suggestions, leave a comment.

This post is public so feel free to share it.

Share

Checkout my Youtube channel for more in-depth content.

Follow me on LinkedIn and X to stay updated.

Checkout my GitHub repositories for free interview preparation resources.

I hope you have a lovely day!

See you soon,

Ashish