Optimize and Solve Techniques Sep 19, 2017
BUD
- B: Bottleneck. The option which has the largest O(). Try to reduce the time complexity of this step.
- U: Unnecessary work. Chop branches.
- D: Duplicated work. Use remember table to solve it.
DIY
- Give yourself a big example.
- Solve it intuitively.
- Abstract your solution to solve the algorithm problem.
Simplify and Generalize
Downcast the problem to a easier one. e,g,: String --> Character
Base case and Build
Calculate from n=1.
When calcultate n=2, check whether can based on n=1 result.
When calculate n=3, check n=2, n=1 result.
----------This type is often recursive.
Data Structure Brainstorm
- Linked List: easy modify, hard search
- Array: easy search, hard modify
- Binary Tree: Binary search tree
- Heap: min, max, median(maintain 2 heaps)
- Priority Queue: maintain sorted
- Stack: push and pop, same sequence
- Hash Table: deal with unsorted array
- Map: Key-Value, Hashmap