Algorithm Flowchart Pseudocode
Algorithm Flowchart Pseudocode
1. Overview
The term "algorithm" is used for describing the sequence of actions leading to the
solution of the given problem.
The field of mathematics known as the theory of algorithms is dedicated to the study of
the properties, methods of recording, the creation of new algorithms and the application
of different algorithms.
Basic requirements to the algorithms used in computer science are the following:
Discreteness: the algorithm should lead to the solution of the assigned problem,
introducing the solution of the problem as a sequence of actions.
Finiteness: the number of steps of the algorithm must be finite.
Efficiency: the algorithm must be such that a solution could be found in a finite
and reasonable time.
Certainty (or precision, determinacy): algorithm's steps have to allow
unambiguous interpretation. Each algorithm has to be devised for a certain
performer. In order that the performer could solve the problem according to the
given algorithm, it is necessary that it would be able to understand and perform
each action instructed by the algorithm. Any action of the algorithm must be
strictly defined and described in each case.
Effectiveness: the algorithm must produce concrete results. Moreover, the
message that the problem has no solution means the result.
Versatility: the algorithm must be developed so that it could be used to solve
similar problems (For example, the rules of addition and multiplication of
numbers are suitable for any numbers and not for any specific ones.).
There are two commonly used tools to help to document program logic (the algorithm).
These are flowcharts and pseudocode. Generally, flowcharts work well for small
problems but pseudocode is used for larger problems. We will use both methods here.
Flowchart is a graphical representation of an algorithm as series of interrelated
functional blocks, each of which corresponds to the implementation one or more actions.
In a flowchart each type of actions (data input, evaluating expressions, checking the
conditions, management of the repetition of actions, end processing, etc.) corresponds to
the geometric shape, presented in the form of block symbol. Inside the block the
description of the appropriate action is given. The blocks are connected by lines of
transitions that determine the order of implementation of the actions.
Following,
Branching,
Loop.
Pseudocode:
Activity 1
Activity 2
Activity 3
Verbal description:
Example: Draw a flowchart for this function: y = x2 + 4x + 3. You can use only the
operations of addition and multiplication.
You can see that it is not a precise definition of the task. It is not defined how we must
compute the function. Hence, we assume in this case that it is possible to calculate the
value of the function at once. Therefore, we can depict the following flowchart:
2. The basic structure of "branching" is a branching algorithm. Depending on the
result of the check of a condition («Yes» or «No»), it provides the choice one of the
alternative paths of the algorithm. Each of the pathways leads to a common output,
so that the algorithm will continue regardless of which path is chosen.
In the following, we assume the structure "branching" exists in four basic versions:
1) IF-THEN
Pseudocode:
IF Decision THEN
Activity 1
END-IF
Verbal description:
If the Decision is true ("Yes"), the following actions(Activity 1) are
performed, otherwise the transition to the next step is made at once, if
any.
Pseudocode:
IF Decision THEN
Activity 1
ELSE
Activity 2
END-IF
Verbal description:
If the Decision is true ("Yes"), the following actions (Activity 1) are
performed, else ("No") the Activity 2 is performed.
3) SELECT
Pseudocode:
SELECT
CASE Decision 1:
Activity 1
END-CASE
CASE Decision 2:
Activity 2
END-CASE
CASE Decision 3:
Activity 3
END-CASE
...
END-SELECT
Verbal description:
4) SELECT-ELSE
Pseudocode:
SELECT
CASE Decision 1:
Activity 1
END-CASE
CASE Decision 2:
Activity 2
END-CASE
CASE Decision 3:
Activity 3
END-CASE
...
ELSE
Activity 4
END-SELECT