Lecture 2 Study of Algorithms
Lecture 2 Study of Algorithms
Algorithms.
Experimental Study:
Some typical inputs.
A real program.
Pseudocode Conventions
What is the Pseudocode?
Pseudocode is a high-level description of an algorithm that
uses natural language mixed with some programming
language-like constructs.
It provides a step-by-step outline of the algorithm’s logic
without being tied to any specific programming language
syntax.
Pseudocode allows algorithm designers to express their ideas
in a concise and understandable manner before actual coding
takes place
Benefits of using Pseudocode
{and}.
An Identifier begins with a letter: max.
Assignment of values to variables is done using
while (condition) do
{
(statement 1)
………………
(statement n)
}
For loop:
for variable:=value1 to value2 step step do
{
(statement 1)
………………
(statement n)
}
Pseudocode Conventions (Cont.)
Repeat-until loop:
repeat
{
(statement 1)
…………
(statement n)
} until (condition)
Conditional statement:
if (condition) then (statement)
if (condition) then (statement 1)
else (statement 2)
Pseudocode Conventions (Cont.)
Case statement:
case
{
: (condition 1): (statement 1)
………………….
: (condition n): (statement n)
: else: (statement n+1)
}
Input and output are done using: read and write.
There is only one type of procedure: Algorithm.
An algorithm consists of a heading and a body.
The heading of an algorithm takes the form