Moe's Tech Blog

[Algorithm] 7 Steps to construct algorithm solution 본문

Algorithms/Notes

[Algorithm] 7 Steps to construct algorithm solution

moe12825 2022. 6. 20. 01:35

  • Step 1: Work example by hand
    • Should be a small problem to solve mentally
      • If problem is unclear --> ask or research
      • If domain knowledge is lacking (i.e. physics behind defining equation of motion) --> research or study till figured out
  • Step 2: Write down what you did
     
    • Write down exact steps on how you did it, and don't leave anything out
      • This steps are for small instance solved in step 1 (Not general step)
      • Do not do this mentally, or gloss over it
  • Step 3: Find patterns and generalize
    • Here steps are written as a solution to any instance of the problem
    • Is done by finding patterns to what I did, and replace it with more general behavior based on the pattern
      • Important tools for finding patterns are:
        • 1. looking for repeatitive behavior
        • 2. finding behavior which works sometimes but not always
        • 3. figuring out what conditions a behavior is performed
        • 4. figuring out how specific values you use relate to parameters you picked
    • How to find patterns?
    • Repeat step 1 and 2 when in trouble
      • Use different inputs
  • Step 4: Check inputs by hand
    • Is the step to find incorrect patterns and mistakes in step 3
    • Fix it all (or as much as you can) before moving to next step
  • Step 5: Translate to code
  • Step 6: Run test cases
    • Use particular input and check if it produces correct answer
  • Step 7: Debug failed test

References