Professional Documents
Culture Documents
the data (e.g., smaller elements and larger elements or used elements and
unused elements).
Sometimes data structures themselves will not be very helpful for
overcoming bottlenecks. If this is the case, then you might want to consider
algorithmic techniques.
o The algorithmic techniques I typically consider, in order of my common
to least common, include:
Preprocessing
Sorting
Hashing
Binary search
Recursion
Sliding window / caterpillar method
Rolling hash
Dynamic programming / memoization
Divide and conquer
Square root decomposition
Pruning / backtracking
Math
Partitioning a range / Bucketing
Rewriting a problem as the difference of two sub problems
Sieving
Lazy evaluation
Amortization
Randomization
Greedy evaluation
Coordinate compression
Tortoise and hare pointer manipulation (slow and fast pointer)
Solving backwards (from expected output to input)
Solving for the complement of the answer and inverting the
result
Isolating concerns (e.g., solving for each dimension separately in
a 2D space problem)
If it is still unclear how to overcome the bottleneck, it might help to think of
ways to rephrase the problem. Try to brainstorm slightly different problems
whose solution will allow you to produce the solution to the original problem.
In order to rephrase a problem, break it down into its smallest parts and then
try breaking it down a different way. Maybe you can solve the problem with
Operation A and Operation B, but maybe you can also solve the problem with
Operation C and Operation D. Unfortunately, this step is the least structured
approach of the above steps, so it can end up being a giant time killer.