• DSA

How to study data structures and algorithms without memorising solutions

The failure mode in data structures and algorithms is memorising solutions, and it's seductive because it produces visible progress — a hundred problems solved feels like competence. It doesn't generalise, because the next problem is a variation you haven't memorised, and without the underlying pattern you have nothing to fall back on. What generalises is a small number of things: the cost model, roughly a dozen recurring patterns, and the ability to recognise which pattern a problem's constraints are pointing at. That set is smaller than a hundred solutions and considerably more useful.

10 min readSubjects

Build the cost model first

Before any specific algorithm, you need an automatic sense of what each structure costs for each operation. Not memorised as a table — internalised, so that "I need fast lookup by key and I don't care about order" produces "hash map" without deliberation.

  • Make the table yourself, from memory, weekly: array, dynamic array, linked list, hash map, balanced tree, heap, stack, queue, graph representations. Insert, delete, lookup, ordered traversal.
  • Know why, not just what. A hash map's O(1) lookup and a tree's O(log n) come from different mechanisms, and knowing which explains when each degrades.
  • Know the degradations. Hash maps degrade with bad hashing, dynamic arrays have amortised costs with occasional expensive operations, and questions target exactly these.
  • Attach a use case to each. A structure without a situation is a name.

The patterns are the syllabus

PatternThe signal that suggests it
Two pointersSorted array, pairs, or in-place partitioning
Sliding windowContiguous subarray or substring with a constraint
Hash map for seen-beforeDuplicates, complements, frequency counts
Binary searchSorted input, or a monotonic answer space
BFSShortest path in an unweighted graph, level-by-level
DFS / backtrackingAll paths, all combinations, constraint satisfaction
Dynamic programmingOverlapping subproblems and optimal substructure
HeapTop-k, running median, merging sorted streams
Union-findConnectivity and grouping over time
Topological sortOrdering with dependencies

Roughly a dozen patterns cover the large majority of problems in most courses and interview sets. Study the mapping from signal to pattern rather than the problems themselves — that's the selection skill that decides whether you can start an unfamiliar question.

How to work a problem so you learn from it

  1. 1

    Spend five minutes on the brute force before anything clever

    State it, state its complexity. This anchors what you're improving on and is often the fallback that earns partial credit in an exam or a working baseline in an interview.

  2. 2

    Say which pattern the constraints suggest, out loud, before coding

    "Contiguous subarray with a sum condition — sliding window." If you can't name a pattern, you're about to improvise, and improvised solutions don't transfer.

  3. 3

    Set a hard time limit — thirty to forty minutes

    Beyond that you're not learning, you're grinding. Look at the solution, understand the key insight, close it, and re-solve from scratch.

  4. 4

    After solving, write one line: the insight

    "Sorting first makes the two-pointer valid." This line is the transferable part and it's what you'll review. The code is not.

  5. 5

    Re-solve it cold in a week, from the problem statement

    If you can't, you memorised. Spaced re-solving is what distinguishes a hundred problems attempted from a hundred problems learned.

  6. 6

    Group it with problems sharing the pattern, not the topic

    Your notes should be organised by pattern. That's the retrieval structure you'll actually use.

Implement the structures once, from scratch

Using a library's hash map teaches you the interface. Writing one — with collision handling and resizing — teaches you why lookups can degrade, why load factor matters, and what an amortised cost actually means. That understanding is what exam questions about hashing are asking for.

Do this once per structure, not repeatedly. It's a comprehension exercise rather than a skill to drill, and the return drops sharply after the first implementation. A linked list, a hash map, a binary search tree with rotations, a heap and a graph traversal is a weekend and it changes how the rest of the course reads.

Exams and interviews want different things

University examTechnical interview
EmphasisProofs, complexity analysis, correctness argumentsWorking code under time pressure, communication
FormatPseudocode or prose, by handLive coding, spoken reasoning
What's markedMethod, analysis, edge cases statedWhether it runs, and whether you explained the approach
PreparationDerive complexities, prove correctness, past papersVolume of problems, spoken practice, mock interviews

The overlap is large but the tails differ, and preparing for one while sitting the other is a common and costly mistake. Check your past papers: if they ask you to prove a greedy choice is optimal, no amount of problem-grinding prepares you for that.

Complexity analysis is a separate skill

  • Practise analysing code you didn't write. Given a snippet, state the time and space complexity. Ten of these takes ten minutes and it's a common exam question in its own right.
  • Learn to solve recurrences, at least well enough for the standard cases. Divide-and-conquer analysis depends on it.
  • Distinguish worst, average and amortised precisely. Questions target the distinction, and "O(1) insert" for a dynamic array is only true amortised.
  • Include space, which students routinely forget. Recursion's stack usage is the classic omission.

A realistic weekly routine

Three to five problems a week, worked properly with the insight line and the cold re-solve, beats twenty rushed ones. Add ten minutes of cost-model and pattern review, and one session a fortnight analysing complexity of unfamiliar code.

If you're preparing for interviews alongside coursework, keep them in separate sessions — the modes are different enough that mixing them tends to mean doing neither well. How to study computer science covers the wider course, and how to learn to code the implementation fluency that all of this rests on.

Common questions

What's the best way to study data structures and algorithms?

Learn the cost model and roughly a dozen recurring patterns, then practise mapping a problem's constraints to a pattern. Memorising solutions produces visible progress that doesn't generalise — the next problem is a variation, and without the pattern you have nothing to fall back on.

How many problems should I solve to learn algorithms?

Three to five a week worked properly beats twenty rushed. 'Properly' means stating the brute force first, naming the pattern before coding, writing one line capturing the insight afterwards, and re-solving cold a week later. If you can't re-solve it, you memorised it.

Should I implement data structures from scratch?

Once each, as a comprehension exercise. Writing a hash map with collision handling and resizing teaches why lookups degrade and what amortised cost means — which is what exam questions about hashing are actually asking. The return drops sharply after the first implementation.

How do I know which algorithm to use for a problem?

By the constraints rather than the topic. Contiguous subarray with a condition suggests sliding window; sorted input or a monotonic answer space suggests binary search; overlapping subproblems suggest dynamic programming. Study that signal-to-pattern mapping directly — it's the skill that lets you start an unfamiliar question.

Is preparing for interviews the same as preparing for the exam?

They overlap heavily and differ at the tails. Exams want proofs, complexity analysis and correctness arguments; interviews want working code under time pressure and spoken reasoning. Check your past papers — if they ask you to prove a greedy choice optimal, problem-grinding won't prepare you.

How long should I spend stuck on a problem?

Thirty to forty minutes. Past that you're grinding rather than learning. Look at the solution, extract the key insight, close it, and re-solve from scratch — that sequence teaches more than another hour of being stuck, and it's how you convert a failed attempt into a pattern you own.

Try it on your own material

Upload your notes, slides or lecture recordings and get a tutor that answers only from them — and says so when they don't cover it.

$12/month, or $8/month billed yearly · cancel in two clicks