Algorithms, Solving Problem Strategies

When solving an algorithm, I follow these strategies that were recommended by Colt Steele from his JavaScript Algorithms and Data Structures Masterclass on Udemy.

**Step 1: Understand the Problem**

*Ask questions to understand the problem:*

Can I restate the problem in my own words?

What are the inputs that go into the problem?

What are the outputs that should come from the solution to the problem?

Can the outputs be determined from the inputs? In other words, do I have enough information to solve the problem? (you may not be able to answer this question until you set about solving the problem. That’s worth considering the question at this early stage.)

How should I label the important pieces of data that are part of the problem?

**Step 2: Explore Examples**

- Coming up with examples can help you understand the problem better
- Examples also provide sanity checks that your eventual solution works how it should

What steps to take to Explore Examples?

- Start with Simple Examples
- Progress to More Complex Examples
- Explore Examples with Empty Inputs
- Explore Examples with Invalid Inputs

**Step 3: Break It Down**

Explicitly write out the steps you need to take

This forces you to think about the code you’ll write before you write it, and helps you catch any lingering conceptual issues or misunderstandings before you dive in and have to worry about details (e.g. language syntax) as well.

**Step 4: Solve the Problem**

if you can’t solve it…SOLVE A SIMPLER PROBLEM!

**Simplify**

- Find the core difficulty in what you’re trying to do
- Temporarily ignore that difficulty
- Write a simplified solution(often here, you’ll gain insight on how this work)
- Then incorporate that difficulty back in

**Step 5: Refactor your code**

Happy Coding!