Heap
- Functions: peek(), pop(), push()
- Functions: peek(), poll(), add()/offer()
- Linked List
- PriorityQueue: new Comparator 很重要
Tree
Depth-first Search
Breadth-first Search
- If BST not given, can use TreeSet
Binary Indexed Tree
Segment Tree
Union Find
Trie
Graph
Topological Sort
- Arrays.asList([1,2,3]);
Two Pointers
Binary Search
Sort
Map
Hash Table
- contains: O(1)
- set.add(...) returns false if there is duplicate. This operation won't change the existing set.
- 转换成string
- % mod, 除法
- Integer.MAX_VALUE, Integer.MIN_VALUE; if overflow, use long
- s.toCharArray()
- String.valueOf(charArrary)
- sb = new StringBuffer()
- sb.reverse(), sb.append(), sb.deleteCharAt(), sb.length()
- Bit OR |, AND &, XOR ^
- Bit shift: <<, >>
Optimization problems:
- memoization && subproblems
- Fibonacci
- Shortest paths
- guessing && DAG View
- Finding all (or some) solutions to some computational problems, notebaly constraint satisfaction problems
- It attemps to build/find all candidates and abandon partial candidate when the candidates appears not to be suitable(backtracking, backing off from wrong candidates)
Memoization
Minimax
Reservoir Sampling
Geometry
Brainteaser
Greedy
Divide and Conquer
- ex: dfs
- always find the entry point or terminating point
- watch out for the return or result of recursed function
Design