Module 2 - Flowcharts, Algorithms Pseudo-Codes
Module 2 - Flowcharts, Algorithms Pseudo-Codes
Algorithms
BITS Pilani Dr. Jagat Sesh Challa
Pilani Campus
Department of Computer Science & Information Systems
Module Overview
• Flowcharts
• Algorithms
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
• Step5: Debugging
• Step6: Documentation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
Flowcharts
Steps of Programming Practices
• Step1: Requirements
• Step5: Debugging
• Step6: Documentation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Flow Chart
• Graphical representation of a solution to a particular problem
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Uses of a Flow Chart
• Important for devising a solution to a problem
• Sequence of a program
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
How to make a flow chart
Step1: Identify input and output.
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Symbols used in Flow Charts
Process Calculation
2 Flow Lines
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Symbols used in Flow Charts (contd.)
Flow Line
Shows the logical flow of
control
Decision Symbol
One flow of line for Input and
two for Output
Connector
Connects separate portions
of a flow chart
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Flow Chart Example 1:
Software Development
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Flow Chart Example 2:
Sum of two numbers
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Flow Chart Example 3:
Whether a number is Prime or Not?
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
Algorithms
Steps of Programming Practices
• Step1: Requirements
• Step5: Debugging
• Step6: Documentation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Algorithms
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Programming Methodologies
General approach
Top to a Problem Abstract
Bottom Particular
Algorithms
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Programming Methodologies
(contd.)
• Design techniques offer mechanisms to create programs that
are easy to understand, free of bugs and convenient to modify.
• If possible, programs should be designed to be reusable.
• Bottom – UP Programming:
Low level components are designed first without fully knowing the big
picture. The components are later integrated to form the complete
system.
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
What is an Algorithm?
Step by step solution to a problem in English like language.
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Programming Logic Constructs
• Imperative statements (Actions)
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Algorithm Example 1:
Sum of two numbers
1. START
2. Initialize sum=0
3. Input the numbers num1, num2
4. Set sum = num1 + num2.
5. Print sum
6. END
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Algorithm Example 2:
Whether a number is Prime or Not?
1. START
2. Initialize i=2 and p=0.
3. Input the number, gno
4. Check if (gno % i==0) is TRUE then
continue else GOTO step 8
5. Set p=1.
6. Increment value of i.
7. Check if (i<gno) is TRUE then GOTO
step 4.
8. Check if(p==0 or gno=2) then
continue else GOTO step 11.
9. The given number is prime.
10. GOTO step 12.
11. The number is NOT prime.
12. END
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Exercise
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus