This table provides common problem solving techniques specific to a particular data structure.
Data structure | Technique |
Array, String | Hash table, Two pointers |
Binary Tree | DFS (recursion): O (n), BFS (level order traversal): O(n) |
Binary Search Tree | Left < Cur < Right: O (log n), In order traversal visiting nodes in ascending order: O(n), |
Binary Search Tree (BFS) | Iterate using size of the queue for level order, Add special character in the queue for level order |
Sorted array | Binary search: O(log n), Two pointers: O(n) |
Matrix/Graph | DFS, BFS |
Linked List | Dummy node, Two Pointers, Fast and Slow pointers |
Queue | |
Permutations, Combinations, Subsets | Backtracking |
Smallest, Largest, Median in a stream | Two heaps |
Solve In-place | Swap corresponding values, Store different values in the same pointers |
Maximum/Minimum Subarray/Subset/Options | Dynamic programming |