0 ratings0% found this document useful (0 votes) 19 views8 pagesDaa Notations of An Algorithm Unit-1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Pane eur ete enters tere nue am
ha sgerNoml entre of wenibigaoes mpuicsoos Bese 5 Bvay Foy 5
obtaining a required output for any legit
AlgorithmEa renee enn manne ee
FIGURE 1.1 The notion of the algorithm.
Itis a step by step procedure with the input to solve the problem in a finite amount of
time to obtain the required output.
The notion of the algorithm illustrates some important points:
© The non-ambiguity requirement for each step of an algorithm cannot be
compromised.
© The range of inputs for which an algorithm works has to be specified carefully.
© The same algorithm can be represented in several different ways.
There may exist several algorithms for solving the same problem.
Algorithms for the same problem can be based on very different ideas and can
the problem with dramatically different speeds.Ay a Mep vy sep proceuure wiur We mpUL LU suIvE WE plovIEME ME UKE aU OF
time to obtain the required output.
‘The notion of the algorithm illustrates some important points:
© The non-ambiguity requirement for each step of an algorithm cannot be
compromised.
© The range of inputs for which an algorithm works has to be specified carefully.
The same algorithm can be represented in several different ways.
‘© There may exist several algorithms for solving the same problem.
* Algorithms for the same problem can be based on very different ideas and can
solve the problem with dramatically different speeds.
Characteristics of an algorithm:
> Input : Zero / more quantities are externally supplied.
Output + Atleast one quantity is produced.
PO vetichiiee — + Enc hietruction be chor snd unambiguous.
Finiteness = If the instructions of an algorithm is traced then for all cases the
algorithm must terminates after a finite number of steps.
Efficiency: Every instruction must be very basic and runs in short time.Ea oeeMeae me en une ce ue eur Noe enue Retm A ee YIN TPS TENOR
1.An algorithm is a procedure. It has two parts; the first part is head and the
second part is body.
2. The Head section consists of keyword Algorithm and Name of the algorithm
th parameter list. E.g. Algorithm namel(p1, p2,....p3)
The head section also has the following:
Problem Description:
/Anput:
Output:
3.In the body of an algorithm various programming constructs like if, for, while
and some statements like assignments are used.
4. The compound statements may be enclosed with { and } brackets. if, for, while
can be closed by endif, endfor, endwhile respectively. Proper indention is must for
block.
‘5.Comments are written using // at the beginning.
6. The identifier should begin by a letter and not by digit. It contains alpha numeric
letters after first letter. No need to mention data types.
7."The left arrow “e—” used as assignmentThe head section also has the following:
//Problem Description:
Mnput:
Output:
3.In the body of an algorithm various programming constructs like if, for, while
and some statements like assignments are used.
4. The compound statements may be enclosed with { and } brackets. if, for, while
can be closed by endif, endfor, endwhile respectively. Proper indention is must for
block.
5.Comments are written using // at the beginning.
6. The identifier should begin By a Tetter and not by digit. It contains alpha numeric
letters after first letter. No need to mention data types.
7. The left arrow “+ used as assignment operator. E.g. v—10
8. Boolean operators (TRUE, FALSE), Logical operators (AND, OR, NOT) and
4.) are also used.
10. Input and Output can be done using read and write.
rray{], if then else condition, branch and loop can be also used in algorithm.
Example:
The greatest common divisor(GCD) of two nonnegative integers m and n (not-both-
zero), denoted ged(m, n), is defined as the largest
evenly, ie., with a remainder of zero.8. Boolean operators (TRUE, FALSE), Logical operators (AND, OR, NOT) and
9, Relational operators (<<=, >, >=,=, 4, >) are also used.
10.Input and Output can be done using read and write.
11 Array{], if then else condition, branch and loop can be also used in algorithm.
Example:
The greatest common divisor(GCD) of two nonnegative integers m and n (not-both-
zero), denoted ged(m, n), is defined as the largest integer that divides both m and n
evenly, i.e., with a remainder of zero.
Euclid’s algorithm is based on applying repeatedly the equality
ged/m, n) = ged(n, m mod n),where m mod n is the remainder of the division of m by n,
until m mod 1 is equal 10 0, Since ged/m,0) = m, the last value of m is also the greatest common
divisor of the initial m and 1.
gcd/60, 24) can be computed as follows:ged/60, 24) = ged(24, 12) = ged 12, 0,
thm for cor le steps
0, return the value of m as the answer and stop; otherwise, proceed to Step 2.
vide m by n and assign the value of the remainder to r.
Step 3 Assign the value of n to m and the value of r to n. Go to Step 1.
m1)Eira iee Ree Tey
Fare netortnmth senor
evenly, i.c., with a remainder of zero.
Euclid’s algorithm is based on applying repeatedly the equality
gcd(m, n) = ged(n, m mod n),where m mod n is the remainder ofthe division of m by n,
until m mod 7 is equal to 0, Since ged(m.0) = m, the last value of m is also the greatest common
divisor of the mandn.
gcd/60, 24) can be computed as follows:ged(60, 24) = ged24, 12) = ged(12, 0) = 12.
Step 1 If'm = 0, return the value of m as the answer and stop; otherwise, proceed to Step 2.
Step 2 Divide m by 7 and assign the value of the remainder to r.
Step 3 Assign the value of 7 to m and the value of r to n. Go to Step 1.Notation of
id’s algorithm for ting gedém, n) in
ALGORITHM Euclid_ged(m, n)
"wo nonnegative, not-both-zero integers m and 7
Output: Greatest common divi
—while n #0 do
— rm mod nme—n
Seaieiersienienis
return
FUNDAMENTALS OF ALGORITHMIC PROBLEM SOLVING
A sequence of steps involved in designing and analyzing an ¢