Moe's Tech Blog
[Algorithm] 7 Steps to construct algorithm solution 본문
- 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
- Should be a small problem to solve mentally
- 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
- Write down exact steps on how you did it, and don't leave anything out
- 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
- Important tools for finding patterns are:
- How to find patterns?
- 1. Create Tables (see 2:10 in https://www.coursera.org/learn/java-programming/lecture/kNS01/java-math)
- 1. Create Tables (see 2:10 in https://www.coursera.org/learn/java-programming/lecture/kNS01/java-math)
- 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
- Java Programming: Solving Problems with Software, Duke University: https://www.coursera.org/learn/java-programming
'Algorithms > Notes' 카테고리의 다른 글
[알고리즘] 재귀함수에 관하여 (0) | 2022.04.21 |
---|---|
[알고리즘] 그리디 알고리즘에 관하여 (0) | 2022.04.18 |
[알고리즘] 계수 정렬에 관하여 (0) | 2022.04.17 |
[알고리즘] 퀵 정렬에 관하여 (0) | 2022.04.16 |
[알고리즘] 삽입 정렬에 관하여 (0) | 2022.04.16 |