The Complete DSA Roadmap for Beginners: What to Learn, in Order

May 31, 202610 min read
interview-prepdsaalgorithmsleetcodecareer
The Complete DSA Roadmap for Beginners: What to Learn, in Order
TL;DR
  • Nine ordered stages take you from language fluency to dynamic programming, with each stage building directly on the last
  • Four to six months is the honest timeline at 1-2 hours/day; consistent daily practice beats weekend binges every time
  • Two-pointer and sliding window are the highest-ROI early patterns, converting O(n²) brute-force into O(n) single-pass solutions
  • Dynamic programming comes last by design: it requires solid recursion, and most beginners who struggle with it are actually struggling with recursion
  • Pattern recognition, not problem count, is the real interview-readiness signal: identify the likely approach on an unseen medium within 2-3 minutes
  • Reading solutions immediately when stuck is the single habit that extends prep timelines by months; struggle independently for at least 20 minutes first
  • Communication is a scored dimension that LeetCode never trains: voice-based mock interviews are the only way to close that gap before the real thing

Most DSA guides hand you a list. Arrays. Trees. Graphs. Dynamic programming. Thanks, very helpful.

What they skip is the order, the dependencies, and the signal for when you've actually cleared a stage. This DSA roadmap covers all three. If you can write a for-loop and know what a function is, you're ready to start.


Stage 0: Pick a Language and Stop Arguing About It (0-2 Weeks)

Python, Java, or JavaScript. Pick one. If you're already comfortable with one, this stage is zero days.

The debates about which language is "best for interviews" are real, mostly pointless, and cost beginners weeks. The language isn't the advantage. Fluency is. Cognitive load during a problem is finite. You can't spend it remembering how to declare a list.

If you're starting fresh, spend a week on small programs: reverse a string, count character frequencies, find the maximum in an array. Stop there. This stage ends the moment writing code feels mechanical, not the moment you've exhausted every beginner tutorial on YouTube.


Stage 1: Learn Big-O Before You Touch a LeetCode Problem (1 Week)

You cannot evaluate whether your solution is good without this. It's also one of the fastest topics to learn, which means there's no excuse to skip it.

Learn to read the time complexity of any loop nest on sight. Nested loops multiply. Sequential loops add. That's 80% of it. The formal Big O notation definition is worth reading once. After that, practice on short snippets until estimation is instant.

The complexity classes that matter: O(1), O(log n), O(n), O(n log n), O(n²), O(2^n). Know what each looks like as code, and know which are acceptable at what input sizes. Our big-O notation guide covers the practical version.

You're ready to move on when you can state time and space complexity for anything you write, without pausing.


Stage 2: Arrays and Strings Are Boring and That's the Point (2-3 Weeks)

Arrays are the backing data structure for half of what you'll learn later. Strings are arrays of characters. Build a shaky foundation here and everything downstream cracks.

Study the core operations: read, write, insert, delete. Understand why insertion at the front is O(n) while insertion at the back is O(1) amortized. Then drill the two-pointer pattern.

The two-pointer technique is the single highest-ROI concept in this stage. It converts O(n²) brute-force loops into O(n) single passes on a surprising range of problems. Practice it on sorted arrays first, then on fast-slow variants where one pointer moves faster than the other.

Aim for 15-20 easy problems and 5-10 mediums. The goal isn't to exhaust the category. It's to build a foundation that doesn't wobble.


Stage 3: Hash Maps Let You Cheat (and You Should) (1-2 Weeks)

You have a nested loop. It's O(n²). You're sad. You add a hash map. Now it's O(n). This, approximately, is the whole stage.

The core idea: trading space for time. A hash map converts O(n) search into O(1) by using memory to record what you've already seen. Two Sum is the canonical example. Once you can explain why the hash map solution is correct and faster than the brute force, you have the stage.

Drill two patterns: frequency counting (how many times does each element appear?) and complement lookup (have I seen the thing I need?). Learn your language's map and set API cold. You should reach for these without checking docs.


Stage 4: Trees and Recursion Will Humble You (3-4 Weeks)

The first three stages feel like you're learning to walk. Stage 4 is when the floor disappears.

Not because trees are conceptually complex. Because they require recursive thinking, and for most beginners that intuition hasn't formed yet. You'll write your first recursive function, test it, watch it produce the wrong answer for no apparent reason, and spend 40 minutes discovering you had the base case wrong.

Give recursion its own day first. Write a recursive factorial, a recursive array sum, a function that flattens a nested list. The goal is for a recursive call to feel mechanical, not mysterious.

Then learn binary trees: structure, traversals (preorder, inorder, postorder), and the core patterns: height, diameter, lowest common ancestor, path sum. Binary search trees have their own invariant. Spend a few days on them separately.

This stage takes longer than any other for most beginners. That's expected. If you reach the end of it and recursive thinking still feels shaky, do more problems before moving forward.

You're ready when you can write an inorder traversal both recursively and iteratively, and solve 10 tree problems without hints.

A programmer celebrates escaping compiler errors, then immediately gets hit by linker errors and runtime errors.

Stages 1-3 feel solved. Then recursion shows up.


Stage 5: Heaps Are One Pattern With Ten Names (1-2 Weeks)

A heap is a complete binary tree stored as an array. You use it when you need fast access to the minimum or maximum of a collection that keeps changing.

Internalize one pattern: top-K elements. "Find the K largest," "find the K most frequent words," "running median of a stream" are all heap problems in disguise. Practice until the signal is immediate.

Learn your language's priority queue API cold. Python's heapq is a min-heap by default. Negating values is the standard trick for max-heap behavior. Move on when you can identify a heap problem within two minutes of reading it.


Stage 6: Graphs Are Just Trees With Cycles (2-3 Weeks)

Trees are acyclic graphs. Everything from Stage 4 transfers directly: BFS and DFS on a graph are the same algorithms, with one extra step (a visited set) to handle cycles. Once that clicks, graphs stop being intimidating.

Start with BFS and DFS on adjacency lists. Solve the classics: number of islands, shortest path in an unweighted graph, connected components, cycle detection. After those feel solid, move to weighted shortest paths via Dijkstra's algorithm and union-find for connectivity queries.

Don't start this stage until trees feel completely solid. If recursion is still shaky, go back.


Stage 7: Patterns Are the Meta-Game (3-4 Weeks)

By now you have the data structures. This stage builds the cross-cutting patterns that apply across all of them.

The highest-ROI ones, in order:

  • Binary search and binary search on an answer space (not just on sorted arrays)
  • Sliding window for subarray and substring problems with a contiguous constraint
  • Backtracking for generating all valid configurations (permutations, subsets, board puzzles)
  • Sorting algorithms (understand merge sort and quicksort, not just arr.sort())

The goal isn't to memorize solutions. It's to see a new problem and have an immediate hypothesis about which pattern applies. When you can name the likely pattern on an unseen medium within two to three minutes, you're ready for the final stage.


Stage 8: Dynamic Programming Goes Last for a Reason (3-4 Weeks)

This is the stage where beginners quit and blame DSA for being too hard. It isn't. They just got there before they were ready.

Save DP for last. It requires solid recursion to click, and most beginners who struggle with it are actually struggling with recursion in disguise.

The framework: every DP problem is recursion plus a cache. Start top-down (memoization), then convert to bottom-up (tabulation). Master the patterns in order:

  1. Linear 1D DP: climbing stairs, house robber
  2. 2D grid DP: unique paths, minimum path sum
  3. Subsequence DP: longest common subsequence, edit distance
  4. Knapsack variants: 0/1 knapsack, coin change

The dynamic programming framework covers the mental model for all four families, including the decision tree for identifying your state.

You're done when you can solve coin change, LCS, and 0/1 knapsack from scratch, no hints.


How Long Does This Actually Take? Be Honest.

At one to two hours of focused practice per day:

StageTopicTime (1-2 hrs/day)
0Language fluency0-2 weeks
1Big-O notation1 week
2Arrays and strings2-3 weeks
3Hash maps and sets1-2 weeks
4Trees and recursion3-4 weeks
5Heaps1-2 weeks
6Graphs2-3 weeks
7Core patterns3-4 weeks
8Dynamic programming3-4 weeks
Total16-24 weeks

Four to six months is the honest number for most people starting from zero. With four or more hours per day, you can compress to two to three months.

What changes the timeline more than hours per day: whether you're struggling through problems independently, or reading solutions and calling it practice. Spoiler: one of those actually works.


Three Signals That You're Actually Interview-Ready

Don't count problems. Ask these three questions instead.

Signal 1: Can you solve most LeetCode easy problems in under 15 minutes without hints?

Signal 2: Can you look at an unseen medium problem and identify the likely pattern within two to three minutes, before you've solved it?

Signal 3: Can you explain your approach aloud while you're coding it?

The third signal is the one most people skip, because LeetCode doesn't test it. But interviewers score communication alongside correctness. A candidate who solves the problem silently and produces correct code gets a weaker hire signal than one who narrates their reasoning to the same solution. Practicing on SpaceComplexity puts you in realistic voice-based mock interviews with rubric-based feedback across all four dimensions: problem-solving, communication, code quality, and optimization. That's the gap LeetCode alone can't close.


The One Mistake That Extends This Roadmap by Months

Reading solutions the moment you're stuck.

It feels productive. It isn't. You open the solution tab, nod along, close it, and think you learned something. You didn't. You watched someone else do it.

The pattern recognition you need for interviews comes from independent retrieval, not passive reading. When you struggle through a problem and fail, then read the solution, you remember far more than if you read it after 90 seconds of confusion.

Give every problem at least 20 minutes of genuine effort before looking at a hint. When you do look, close the solution, wait 10 minutes, and write it from memory. Then solve one more problem of the same type before moving on.

Disaster girl smiling in front of a burning house - representing the chaos of skipping struggle time on LeetCode problems.

"I'll just peek at the solution." Your interview three months from now:

If you solve 200 problems by reading solutions, you've seen 200 approaches and internalized about 40. The guide on practicing LeetCode correctly covers what deliberate practice actually looks like, including what to do with problems you can't crack at all.


Further Reading