Course Introduction to Programming

Representation Forms

Course's Page 6 min Text by
User Image
Julio Nunes Avelar

In this lesson, we will understand why we represent algorithms and the three main types of algorithm representation. This class will be divided into:

  • Why represent an algorithm?
  • Narrative description;
  • Narrative description example;
  • Pseudocode;
  • Pseudocode example;
  • Flowchart;
  • Formats used;
  • Example of flowchart.

Why represent an algorithm?

Each language has its own rules; this makes programmers used to certain languages not understand others. An algorithm representation is used to make it possible for anyone to understand how a certain algorithm works without having to understand a specific programming language.

Narrative description.

In the narrative description, the algorithm is described using natural language (the usual way of speaking), without details of how to perform the commands and with a more straightforward representation.

Example of Narrative Description

Algorithm to calculate the grade average of a student

  1. Take note of the first grade;
  2. Take note of the second grade;
  3. Calculate the arithmetic mean of the grades;
  4. If the average is greater or equal to 7, the student is approved;
  5. If the average is less than 7 but greater or equal to 4, the student has to go to summer school;
  6. If the average is less than 4, the student has failed;

(This is how it is usually done in Brazil and the grades go from 0, the worst, to 10, the best.)

Pseudocode.

Pseudocode uses a representation in code form, but the code uses commands in natural language, it is similar to code written in some programming languages and its translation into some programming language is simpler.

Example of pseudocode.

Algorithm to calculate the grade average of a student using pseudocode, soon you will see that this representation is much more like a conventional programming language.

  1. Variables: Grade1, Grade2, Average
  2. Read(Grade1, Grade2)
  3. Average = (Grade1+Grade2)/2
  4. If (Average >= 7) Print "Student is approved"
  5. If (Average < 7 and Average >= 4) Print "Student goes to summer school"
  6. If (Average <= 4) Print "Student fails"

Flowchart.

The Flowchart uses a representation in graphic form. The algorithm representation is made using geometric shapes and a brief description of which action is associated with each shape.

Formats used.

Main formats used:

Start and end of the algorithm:

Data input and output:

Decision:

Process:

Example of flow chart.

Algorithm to calculate a student's grade average using a flowchart. Notice that for each action type a different type of figure is used.

We hope you've enjoyed the class, see you next time ๐Ÿ˜„