Java Reference
In-Depth Information
Step 1 Consider various ways to simplify inputs.
In your mind, fix a particular input or set of inputs for the problem that you want to
solve.
Think how you can simplify the inputs in such a way that the same problem can be
applied to the simpler input.
When you consider simpler inputs, you may want to remove just a little bit from
the original input Ȍmaybe remove one or two characters from a string, or remove a
small portion of a geometric shape. But sometimes it is more useful to cut the input
in half and then see what it means to solve the problem for both halves.
597
598
In the palindrome test problem, the input is the string that we need to test. How can
you simplify the input? Here are several possibilities:
ȗ
Remove the first character.
ȗ
Remove the last character.
ȗ
Remove both the first and last characters.
ȗ
Remove a character from the middle.
ȗ
Cut the string into two halves.
These simpler inputs are all potential inputs for the palindrome test.
Step 2 Combine solutions with simpler inputs into a solution of the original
problem.
In your mind, consider the solutions of your problem for the simpler inputs that
you discovered in Step 1. Don't worry how those solutions are obtained. Simply
have faith that the solutions are readily available. Just say to yourself: These are
simpler inputs, so someone else will solve the problem for me.
Now think how you can turn the solution for the simpler inputs into a solution for
the input that you are currently thinking about. Maybe you need to add a small
quantity, related to the quantity that you lopped off to arrive at the simpler input.
Search WWH ::




Custom Search