鶹Լ

How do we evaluate our solution?

There are several ways to evaluate solutions. To be certain that the solution is correct, it is important to ask:

  • does the solution make sense?

Do you now fully understand how to solve the problem? If you still don’t clearly know how to do something to solve our problem, go back and make sure everything has been properly . Once you know how to do everything, then our problem is thoroughly decomposed.

  • does the solution cover all parts of the problem?

For example, if drawing a cat, does the solution describe everything needed to draw a cat, not just eyes, a tail and fur? If not, go back and keeping adding steps to the solution until it is complete.

  • does the solution ask for tasks to be repeated?

If so, is there a way to reduce repetition? Go back and remove unnecessary repetition until the solution is efficient.

Once you’re happy with a solution, ask a friend to look through it. A fresh eye is often good for spotting errors.

Dry runs

One of the best ways to test a solution is to perform what’s known as a ‘dry run’. With pen and paper, work through the algorithm and trace a path through it.

For example, in Algorithms, a simple was created to ask someone their name and age, and to make a comment based on these. You could try out this algorithm – give it a dry run. Try two ages, 15 and 75. When using age 75, where does the algorithm go? Does it give the right output? If you use age 15, does it take you down a different path? Does it still give the correct output?

If the dry run doesn’t give the right answer, there is something wrong that needs fixing. Recording the path through the algorithm will help show where the error occurs.

Dry runs are also used with completed programs. Programmers use dry runs to help find errors in their program code.