Welcome to Rithm’s series on problem-solving strategies. If you’re just joining us, you may want to start at the beginning. Here’s a list of the articles we’ve written:
- Understand the Problem
- Explore Concrete Examples
- Break It Down
- Solve a Simpler Problem
- Use Tools Strategically
- Look Back and Refactor
We’ve talked about how to initially approach a problem by understanding what it’s asking and exploring concrete examples. We’ve also discussed developing a plan to solve the problem, by breaking it down into smaller and more manageable pieces.
But planning is sometimes easier said than done. After you’ve broken a problem down, you may find that one of the components is quite difficult. For particularly challenging problems, you may not even know how to break down the problem at all. In these situations, it may help to turn to our next problem solving strategy: solve a simpler problem.
Strategy #4: Solve a Simpler Problem
In How To Solve It, Polya writes that “If there is a problem you can’t solve, then there is an easier problem you can solve: find it.”
The idea here is that you want to relax the assumptions of the original problem, without sacrificing too much of the nature of the solution. In this way, the hope is that you can simplify the problem sufficiently that it becomes solvable, and that the solution will provide insight into the original problem.
To put it another way, solving a simpler problem is about finding the core difficulty in what you’re trying to do, trying to temporarily ignore that difficulty, and then incorporate that difficulty back in to a solution you derive for the simplified problem.
An Example
Let’s return to our coding example from before:
Write a function which takes in a string and returns counts of each character in the string.
Someone who can’t solve this problem could be struggling for a variety of reasons. Here are a few:
- They have trouble with looping and iteration.
- They aren’t comfortable manipulating keys and values in objects,
- They aren’t comfortable with string manipulations (for instance, not differentiating between upper- and lowercase letters in the count),
Depending on where the difficulty lies, there are a number of simpler problems that could try to address the underlying problem:
- Rather than returning an object of character counts, return an object with the first character as a key and a value of 1. In other words, only count the first character. (This problem requires no iteration, it focuses more on understanding key-value pairs in objects.)
- Rather than counting all characters, return an object whose keys are the characters in the input string, and whose values are all 1. This requires looping, but less manipulation of values in an object.
- Make some simplifying assumptions on the input. For example, assume the input string consists of only lowercase letters. This simplification removes the need to worry about the distinction between uppercase and lowercase characters, as well as the need to worry about characters that aren’t letters.
Solving a simpler problem is all about trying to find the root of the difficulty you’re experiencing, and modifying the problem so that the difficulty can be safely ignored.
One caveat with this approach is that it’s possible to oversimplify a problem. When this happens, you may wind up with an easier problem that you can solve, but whose solution provides little insight into the original problem.
Here’s one oversimplification of the current example: rather than returning a count for each character, just return a count of the total number of characters. Here are two solutions to this simplified problem:
// Solution 1 function charCount(str) { var count = 0; for (var i = 0; i < count.length; i++) { count++; } return count; } // Solution 2 function charCount(str) { return str.length; }
While the first solution may be helpful for someone still struggling with for
loops in JavaScript, the second solution provides no insight into the nature of the original problem.
But not to fear; solving a simpler problem is a process. If you find that your simplification makes the problem too simple, try to find a problem that is harder than your simplification, but still easier than the original problem.
And if you’re having trouble solving your simpler problems too, there are a couple more problem solving strategies that may help. We’ll discuss another strategy next time.