I'm reading Cracking the Coding Interview and one of the chapters discusses few approaches to designing and optimizing an algorithm:

  • BUD
  • DIY
  • Simplify and Generalize
  • Base Case and Build
  • Data Structure brainstorm

Below is the short description of those approaches.

BUD

BUD means Bottlenecks, Unneeded work and Duplicated work. In this approach we design the simplest possible algorithm which will be probably the slowest one as well. Then we are looking for bottlenecks, work which is not needed and duplicated work, and we are trying to get rid of those.

DIY

DIY means Do It Yourself. In this technique we are simulating the way we would solve the problem as humans. We need to keep in mind the ways our brain works through the problem and all explicit and implicit optimizations it's doing.

Simplify and Generalize

In this approach, we are first simplifying a problem and looking for a solution for it. Next we try to generalize it to more complex cases.

Base Case and Build

In this technique we are using the simplest possible cases of the problem. Like instead of general n as an input, we are first trying to deliver a solution for n = 1 and n = 2. Based on that solution, we are then implementing the solution for general cases. This technique often leads to natural recursive solutions.

Data Structure brainstorm

In this approach we are going through different data structures, and we are trying to use one of them to solve our problem.