Methods of implementing algorithms

Methods of implementing algorithms imply the same as methods of representing or specifying algorithms. It means those methods an algorithm (i.e. an instruction) can be presented in. They include;

  1. Flow Charts: A graphical representation of instruction
  2. Pseudo-code (not executable because it does not follow appropriate syntax of any programming language. Written in mixture of commands and words) 
  3. Computer program: Could be written in any programming language like java, C++, VB, PHP…and so on. The instruction is executable because an instruction written in a computer program follows certain programming language syntax. 
  4. Decision table and tree: A graphical representation of instruction
  5. Mathematical formulas 
  6. Natural language: E.g. English representation of instruction. May also be in other spoken languages (can be in structured or unstructured sentences)

Now let’s look at some examples on methods of implementing algorithms; Problem 1: Find the area of a circle with radius=4. Algorithm: Let’s make a representation of the instruction for the above problem in a simple mathematical formula. The solution will look like these


Problem 2a: How to change motor oil Algorithm: let’s try to represent the algorithm instruction for the stated problem in a natural language description e.g English. Plain English description: Algorithm instruction for the problem stated will look like the following if represented in plain or unstructured English.


Problem 2b: The old world puzzle [the peasant problem] “A peasant finds himself on a riverbank with a wolf, a goat and a cabbage. He needs to transport all three to the other side of the river in his boat. However, the boat has room for only the peasant himself and one other item (either the wolf, the goat, or the cabbage). In his absence the wolf would eat the goat, and the goat would eat the cabbage. (Note: the peasant is a vegetarian but does not like cabbage and hence can eat neither the goat nor the cabbage)” 

Algorithm: Algorithm instruction for the peasant problem represented in structured English

Step 1: Starting from the initial point (i.e point of peasant, wolf, goat and the cabbage), the peasant pick goat only with him to cross to the other side of the river 

Step 2: Peasant return empty to the initial point to pick the wolf with him to cross to the other side of the river 

Step 3: Peasant return to the initial point picking the goat along. 

Step 4: Peasant drops the goat and pick the cabbage with him to cross to the other side of the river 

Step 5: Peasant will return empty to the initial point and pick the goat with him to cross to the other side of the river 

Step 6: Stop