DSA Cheatsheet

DSA Cheatsheet

This table provides common problem solving techniques specific to a particular data structure.

Data structureTechnique
Array, StringHash table, Two pointers
Binary TreeDFS (recursion): O (n), BFS (level order traversal): O(n)
Binary Search TreeLeft < 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 arrayBinary search: O(log n), Two pointers: O(n)
Matrix/GraphDFS, BFS
Linked ListDummy node, Two Pointers, Fast and Slow pointers
Queue
Permutations, Combinations, SubsetsBacktracking
Smallest, Largest, Median in a streamTwo heaps
Solve In-placeSwap corresponding values, Store different values in the same pointers
Maximum/Minimum Subarray/Subset/OptionsDynamic programming