Stands for Bottlenecks, Unnecessary , Duplicated work. These are the three main things to look for when optimizing code.
- Look for ununsed info in the problem
- Solve manually on an example and reverse engineer how the algorithm works
- Solve incorrectly and think about why the algorithm fails
- Use a fresh and different example
- What can we store or Memoize to save time?
- Make time vs space tradeoffs. Hash Structures are useful
- Pre-process information. Maybe sort the array first, etc.
- If array related, consider Sorting
- If search related, consider Binary Search
- If parsing Tree or Graphs or traversal or reversal consider a Stack
- If dealing with lots of strings, try putting them in a Prefix Tree
- Does the problem have optimal substructure? optimal solution to sub-problems helps get optimal solution to the problems? Consider Greedy Algorithm
- Does solving the problem for
n-1
help solve it forn
? Consider Dynamic Programming - Do you have to take min/max of a dynamic collection? Consider Heap