Friday, October 16, 2009

1-8 Pseudo Code or Algorithms Notations

Format: The format for the presentation of an algorithm consists of two parts.

· The first part is a paragraph which tells the purpose of the algorithm, identifies the variables, and lists the input data and size.

· The second part of the algorithm consists of the list of steps that is to be executed.

Steps, Control and Exit

· The steps of the algorithm are executed one after the other, beginning with step 1, unless indicated otherwise.

· Controls may be transferred to any step n by the statement “Go to Step n”, other control structure include conditional flow and repetitive flow like if–then-else, repeat-for, and repeat-while.


then they are executed from left to right.

· The algorithm is completed when the statement

Exit or return

is encountered.


Assignment Statement


Input and Output

· Data may be input and assigned to variables by means of a Read statement

Read : Variables names.

· Messages and data in variables may be output by means of a write and print statement

Write : Messages and/or variable names

Indentation

Indentation is used to indicate block structure. Using indentation, greatly reduces clutter while preserving, or even enhancing, clarity. For example in Algorithm, INSERTION – SORT (figure 1-3), the body of FOR loop begins on line 1 consists of lines 2-8, and the body of While loop that begins on line 5 contains lines 6-7, but not line 8. Indentation style applies to if-then-else, and repeat statements as well.

Control Structures

Algorithms and their equivalent computer programs are more easily understood if they mainly use self-contained modules and three types of logic, or flow of control, called

(1) Sequence logic, or sequential flow

(2) Selection logic or conditional flow

(3) Iteration logic, or repetitive flow

These three types of logic are discussed below, and in each case we show the equivalent flowchart.

Selection Logic (Conditional Flow)

Selection logic employs a number of conditions which lead to a selection of one out of several alternative modules. The structures which implement this logic are called conditional structures or If structures. For clarity, we will frequently indicate the end of such a structure by the statement.

[End of If structure.]

or some equivalent.

These conditional structures fall into three types, which are discussed separately.

(1) Single alternative. This structure has the form

If condition, then:

[Module A]

[End of If structure.]

The logic of this structure is pictured in Fig. 9(a). If the condition holds, then Module A, which may consist of one or more statements, is executed;

No comments:

Post a Comment