DSA Roadmap: What to Learn, in What Order, and Why

A path through data structures and algorithms for self-taught developers, computer science students and anyone preparing for coding interviews. Go stage by stage: each step links to a page that animates its topic, and each stage ends with what you should be able to do before moving on.

Fun fact: a study plan is a topological sort — you can only learn a topic after everything it depends on.

An arrow shows which earlier stage a stage needs. Stages 2, 3 and 4 each need only Stage 1, so their order is yours to choose.

Stage 0: Measuring cost

  • 1Big O notation — Every later step is weighed by how its work grows with the input, and Big O is how that growth is written.

Ready to move on when you can say why one loop over n items is O(n) and a loop inside a loop is O(n²), and why O(log n) appears whenever the work halves each step.

Stage 1: Linear structures

  • 2Array — Values side by side in memory, so any index is reached in one step, O(1). Sorting, hashing and heaps all work on arrays.
  • 3Linked list — Nodes joined by links: inserting at the front takes O(1) with nothing shifted, but reaching a position means walking to it, the array's trade-off reversed.
  • CompareArray vs Linked List: the same values in both, at the front and at the end.
  • 4Doubly linked list — A second link in each node, back to the one before, so the list can be walked both ways and a node you hold can be removed in O(1).
  • CompareSingly vs Doubly Linked List: the same deletion in both.
  • 5Stack — Last in, first out, built here on an array: push and pop work at its end in O(1). The browser's Back button works this way.
  • 6Queue — First in, first out, built here on a linked list: add at the rear, remove at the front, both in O(1).
  • CompareStack vs Queue: the same six operations on both.

Ready to move on when you can explain why inserting at the front costs O(n) in an array and O(1) in a linked list, and say which of stack or queue gives "undo" and which gives "first come, first served".

Stage 2: Sorting

  • 7Bubble sort — Compares and swaps only neighbors, so it is the easiest sort to trace by hand: about n passes of about n comparisons each, O(n²) at work.
  • 8Selection sort — Each pass finds the minimum of the unsorted part and swaps it to the front: still O(n²) comparisons, but at most one swap per pass.
  • 9Insertion sort — Shifts each value left into the sorted part. On almost-sorted data it barely shifts at all, which is why fast library sorts still use it for short runs.
  • 10Merge sort — Splits the array in halves, sorts each half and merges them: log n levels of O(n) merging give O(n log n) on any input, using O(n) extra memory.
  • 11Quick sort — Splits around a pivot instead of in the middle and sorts in place, without merge sort's extra array; a pivot that is always the largest or smallest value makes it O(n²).
  • CompareMerge Sort vs Quick Sort: both on one array, split by position or by value.

Ready to move on when you can name one O(n²) sort that is fast on almost-sorted data (insertion), explain why merge sort is always O(n log n), and give an input that makes a last-element-pivot quick sort O(n²).

Stage 3: Hashing

  • 12Hash table — A hash function turns each key into an array index, and keys that land on the same index share a linked list there (chaining): both structures from Stage 1, for O(1) lookups on average.

Ready to move on when you can explain what a collision is, and why lookups are O(1) on average but O(n) in the worst case.

