An example is given below for the given problem statement
Problem Definition: A solution is needed which finds the circumference of a circle.
Algorithm in narrative form: Prompt the user to enter a non-negative value for the radius and store it. If the radius entered is negative or is not a number, keep on prompting the user and accept values until a suitable value is entered. Use the formula C=2*3.14* r to calculate and store the circumference. Output the circumference to the user and stop processing.
In our discussion, we consider well defined precise algorithms (in flowcharts or pseudocode) as compared with narrative algorithms.
Some of the reasons why algorithms are beneficial or important to the problem solving process are:
Algorithms serve as a blueprint for other programmers to follow
When problems are complex, an algorithm’s precise structure allows for an accurate development of a solution in parts. This documentation (the algorithm itself) is useful since it is difficult for the problem solver to remember many sub-processes , procedures and inputs/outputs to the problem.
Because algorithms are intended for a computer system and programming language, it allows us to design for that particular programming language’s structure and for efficiency ,given the limitations of system resources.
For example, an algorithm which processes DNA sequence information for matching DNA strands together (see Longest common sub sequence) can be developed strictly for solving the problem without considering system resources. In this case the algorithm still resembles programming language.
Usually in this type of general solution, array sizes are allowed to be very large or of infinite size. If memory becomes a constraint, we can now modify the algorithm to use say, array sizes at a maximum of 1000 to allow for the intended program to run within the limitation of our system resources.
Algorithms are easily testable when using dry runs and trace tables.