6.4 Notations for Describing Algorithms


6.4 Notations for Describing Algorithms

An algorithm describes the data and the transformation of that data. The transformation part of a problem solution consists of a sequence of detailed instructions. The order of how the instructions are to be carried out is very important.

A notation is some syntax convention used for the informal description of an algorithm. Two well-known design notations to describe algorithms are:

  • Flowcharts

  • Pseudo-code

6.4.1 Flowcharts

A flowchart is a visual notation for describing a sequence of instructions, in a precise manner. Flowcharts consist of a set of symbols connected by arrows. These arrows show the order in which the instructions are to be carried out. The arrows also show the flow of data.

Figure 6.1 shows some of the basic symbols used in a flowchart, and the arrows that connect these symbols. A flowchart that describes a problem solution always begins with a start symbol, and always ends with a stop symbol. The start symbol always has an arrow pointing out of it, and the stop symbol always has one arrow pointing into it. A well-defined flowchart must have a starting point represented by a start symbol and a terminating point represented by a stop symbol.

click to expand
Figure 6.1: Basic symbols used in flowcharts.

The most general symbol is the transform symbol, also called a process symbol. The symbol is represented as a rectangle and represents any computation or sequence of computations carried out on some data. There is one arrow point in and one arrow point out of the symbol. In a flowchart, a rectangle is usually called a process block or simply a block of instructions.

The symbol on the right of Figure 6.1 has the shape of a vertical rhomb (or diamond), and it represents a selection of alternate paths in the sequence. Sometimes, this symbol is called a decision block or a conditional block because the sequence of instructions can take one of two directions in the flowchart, depending on the outcome of the condition.

Another basic symbol in a flowchart is the one that represents the input or output operation on the data. This symbol is shown in Figure 6.2. There is one arrow pointing into the block and one arrow pointing out from the block.


Figure 6.2: The input/output symbol in a flowchart.

The flowchart symbols described are the basic symbols that are used to represent the algorithm of small problems. For larger or more complex algorithms, the flowcharts can become too large to be used effectively. For such cases, flowcharts are used only for the high-level description of the algorithms.

Figure 6.3 shows a sequence of three instructions, each in a separate flowchart box. The arrows precisely illustrate the order in which the instructions must be executed.


Figure 6.3: Flowchart of a sequence of three blocks of instructions.

6.4.2 Pseudo-code

Pseudo-code is structured notation that can be very informal; it uses an English description of the set of transformations that define a problem solution. It is a natural language description of an algorithm.

Note

Pseudo-code is much easier to understand and use than an actual programming language. It can be used to describe relatively large and complex algorithms.

If a few design rules are followed, another advantage is that it is almost straightforward to convert the pseudo-code to a programming language like KJP. The notation used in a programming language is much more formal and allows the programmer to clearly and precisely describe the algorithm in detail.

Various levels of algorithm descriptions are normally necessary, from a very general level for describing a preliminary design, to a much more detailed description for describing a final design. Thus, the first level of description is very informal, and the last level is formal.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net