Stage 4: Trees

  • 13Binary search tree — Nodes with two links instead of one: smaller keys go left and larger ones right, so each step down rules out a whole subtree, as binary search rules out half an array.
  • Try itBinary search tree visualizer: insert your own keys and watch each comparison on the way down.
  • 14Inorder traversal — Left subtree, node, right subtree: on a binary search tree the keys come out in ascending order. The app walks it with a stack from Stage 1.
  • 15Preorder traversal — The node before its subtrees: the order in which a tree is copied or saved, here with a stack too.
  • 16Postorder traversal — The node after its subtrees: the order in which a tree is deleted or an expression tree is evaluated, here with two stacks.
  • CompareInorder vs Preorder vs Postorder: all three on one tree.
  • 17Level order traversal — Level by level from the root, with a queue in place of the stack: the tree form of breadth-first search in Stage 6.
  • 18AVL tree — Rotates after an insertion so that at every node the two subtrees differ in height by at most one, and a search stays O(log n) whatever order the keys arrive in.
  • Try itAVL tree visualizer: insert your own keys and watch every rotation.
  • 19Red-black tree — A looser balance kept by node colors: the tree may be a little taller than an AVL tree but rebalances less often, which is why ordered maps in standard libraries are usually red-black trees.
  • Try itRed-black tree visualizer: insert your own keys and watch every recoloring and rotation.
  • CompareAVL Tree vs Red-Black Tree: the same six keys in both.
  • 20B-tree — Many keys per node, so the tree stays short and wide: each level costs one node read, which is what disks and database indexes need.
  • Try itB-tree visualizer: insert your own keys and watch each split send a middle key up.
  • 21Trie — A tree keyed by characters instead of whole keys: finding a word takes as many steps as the word has letters, however many words are stored.

Ready to move on when you can insert 10, 20, 30 into a BST and explain why it became a chain, then say what an AVL tree does about it; and say why inorder traversal of a BST gives sorted keys.

Stage 5: Heaps

  • 22Min-heap — A binary tree stored in an array, every parent no larger than its children: the minimum sits at the root, and insert or extract-min moves one value along a single path.
  • 23Heap sort — Uses the min-heap's mirror, a max heap: it builds one in the array, then swaps the largest value to the end again and again, O(n log n) with no extra memory.

Ready to move on when you can explain why the smallest value is always on top, why insert and extract-min are O(log n), and why a heap can't find an arbitrary value fast.

Stage 6: Graphs

  • 24Graph — Lists and trees are special graphs; here any vertex may link to any other, stored as a matrix of edges or as a list of neighbors per vertex.
  • 25Breadth-first search (BFS) — Visits the nearest vertices first by keeping the waiting ones in a queue, so in a graph without weights it finds the path with the fewest edges.
  • 26Depth-first search (DFS) — The same loop with a stack in place of the queue: it follows one path as deep as it goes, then backtracks.
  • CompareBFS vs DFS: both searches on one tree.
  • 27Topological sort — Orders the vertices of a directed graph without cycles so that every edge points forward. Kahn's algorithm, the one shown here, works like BFS on a queue of the vertices with no incoming edges left.
  • 28Union-Find — Keeps elements in separate sets and tells in almost constant time whether two are in the same one: the check Kruskal's algorithm needs at the end of this stage.
  • 29Dijkstra's algorithm — Shortest paths by total weight: it settles the closest vertex next, taken from a priority queue, usually the min-heap of Stage 5.
  • 30Bellman-Ford algorithm — Shortest paths when some weights are negative, where Dijkstra's algorithm fails: it relaxes every edge, pass after pass, in O(V·E), and detects a negative cycle the source can reach.
  • CompareDijkstra vs Bellman-Ford: both on one graph with a negative edge.
  • 31Prim's algorithm — A minimum spanning tree grown from one vertex: Dijkstra's loop, with a min-heap keyed by a single edge's weight instead of a total distance.
  • 32Kruskal's algorithm — A minimum spanning tree from the edges sorted lightest first, each kept unless union-find says it would close a cycle.
  • ComparePrim vs Kruskal: both build the same tree on one graph.

Ready to move on when you can say why BFS finds the fewest-edges path and DFS doesn't, why Dijkstra breaks on a negative edge, and what Prim and Kruskal each pick at every step.

Preparing for coding interviews? Take this shorter route

Interviews lean on hashing, two pointers over arrays, trees and graph traversal; B-trees and red-black internals rarely come up.

  1. Big O
  2. Array
  3. Linked list
  4. Hash table
  5. Stack & Queue
  6. Merge & Quick sort
  7. BST and traversals
  8. Min-heap
  9. BFS & DFS
  10. Topological sort
  11. Dijkstra
  12. Union-Find

Learn it
on your phone.

Every topic on this path is in the VisiGrab app, animated step by step, with its code in Java, Python and C++.