3GL Programming Environment

Introduction to Algorithms


"An algorithm is a formula, a recipe, a step-by-step procedure to be followed in order to obtain the solution to a problem.
To be useful as a basis for writing a program, the algorithm must:
  1. arrive at a correct solution within a finite time;
  2. be clear, precise and unambiguous;
  3. be in a format which lends itself to an elegant implementation in a programming language."
Peter Juliff, Program Design, 1990


1. Describing an Algorithm

1.1 Flow Charts

Generally uses only four constructs:
1. Start/End specified by a circle,
2. Commands in a rectangle,
3. Decisions in diamonds, with only a Yes or No answer,
4. and flow arrows indicating the next step to follow. Pointing backwards may indicate a loop.

eg.

Advantages:

Disadvantages:

1.2 Nassi-Schneiderman diagrams

Similar to data flow diagrams, except statements are structured so flow of control is downward. Statements are drawn directly under each other without the use of arrows to show the flow of control.
eg.

Uses only 3 constructs:
1. sequential statements placed directly under each other
2. iteration (or looping)
3. selection (or decision)
Start is at the top, End is at the bottom. Flow of control is downwards.

Advantages:

Disadvantages:

1.3 Pseudocode (structured English)

Statements are written in free-flowing English text, although some key words are defined to represent control structures.
Flow of control is top-to-bottom.

eg.
Calculate student grades
START with students' marks
     WHILE another student
          Read student's mark as imark
          IF imark < 50
              sgrade = "N"
          ELSEIF imark < 60
              sgrade = "D"
          ELSEIF imark < 70
              sgrade = "C"
          ELSE
              sgrade = "B"
          ENDIF
          PRINT sgrade as the student's grade
     ENDWHILE
END

Advantages:

Disadvantages: