Computer Installation Notes

2. Role and Structure of algorithms

The role of algorithms is to support programmers in designing and implementing computer programs that solve a problem of importance. For example, consider a problem of finding the shortest route to travel between Kigali and Musanze. To solve such a problem, algorithm design follows a structured approach outlined below:
1. The programmer first analyses the problem to come up with problem specification as shown in Fig. 7.1. A problem specification defines input, processing and output required to solve the problem
2. Map the problem specification into an algorithm that defines the logic or
procedure for solving the problem.
3. Once an algorithm has been designed and tested against problem specifications,
implement it as a program using suitable programming languages.
4. Finally the program is installed on computers or portable devices to solve the
problem.

7.2 Design of Algorithms
Algorithms can be expressed in many ways such as using natural languages,
pseudocode, and flowcharts used for complex or technical algorithms. To avoid
ambiguities common in natural language statements, most programmers prefer using
structured design tools like pseudocode and flowcharts discussed in details later.

7.2.1 Natural language
The term natural language refers to the ordinary language likes English or Kinyarwanda
used by human beings to communicate with each other in speech or writing. Because
an algorithm is a procedure for solving a problem, the natural languages can be used
to express the steps to be followed to solve a specific problem. For example, the
following is natural language algorithm for how to make a hot sauce:
1. Before you prepare a hot sauce, make sure you have garlic that is peeled and
chopped, fresh lime juice, distilled white, vinegar, olive oil, molasses, turmeric
and salt.
2. Now, combine the pepper, garlic, lime juice, vinegar, mustard, oil, molasses,
turmeric, and salt in a blender and puree until smooth. Correct the seasoning,
adding more salt or molasses to taste.
3. Transfer the sauce to a clean bottle. You can serve it right away, but the flavour
improves if you let it age for a few days.
The above ‘algorithm’ is a recipe, that is, a step-by-step instructions that takes raw
ingredients and produces a tasty product – hot sauce. However, one of the limitations
of such an algorithm is that it tends to be verbose or ambiguous. Furthermore, there
are different languages in the world which makes it difficult for an algorithm written
in a particular language to be universal. To avoid ambiguities inherent in natural
languages, there are language independent tools such as pseudocode and flowcharts discussed later in this section.