ICSCT - Different Ways to Express Algorithms Lesson

Different Ways to Express Algorithms Lessons

A programming language follows a strict set of grammatical rules called syntax. Syntax is the rules for writing the code for the program. Since there are many programming languages, algorithm solutions are not written in a particular syntax. Most programs have common words that represent actions. Those words are used to develop algorithms that can then be translated into the syntax of a particular language.  

There are two common methods used for expressing algorithms.

Pseudocode is a textual description that uses English-like instructions combined with certain key programming terms to solve a problem.

These are guidelines for developing algorithms with pseudocode.

  1. Statements describe an action
  2. Steps should be numbered and follow a logical order
  3. Avoid any specific programming language
  4. Write clear, simple, and precise instructions so each statement can execute

Two Methods Expressing Algorithms are Pseudocode and Flowchart

These are common words used in pseudocode to write algorithms:  

Common Words to Write Algorithms
To perform arithmetic calculations            add, subtract, multiply, divide, calculate, increase, decrease
To transfer data move, store, replace, copy
To get Input/ Output print, display, set, get, assign, enter  
To assign data to inputs =,    equal  
To check conditions if, then, else, < , > , <=, >=, ==  (equivalent to)  
To repeat a set of instructions repeat until, while, end, for

A flowchart is another tool for creating algorithms.  It is a visual diagram represented by different shapes used to sequence the steps to perform a process.  Complex programs are usually designed as a flowchart.    

General rules for creating flowcharts

  1. All symbols of the flowchart are connected by flow lines (note arrows, not lines)
  2. Flow lines enter the top of the symbol and exit out the bottom, except for the decision symbol, which can have flow lines exiting from the bottom or the sides depending on true or false
  3. Flowcharts are drawn so flow generally goes from top to bottom
  4. The beginning and the end of the flowchart is indicated using the terminal symbol.

Flow_Chart_Symbols

Let's look at our problem from the previous lesson.  We created an IPO chart to find the inputs, processes, and outputs for finding the average of 3 numbers.  

Here is an example of the algorithm written in pseudocode and as a flowchart.

Example of writing an algorithm using pseudocode and as a flowchart.

 

Controlling Flow in Programming Activity

Complete the learning object below by clicking Begin then click the arrow button at the bottom.

Now that you know the basic control structures used in all programs, go through the learning activity on recognizing which control structure to use to solve a problem.  

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION