Lecture 3: Algorithm Development

advertisement
Lecture 3: Algorithm Development
The crucial state of problem solving with the computer is the design of the algorithm and the
underlying data structure. An algorithm is a precisely, expressed procedure for obtaining the
problem solution which is subsequently presented to a computer in the selected programming
languages.
ALGORITHM
A finite set of instructions that specify a sequence of operations to be carried out by the computer
in order to solve a problem or class of problems. In short, it is a recipe in solving the problem.
Two Forms of Expression to Present an Algorithm
1. Pseudocode
- a textual representation of an algorithm, where, the actions to be taken by the machine
are specified in a manner close to a natural language with the control structures
imposing the logic.
2. Flowchart
- a diagram representing the logical sequence in which a combination of steps or
operations is to be performed. It consists of labeled geometrical symbols that are
interconnected to provide pictorial representation of a data processing procedure. The
predefined graphic symbols of a flowchart are also used to indicate various operations
and flow of control.
- A flowchart is actually a visual representation of an algorithm.
1
FLOWCHARTING SYMBOLS
1. INPUT / OUTPUT SYMBOL - represents an instruction to an input or output device
2. PROCESSING SYMBOL - represents a group of program instructions that perform
processing functions such as arithmetic operations, or to compare, sort, etc.
3. DECISION SYMBOL - denotes a point in the program where more than one path may be
taken. It is used to document points in the program where, based on variable conditions, a
branch to alternative paths is possible.
4. PREPARATION SYMBOL - this symbol is used to represent an instruction or group of
instructions that will alter, or modify a program s course of execution. It is commonly
used to specify operations such as control, index register, initialization, switch setting and
in indicating loops.
5. TERMINAL SYMBOL - used to designate the beginning and end of the program.
6. PREDEFINED PROCESS SYMBOL - a specialized process symbol that represents
named operation or programmed step not explicitly detailed in the program flowchart. As
a subroutine symbol, it can be used when a procedure needs to be repeated several times.
Rather than write the instructions for the procedure each time it is needed, the predefined
process symbols is used.
7. ON PAGE CONNECTOR - is a non-processing symbol that is used to connect one part
of the flowchart to another without drawing flow lines. It denotes an entry or an exit from
another part of the flowchart and is also used to change the reading sequence of a
flowchart on the same page.
2
8. OFF PAGE CONNECTOR - this type of connector is used instead of an on-page
connector to designate entry to and exit from a page when a flowchart requires more than
one page.
9. FLOWLINES are used to show reading order or sequence in which the flowchart
symbols are to be read.
PROPERTIES OF ALGORITHM
1. Finiteness
- the execution of programmed algorithm must be completed after a finite number of
operations have been performed.
2. Absence of Ambiguity every step an algorithm should take ought to have a unique
interpretation.
3. Sequence of Definition the sequence of steps of the algorithm must be specified. An
algorithm ought to have a unique initial instruction, and every instruction must have a
unique successor for the given input data
4. Input and Output Definition
a. Inputs are data items presented to the algorithm.
b. Outputs are data items presented to the outside world as a result of execution of a
program based on the algorithm
5. Effectiveness an algorithm must have sufficient information or its result must always be
defined.
6. Scope of Definition an algorithm must apply to a specific problem or class of problems.
The range of inputs had to be predefined since it will determine the generality of the
algorithm.
3
Download