# it-e-40 Algorithms and Flowcharts

The computer scientist Niklaus Wirth stated that:

Programs = Algorithms + Data

The algorithm is part of the blueprint or plan for the computer program; an algorithm is:

"An effective procedure for solving a problem in a finite number of steps."

It is effective, which means that an answer is found and it finishes, that is it has a finite

number of steps. A well-designed algorithm will always provide an answer, and it may not be the

answer you want but there will be an answer. It may be that the answer is that there is no answer.

A well-designed algorithm is also guaranteed to terminate.

The key features of an algorithm are:

Sequence (also known as Process),

Decision (also known as Selection)

Repetition (also known as Iteration or Looping)

In 1964 the mathematicians Corrado Bohm and Guiseppe Jacopini demonstrated that any

algorithm can be stated using sequence, decision and repetition. The work of Bohm and Jacopini

was of great importance since it eventually led to the disciplines of structured program design

that are much used today.

Sequence means that each step or process in the algorithm is executed in the specified order.

In an algorithm each process must be in the correct place, otherwise the algorithm will most

probably fail.

The Decision constructsIf ... then, If ... then ... else ...

In algorithms the outcome of a decision is either true or false, and there is no in between.

The outcome of the decision is based on some condition that can only result in a true or false

value[1].

The decision takes the form: if proposition then process

A proposition in this sense is a statement, which can only be true or false. It is either true

that today is Wednesday or false that today is Wednesday. It can't be both true and false. If the

proposition is true then the process, which follows the then, is executed.

The decision can also be stated as:

if proposition

then process1

else process2

This is the if ... then ... else ... form of the decision. This means that if the proposition is true

then execute process1 else or otherwise execute process2.

The first form of the decision if proposition then process has a null else, that is, there is no

else.

The Repetition constructsRepeat and While

Repetition takes two forms, the Repeat loop and the While loop.

The repeat loop is used to iterate or repeat a process or sequence of processes until some

condition becomes true. It has the general form:

Repeat

Process1

Process2

ProcessN

Until proposition

The repeat loop does some processing before testing the state of the proposition.

The while loop is used to iterate or repeat a process or sequence of processes while some

condition becomes true. It has the general form:

While proposition

Process1

Process2

ProcessN

The while loop tests the state of the proposition first.

There are four different ways of stating algorithms: Step-Form, Pseudocode, Flowchart, and

Nassi-Schneiderman.

The first two are written forms. The written form is just normal language.[2]A problem with

human language is that it can seem to be imprecise. In terms of meaning, what I write may not be

the same as what you read.[3]Pseudocode is also human language but tends toward more precision

by using a limited vocabulary.

The last two are graphically-oriented, that is they use symbols and language to represent

sequence, decision and repetition.

Flow charts are a graphical method of designing programs and once

the rules are learned they are very easy to draw. A well-drawn flow chart

is also very easy to read.

The major symbols are the DECISION (also known as selection)

and the SEQUENCE (or process) symbols. The START and STOP symbols are called the

terminals. The SUBPROCESS symbol is a variation on the sequence symbol.

1, imprecise [,impri'sais]

adj. 不精确的；不严密的；不确切的