Skip to main content

Strategy for Studying Data Structures & Algorithms

My Approach for studying DS&A & Leetcode.



Just shaddap and show me an example



Ok, Fine, Explain it...

Note: To study Data Structures & Algorithms ("DS&A") via Leetcode, I also rely on the following resources, alongside Leetcode's Problem Editorials & Solutions sections.

Please note: This particular blog post is in Draft mode: I plan to write about this more in depth once I complete my current interview cycle. At that point I will take some time and either create a NextJS + Strapi CMS blog, or for the sake of speed, just continue with this Docusaurus + Vercel blog you're currently on.

In the process of studying Data Structures & Algorithms via Leetcode... I recently realized what is my current best strategy for learning the material.

I never studied Computer Science formally. I've taken a few CIS courses. And in being a mostly-Autodidact, This is simply my approach and my personal "framework" for studying new material.

In the case of Leetcode, and in the context of Technical Interviews, here is what I recently realized will by my strategy moving forward...

Read the Editorial. Debug its code via a UnitTest

  • Read the Editorial of the problem
    • Every Leetcode problem has an editorial section. This is especially important to read if you are not familiar with particular problem and strategies for solving it. So, read the Editorial. In particular, take your time reading the Algorithm steps of the Editorial.
    • Research unfamiliar Prerequisite concepts you read about in the Editorial and Problem statement. I expand on this below, but for brevity of this section fo the post, I will just say: You must understand 100% of all the concepts the editorial discusses if you truly want to master the content.
  • Copy the Editorial’s code into a Python file (or whatever language you use).
  • Create a Python test file. Set up a simple unit test for the Editorical code for the purposes of navigating the code + environment during an example unit test.
  • Using the Python debugger, set a breakpoint at the assertEqual line of your unit test.

If you're unfamiliar with breakpoints & debugging in VS Code, here's a brief how-to:

Note: This Embedded video may not work if you have enabled extensions such as PrivacyBadger, AdBlock, and others that interfere with Javascript.

Actually.. It looks like Google Drive might not like to have its videos embedded

  • Continuously click “Step Into” debugger button and watch how the environment changes in response to the code. In this way, rather than using unwiedly print statements, you can view how the environment of the program grows and evolves as data from the function(s) arguments move through the program.

Research unfamiliar Prerequisite concepts

  • In studying unfamiliar content, it may be temping to delude one's self into thinking that it's enough to merely go through the motions of watching a tutorial and even coding along with it.
  • However, if you do not 100% fully understand exactly what is happening, in depth, every step of the way, then your studying is a waste of time. You must fully understand and fully assimilate the new knowledge as much as you possibly can.
  • The only way to do this is to Research all unfamiliar prerequisite concepts you encounter in your studying.

Here's an example: First, let's cliffnotes of the initial section of this post:

Cliffnotes of how to study (It goes without saying: Also read eBooks on Data Structures & Algorithms from LibraryGenesis and review videos from Youtube or Udemy)

  • Review editorial
  • Copy editorial code
  • Setup test of editorial code, debug the test of editorial code in order to step through A. its environment and B. the program itself, alongside each other, to better understand what the program is actually doing while it encounters the arguments passed into the functions.

OK, Now, How do we approach unfamiliar concepts? We research the heck out of them.

  • While reviewing the problem and editorial, identify prerequisite knowledge.

  • Now, in this case, https://leetcode.com/problems/parallel-courses/

    • It involves Breadth First Sort and a Graph (i.e. Graph Theory).
    • These are two important prerequisites for understanding this problem.
  • A good way to identify & test whether you have prerequisite knowledge for a Leetcode problem is to go through the steps of the “Algorithm” section of the Editorial

  • For me for example– “Step 1: Build a directed graph from relations.”

    • if I don’t know how to build a directed graph via Python, or even what a directed graph is, then I will start with searching for those topics on Youtube (tip: filter by view count to find the more popular video explanations)
      • “What is a directed graph?”
      • “How do I build a directed graph with Python?”
    • In reading the Editorial explanation (before Algorithms section), I found examples of two other concepts I need to understand, as a prerequisite. So, I will search for these on Youtube as well:
      • Kahn’s Algorithm
        • …which leads to videos about Topological Sorting, Graph Theory, and other topics:
        • How Breadth First Sort works in Python
        • How a Graph is created and navigated in Python
      • In studying those, you might identify other concepts you need to understand as well, such as Queues, or foundational data structures within Python such as Lists, Sets, etc.
      • Then study a simpler problem showing how those two concepts work.
        • A simple BFS problem
        • A simple graph problem
    • Now that you have studied the above concepts, you have a much better knowledge some context for understanding both the problem and the solution.
    • Return back to the Problem's Editorial.
      • Go back to its Editorial's "Algorithm" section's "Steps".
      • Translate its Steps into Pseudocode.
      • Then translate the Pseudocode into working code.
      • Then create a unittest for the working code
      • Then debug the unittest to watch the program in action.