Data Structure Patterns for Coding Interview Preps
Data structure patterns are the standard techniques for problems built on trees, graphs, heaps and dynamic programming. This unit covers traversal orders, BFS and DFS, top-k selection with a heap, and defining states and transitions for DP. It builds on core patterns and is where medium and hard interview questions are usually found.
Stage: Patterns · Part of the Coding Interview Prep roadmap · Last reviewed 19 November 2026
What to learn in Data Structure Patterns
- Traverse a binary tree in pre-order, in-order and level-order using recursion and a queue
- Run BFS to find the shortest path in an unweighted graph
- Detect a cycle in a directed graph using DFS or topological sort
- Use a min-heap to find the k largest elements in a stream
- Define the state and recurrence for a DP problem and convert it to a bottom-up table
Data Structure Patterns interview questions
How do you recognise that a problem needs dynamic programming?
Look for overlapping subproblems and optimal substructure: the answer is built from answers to smaller versions of the same question, and a naive recursion recomputes the same states. If you can name a state and a recurrence, memoise it or fill a table.
When do you choose BFS over DFS on a graph?
Choose BFS when you need the shortest path by number of edges in an unweighted graph or want to process nodes level by level. DFS suits exhaustive exploration, cycle detection, connected components and topological ordering, and usually needs less memory on wide graphs.
Where Data Structure Patterns fits in the Coding Interview Prep roadmap
Data Structure Patterns belongs to the Patterns stage (intermediate level), which takes about 27 hours. Core techniques.
Other units in this stage
Back to the full Coding Interview Prep roadmap