0% found this document useful (0 votes)
44 views

2 - Algorithm Notation - Pseudocode

The document discusses the properties and notation of algorithms. It defines algorithms as needing to be finite, definite, and effective. It then describes pseudocode as an informal way to describe algorithms using structured natural language. The document outlines common pseudocode elements like variables, inputs/outputs, control structures, and subalgorithms. It provides examples of sequence, selection, and repetition logic in pseudocode and conventions for writing clear pseudocode.

Uploaded by

Shakir khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

2 - Algorithm Notation - Pseudocode

The document discusses the properties and notation of algorithms. It defines algorithms as needing to be finite, definite, and effective. It then describes pseudocode as an informal way to describe algorithms using structured natural language. The document outlines common pseudocode elements like variables, inputs/outputs, control structures, and subalgorithms. It provides examples of sequence, selection, and repetition logic in pseudocode and conventions for writing clear pseudocode.

Uploaded by

Shakir khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Properties of Algorithms

 Finiteness: The algorithm must always terminate after a finite


number of steps.
 Definiteness: Each step must be precisely defined; the actions to be
carried out must be rigorously and unambiguously specified for
each case.
 Input: An algorithm has zero or more inputs, taken from a specified
set of objects.
 Output: An algorithm has one or more outputs, which have a
specified relation to the inputs.
 Effectiveness: All operations to be performed must be sufficiently
basic that they can be done exactly and in finite length.
Algorithmic Notation
 Pseudocode
 an informal high-level description of the operating
principle of an algorithm
 intended for human reading rather than machine reading
 uses natural language descriptions with some structural
conventions of a normal programming language
 No standard pseudocode syntax as a program in
pseudocode is not an executable program
 Flowcharts can be thought of as a graphical alternative
to pseudocode
Format of Pseudocode

 Two parts
 First part: a paragraph in natural language which tells
the purpose of algorithm, identifies the variables which
occur in algorithm and lists input data
 Second part: a list of instructions
Primitive operations

 READ and WRITE


 Assigning a value to a variable
 Arithmetic operations
 Comparing two numbers
 Array access
 Calling a sub-algorithm
 Returning from a sub-algorithm
Control Structures in Pseudocode
 Sequence Logic
 It is used to perform instructions in a sequence, that is one after
another.
 Pseudocode instructions are written in an order in which they are
to be performed.
Control Structures in Pseudocode
 Selection Logic
 It is used for making decisions and for selecting the proper path out of
two or more alternative paths in program logic
 It is also known as decision logic
Single Alternative
Control Structures in Pseudocode
 Selection Logic
Double Alternative
Control Structures in Pseudocode
 Selection Logic
Multiple Alternative
Control Structures in Pseudocode
 Iteration Logic (repetetive)
 It is used to produce loops when one or more instructions may be
executed several times depending on some of the conditions.
 It uses structures called the REPEAT FOR and REPEAT WHILE.
Repeat For
Repeat While
Subalgorithm

 A subalgorithm is a complete and independently defined algorithm


which is used by some algorithm (other subalgorithm)
 Receives values called arguments (or parameters), perform
computations, and sends back results to the calling algorithm
 A subalgorithm has a heading
 NAME(par1, par2,…,park)
 Return statement instead of Exit
Conventions in Pseudocode

 Write only one statement per line.


 Each statement in your pseudocode should express just one
action for the computer.
 Capitalized keyword
 READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE,
REPEAT, UNTIL
 Indent to show hierarchy
 For sequence, selection and looping
Conventions in Pseudocode

 End multi-line structures.


 All the initial keyword must always in line with the last or end of
the structure.
 Keep statement language independent.
 Number each instruction.
 Identifying Number
 Algorithm 2, Algorithm 4.3
 Write comments in each statement
Largest Number in Array
An array DATA of numerical values is in memory. We want to find index LOC and value
MAX of the largest element of DATA.
Largest Number in Array
An array DATA of numerical values is in memory. We want to find index LOC and value
MAX of the largest element of DATA.

You might also like