Documente Academic
Documente Profesional
Documente Cultură
Code
MSIT
Agenda
History of Algorithm
Definition of Algorithm
Algorithm criteria
Different ways to write Algorithm
What is Pseudo Code?
Need for Pseudo Code.
Pseudo Code Standards.
Different Constructs.
History Of Algorithm
The word algorithm comes from the name
of a Persian author ,Abu Ja’far Mohammed
bin Musa al Khowarazimi(825 A.D.).
This word has taken on a special
significance in computer science, where
“algorithm” has come to refer to a method
that can be used by a computer for the
solution of a problem.
That is what makes algorithm different
from words such as process, technique, or
method.
Definition of Algorithm
An algorithm is a finite set of instructions that, if
followed ,accomplishes a particular task.
For example:
Performing arithmetic operations on integers is an
example of effective operation.
But arithmetic operations on real numbers violates
effectiveness.
As each value may be expressible only by infinitely long
decimal expansions.
Adding such values violates effectiveness.
Contd..
We can describe an algorithm in many
ways .
Writing pseudo code will save you time later during the
construction & testing phase of a program's development.
Pseudo code standards
Each textbook and each individual designer may
have their own personal style of pseudo code.
IF condition THEN
sequence 1
ELSE sequence 2
ENDIF
The ELSE keyword and "sequence 2" are optional. If the condition
is true, sequence 1 is performed, otherwise sequence 2 is
performed. Example
IF HoursWorked > NormalMax THEN
Display overtime message
ELSE Display regular time message
ENDIF
WHILE
The WHILE construct is used to specify a loop with a test at the
top.
The beginning and ending of the loop are indicated by two
keywords WHILE and ENDWHILE. The general form is:
WHILE condition
Sequence
ENDWHILE
CASE expression OF
condition 1 : sequence 1
condition 2 : sequence 2
...
condition n : sequence n
OTHERS:
default sequence
ENDCASE
CASE grade OF
A : points = 4
B : points = 3
C : points = 2
D : points = 1
F : points = 0
ENDCASE
REPEAT-UNTIL
This loop is similar to the WHILE loop except that the test is
performed at the bottom of the loop instead of at the top.
Two keywords, REPEAT and UNTIL are used. The general form is:
REPEAT
Sequence
UNTIL condition
Algorithm Sum(a,b)
Begin:
Set c=a +b;
Display c;
End:
Exception Handling
Handling of errors in the code manually is called
Exception Handling.
BEGIN
statements
EXCEPTION
WHEN exception type
statements to handle exception
WHEN another exception type
statements to handle exception
END
Recursive Algorithms
Calling a sub-routine within itself is called
recursive sub-routine.
Algorithm RSum(a,n)
{
If (n<=0) then return 0.0;
Else return RSum(a,n-1)+a[n];//calling
subroutine within itself.
}
Example:
Algorithm Fibonacci (n)
//compute the nth Fib`onacci number
Begin:
if n<=1 then
Display n;//write output to console
else
set n1=0;
set n2=1;
for i=2 to n do
set res=n1+n2;
n1=n2;
n2=res;
display res;//writing the result to console
End:
Example
Algorithm Fibonacci(n)
//compute the nth Fib`onacci number
{ if(n<=1) then
write(n);//write output to console
else
{
n1:=0;n2:=1;
for i:=2 to n do
{
res:=n1+n2;
n1:=n2;
n2:=res;
}
write(res);//writing the result to console
}
}
http://en.wikipedia.org/wiki/Pseudocode
http://www.csc.calpoly.edu/~jdalbey/SWE/pdl_std.ht
http://www.wiley.com/college/busin/icmis/oakman/ou
http://www.webopedia.com/TERM/P/pseudocode.htm