GE3151 - PROBLEM SOLVING AND PYTHON PROGRAMMING
Notation (Pseudo code, Flow chart,
Programming language)
Mr. V. THIYAGARAJAN, M.E., M.B.A.,
Assistant Professor,
Department of Computer Science & Engineering,
CKCET
Notation
Pseudo Code
Flow Chart
Programming language
Pseudo Code
Pseudo code
It is easier to understand for the programmer or
non-programmer to understand the general working of the
program, because it is not based on any programming language.
Pseudo code
It gives us the sketch of the program before actual coding.
It is not a machine readable.
Pseudo code can’t be compiled and executed.
There is no standard syntax for pseudo code.
Guidelines for writing Pseudo code
1. Pseudocode is written using structured English.
2. The programmers may use their own style for writing a
Pseudo code, which can be easily understood.
3. It never use the syntax of any programming languages.
Guidelines for writing Pseudo code
4. It uses some keywords to denote programming process.
Input : INPUT, GET, READ and PROMPT.
Output : OUTPUT, PRINT, DISPLAY and SHOW.
Processing : COMPUTE, CALCULATE, DETERMINE, ADD,
SUBTRACT, MULTIPLY and DIVIDE.
Initialize : SET and INITIALISE
5. Keyword should be in capital letter.
Common keywords used in Pseudo code
The following gives common keywords used in pseudocode.
// : This keyword used to represent a comment.
BEGIN, END : Begin is the first statement and End is the last
statement.
INPUT, GET, READ : The keyword is used to input the data.
Common keywords used in Pseudo code
COMPUTE, CALCULATE : used for calculation of the result of
the given expression.
ADD, SUBTRACT, INITIALIZE : used for addition, subtraction
and initialization.
OUTPUT, PRINT, DISPLAY : It is used to display the output of
the program.
Common keywords used in Pseudo code
IF, ELSE, ENDIF : used to make decision.
WHILE, ENDWHILE : used for iterative statements.
FOR, ENDFOR : Another iterative incremented/decremented
tested automatically.
Guidelines for writing Pseudo code
6. There are 3 Control Structures in Pseudo code.
Sequential logic
Selection logic
Iteration logic
Sequence Logic
It is used to perform instructions in a sequence, that is one
after another.
For sequence logic, pseudo code instructions are written in an
order in which they are to be performed.
The logic flow of pseudo code is from top to bottom.
Example : Find the Product of two numbers
BEGIN
READ the values of A and B
COMPUTE C by multiplying A with B
PRINT the result C
END
Selection Logic
It is used for making decisions and for selecting the proper path
out of two or more alternative paths in program logic.
It is also known as decision logic.
Selection logic is depicted as either an IF..THEN or an IF…
THEN..ELSE Structure.
Syntax for if else
IF (condition)THEN
statement1
...
ELSE
statement2
...
ENDIF
Example : Greatest of two numbers
BEGIN
READ the values of A and B
IF A is greater than B THEN
DISPLAY “A is greater”
ELSE
DISPLAY “B is greater”
END IF
END
Iteration Logic
It is used to produce loops when one or more instructions may
be executed several times depending on some conditions.
It uses structures called FOR, WHILE and REPEAT__UNTIL.
Syntax for For
FOR( start-value to end-value) DO
statement
...
ENDFOR
Example : Print n natural numbers
BEGIN
GET the value of N
INITIALIZE I to 1
FOR I less than or equal to N DO
PRINT the value of I
INCREMENT I by 1
ENDFOR
END
Advantages
1. Pseudo is independent of any language; it can be used by most
programmers.
2. It is easy to translate pseudo code into a programming language.
3. It can be easily modified as compared to flowchart.
4. Converting a pseudo code to programming language is very easy as
compared with converting a flowchart to programming language.
Disadvantages
1. It does not provide visual representation of the program’s logic.
2. There are no accepted standards for writing pseudocode.
3. It cannot be compiled nor executed.
4. For a beginner, It is more difficult to follow the logic or write
pseudocode as compared to algorithm and flowchart.
Examples: Algorithms, Pseudo Code, Flow Chart,
Programming Language
1. Write an algorithm to find Area of a Rectangle
Algorithm Pseudocode Flow Chart
Step 1 : Start BEGIN
Step 2 : Get l, b values READ l, b
Step 3 : Calculate A = l * b CALCULATE A = l * b
Step 4 : Display A DISPLAY A
Step 5 : Stop END
2. Write an algorithm for Calculating Area and Circumference of Circle
Algorithm Pseudocode Flow Chart
Step 1 : Start BEGIN
Step 2 : Get r value READ r
Step 3 : Calculate A=3.14*r*r CALCULATE A and C
Step 4 : Calculate C=2*3.14*r A = 3.14*r*r
Step 5 : Display A, C C = 2*3.14*r
Step 6 : Stop DISPLAY A, C
END
3. Write an algorithm for Calculating Simple Interest
Algorithm Pseudocode Flow Chart
Step 1 : Start BEGIN
Step 2 : Get P, N, R value READ P, n, r
Step 3 : Calculate CALCULATE S
SI = (P*N*R)/100 SI = (P*N*R)/100
Step 4 : Display SI DISPLAY SI
Step 5 : Stop END
4. To check greatest of two numbers
Algorithm Pseudocode Flow Chart
Step 1 : Start BEGIN
Step 2 : Get a, b value READ a, b
Step 3 : check if(a > b) IF (a > b) THEN
print a is greater DISPLAY a is greater
Step 4 : else b is greater ELSE
Step 5 : Stop DISPLAY b is greater
END IF
END
Flow Chart
Flow Chart
A Flowchart is a pictorial (graphical) representation of an
algorithm.
A flowchart is drawn using different kinds of symbols.
The flowchart symbols are linked together with
arrows showing the flow of directions.
Each symbol has name.
Flow Chart
Flow chart is defined as graphical representation of the logic for
problem solving.
A flowchart is drawn using boxes of different shapes with lines
connecting them to show the flow of control.
Flow Chart
The purpose of flowchart is making the logic of the program
clear in a visual form.
The logic of the program is communicated in a much better way
of using a flowchart.
Cloud Computing 31
Flow Chart Symbols
Rules for drawing a flowchart
1. It should contain only one start and one end symbol.
2. The standard symbols must be used while drawing a flowchart.
3. The direction of flows from top to bottom or left to right
4. It should be simple and drawn clearly and neatly.
5. Use properly labeled connectors to link the portions of the
flowchart on different pages.
6. The branches of decision box must be label.
Rules for drawing a Flowchart
1. The flowchart should be clear, neat and easy to follow.
2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
Rules for drawing a Flowchart
4. Only one flow line should enter a decision symbol.
However, two or three flow lines may leave the decision symbol.
5. Only one flow line is used with a terminal symbol.
Rules for drawing a Flowchart
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.
Flowchart
Flowchart is made up of the following logic structure
1. Sequential logic
2. Selection logic
3. Iteration logic
Sequence Logic
In a computer program or an algorithm, sequence involves simple
steps which are to be executed one after the other.
The steps are executed in the same order in which they are written.
Area of circle
Selection Logic
Selection is used in a computer program or algorithm to determine
which particular step or set of steps is to be executed.
This is also referred to as a ‘decision’.
Selection Logic
There are two types of selection:
1. Binary selection (two possible pathways)
2. Multi-way selection (many possible pathways)
Flowchart to find biggest among two numbers
Binary selection
Flowchart to find biggest among three numbers
Multi-way selection
Iteration Logic
Repetition allows for a portion of an algorithm or computer
program to be executed any number of times dependent on
some condition being met.
An occurrence of repetition is usually known as a loop.
Flowchart for find sum of a given number
Advantages of flowchart
1. Communication :- Flowcharts are better way of communicating
the logic of a system to all concerned.
2. Effective analysis :- With the help of flowchart, problem can be
analyzed in more effective way.
3. Proper documentation :- Program flowcharts serve as a good
program documentation, which is needed for various purposes.
Advantages of flowchart
4. Efficient Coding :- The flowcharts act as a guide or blueprint
during the systems analysis and program development phase.
5. Proper Debugging :- The flowchart helps in debugging process.
6. Efficient Program Maintenance :- The maintenance of operating
program becomes easy with the help of flowchart. It helps the
programmer to put efforts more efficiently on that part.
Disadvantages of flow chart
1. Complex logic :- Sometimes, the program logic is quite
complicated. In that case, flowchart becomes complex and
clumsy.
2. Alterations and Modifications :- If alterations are required the
flowchart may require re-drawing completely.
Algorithm VS Flowchart VS Pseudocode
Algorithm Flowchart Pseudocode
An algorithm is a It is a graphical It is a language
sequence of representation of representation of
instructions used to algorithm algorithm.
solve a problem.
User needs knowledge Not need knowledge Not need knowledge
to write algorithm. of program to draw or of
understand flowchart. program language to
understand or write a
pseudo code.