Professional Documents
Culture Documents
Au-SOEIT-Dep’t of IT Page 1 of 7
What part of the problem is going to be solved?
What input data is required to solve the problem?
What output data (result) is expected?
What procedures are needed to achieve the result?
Au-SOEIT-Dep’t of IT Page 2 of 7
Figure below lists the relative amount of effort that is typically expended on
each of these four development and design steps in large commercial programming
projects.
Step Effort (%)
Analyzing the solution 10
Developing the solution 20
Coding the solution 20
Testing the solution 50
Au-SOEIT-Dep’t of IT Page 3 of 7
Design and Implementation of Algorithms:
A. Pseudo code
Pseudo code is an artificial and informal language that helps
programmers to develop algorithms. Pseudo code is a language used
to describe the manipulations to be performed on data. This language
is a simple mixture of natural language and mathematical notations
and it is independent of programming language. Pseudo code has
some ways to represent sequence, decision and repetition in
algorithms.
Example: 1) Pseudo code to add two numbers.
Step 1: start
Step 2: Read two numbers n1 and n2.
Step 3: sum n1 + n2
Step 4: Print sum
Step 5: Stop
Example: 2) pseudo code to find largest number from two numbers.
Step 1: start
Step 2: Read two numbers n1 and n2.
Step 3: If n1 > n2 then
Big n1
else
Big n2
Step 4: Print Big
Step 5: Stop
Example: 3) pseudo code to find largest number from three numbers.
Step 1: start
Step 2: Read three numbers n1, n2 and n3.
Step 3: If n1 > n2 and n1 > n3 then
Big n1
Else
If n2 > n1 and n2 > n3 then
Big n2
else
Big n3
Step 4: Print Big
Step 5: Stop.
Au-SOEIT-Dep’t of IT Page 4 of 7
Loops
Some times there is a situation in which it is necessary to
execute a group of statements repeatedly until some condition is
satisfied. This situation is called a loop. Loop is a sequence of
instruction, which is repeated until some specific condition occurs.
The general execution flow structure of loops looks like the following.
[Initialization]
true
[Compute]
[Increment/Decrement]
The above simple structure tells that execution continues as far as the
test holds true.
Example 4) Pseudo code to find sum of N positive integer numbers.
Step 1: start
Step 2: Read N
Step 3: Sum 0,
Step 4: Count 0
Step 5: Read Num
Step 6: SumSum + Num
Step 7: count count +1
Step 8: If Count < N then goto step 4
Step 9: Print Sum
Step 10: Stop
Assignment:
1) Write an algorithm to find the roots of quadratic equation
ax 2 bx c 0 . using the formula x= b ( b 2 4ac ) / 2a . Depending on
the values of D Where D b 2 4ac
2) Write an algorithm to check whether the given number is even or
odd and display the suitable message.
B. Flow charts:
Due to the detail required of them, programming languages are not
convenient tools for initial algorithm design. The means of notation
widely used for algorithm is a flowchart. Flowchart is a two-
dimensional representation of an algorithm; the predefined graphic
symbols of a flowchart are used to indicate the various operations and
the flow of control. The most significant advantage of flowcharts is a
clear presentation of the flow of control in the algorithm, i.e. the
sequence in which operations are performed.
Au-SOEIT-Dep’t of IT Page 5 of 7
A basic set of established flowchart symbols is:
Decision
Processing Input/output
Connector
Annotation
Flow lines
The symbols have the following meanings:
Processing: one or more computational tasks are to be performed
sequentially
Input/Output: Data are to be read into the computer memory from
an input device or data are to be passed from the memory to an
output device. (Parallelogram)
Decision: two alternative execution paths are possible. The path to be
followed is selected during the execution by testing whether or not the
condition specified within the outline is fulfilled. (Rhombus)
Terminals: appears either at the beginning of a flowchart (and
contains the word “start”) or at its conclusion (and contains “stop”).
Annotation: contains comments that simplify the understanding of
the algorithm or description of data.
Connector: makes it possible to separate a flowchart into parts.
Identical cross reference symbols are placed in this outline where the
flow line is interrupted and where it resumes.
Flow lines: indicates the outline that is to be entered next.
Flowcharts allow the reader to follow the logic of the algorithm more
easily than would a linear description in English.
1. A flowchart to find factorial 2. A Flowchart to find
of a positive integer n largest of two numbers.
START
Start
Input n
Read A,
B.
F=1
Is
No
Display F A>B ?
n>
0? Yes
Au-SOEIT-Dep’t of IT Page 6 of 7
Since flowcharts are inconvenient to revise, they have fall out of
favour by programmers. Nowadays, the use of pseudo code has gained
increasing acceptance.
Only after an algorithm has been selected and the programmer
understands the steps required can the algorithm be written using
computer-language statements. The writing of an algorithm using
computer-language statements is called coding the algorithm, which is
the third step in our program development process.
Exercise:
Algorithms:
1. Write an algorithm to find the smallest number from three
numbers.
2. Write an algorithm to find the sum of first N even numbers.
3. Write an algorithm to generate Fibonacci series.(a series which
goes like 1,1,2,3,5,8,13,…)
4. Write an algorithm to find the sum of digits of given number.
(eg. If the given number is 251, the sum of digits is 2+5+1=8)
Flowcharts:
1. Draw a flowchart to find sum of N positive numbers.
2. Draw a flowchart to find the biggest among N numbers.
3. Draw a flowchart to find the Factorial of a given number.
Programming paradigms
A programming paradigm is a fundamental style of computer
programming. The following are examples of programming paradigms:
1. Imperative Paradigm/Procedural: The 'first do this, next do that' is a
short phrase which really in a nutshell describes the spirit of the imperative paradigm.
The basic idea is the command, which has a measurable effect on the program state.
The phrase also reflects that the order to the commands is important. 'First do that,
then do this' would be different from 'first do this, then do that'.
2. Functional Paradigm: Functional programming is in many respects
a simpler and cleaner programming paradigm than the imperative
one. The reason is that the paradigm originates from a purely
mathematical discipline: the theory of functions.
3. Logic Paradigm: The logic paradigm is dramatically different from
the other three main programming paradigms. The logic paradigm fits
extremely well when applied in problem domains that deal with the
extraction of knowledge from basic facts and relations. The logical
paradigm seems less natural in the more general areas of
computation.
4. Object Oriented Paradigm: The object-oriented paradigm has
gained great popularity in the recent decade. The primary and most
direct reason is undoubtedly the strong support of encapsulation and
the logical grouping of program aspects. These properties are very
important when programs become larger and larger.
Au-SOEIT-Dep’t of IT Page 7 of 7