You are on page 1of 8

Algorithm &

Pseudo Code

Syed Zaid Irshad


Outline

– Algorithm
– What is an algorithm?
– How are mathematical statements and algorithms related?
– What do algorithms have to do with computers?
– Pseudo Code
– What is pseudocode?
– Writing pseudocode
– Pseudo Code vs Algorithm
What is an algorithm?

– An algorithm is a finite, explicit step-by-step procedure for solving a specific problem or


accomplishing a specific goal.
– We frequently talk about algorithms in mathematical terms, and many algorithms are
expressed using notation borrowed from mathematics, but algorithms aren't necessarily
mathematical in the operations performed, or in the results produced.
– In general, an effective algorithm has these characteristics:
– Explicit, complete, and precise initial conditions;
– A finite, complete, unbroken
– Explicit, complete, and precise terminal (stopping) conditions
How are mathematical statements
and algorithms related?
5(𝐹 − 32) = 9𝐶
– First, convert expression into a form that expresses C as a function of F:
C=5/9 * (F – 32)
– Now it's a straightforward task to write an algorithm (based on the standard order
of arithmetic operations) to convert from Fahrenheit to Celsius.
– Start with a given temperature in degrees Fahrenheit.
– Subtract 32 from the value used in step # 1.
– Multiply the result of step # 2 by 5.
– Divide the result of step # 3 by 9.
– The result of step # 4 is the temperature in degrees Celsius.
What do algorithms have to do
with computers?
– Computer programming consists, in large part, of creating unambiguous, step-by-step
procedures for the computer to follow, to produce specific results. In other words, we might
say that computer programming is almost all about algorithms.
– In many respects, computers are electronic idiot savants: they can perform amazing feats of
calculation and memory, but without our help, they're almost totally incompetent when it
comes to applying those abilities to practical problems.
– Want to compute the sine of an angle? How about computing the natural logarithm of a
number? These tasks are easy for a computer –, in most modern computers, these operations
are built into the CPU itself.
– But if you want to plot the graph of y=sin x on the screen, or balance your cheque book, or
compute the area of the region 1≤x≤100,0≤y≤1/x, the computer is helpless – until someone
writes algorithms to accomplish these tasks, and “teaches” them to the computer.
What is pseudocode?

– Simply put, it's a set of practices and conventions for producing very precise, minimally
ambiguous descriptions of algorithms.
– One way this can be accomplished is through the use of algebraic conventions for variable
naming and expressions, as well as specialized notation from set theory, linear algebra, and
other branches of mathematics.
– The use of these mathematical conventions can go a long way toward reducing ambiguity in
the description of an algorithm.
– Ultimately, the most important characteristic of pseudocode is not really what it is, but what it
enables.
– Working from well-written pseudocode, virtually any programmer with professional
competence in a given programming language should be able to implement the algorithm
described by the pseudocode, in the given language, with little or no need for further
instruction.
Writing pseudocode

C=5/9 * (F – 32)
FahrenheitToCelsius()
Begin
Read: F;
Set C = 5/9 * (F – 32);
Print C;
End
Pseudo Code vs Algorithm

You might also like