Lesson 1
Lesson 1
LECTURE 1
Introduction to Algorithms and
Flowcharts
Presented by:
Pratibha Ku. Khandual
Department of CSE,
VSSUT, Burla
Algorithms and Flowcharts
• Algorithm and flowchart are the powerful tools
for learning programming.
• An algorithm is a step-by-step analysis of the
process, while a flowchart explains the steps of a
program in a graphical way.
• Algorithm and flowcharts helps to clarify all the
steps for solving the problem.
• For beginners, it is always recommended to
first write algorithm and draw flowchart for
solving a problem and then only write the
program.
2
Algorithms
• A typical programming task can be divided into two
phases:
• Problem solving phase
– Produce an ordered sequence of steps that describe
solution of problem
– This sequence of steps is called an algorithm
– An algorithm is a sequence of steps to solve a particular
problem
– An algorithm is defined as an ordered set of unambiguous
steps that produces a result and terminates in a finite time
• Implementation phase
– Implement the program in some programming language
3
Steps In Problem Solving
• First write a general algorithm called
pseudocode.
• Pseudocode is an artificial and informal
language that is very similar to everyday
English. It helps programmers develop
algorithms.
• Refine the pseudocode successively to get
step by step detailed algorithm that is very
close to a computer language.
4
Characteristics of an Algorithm
• An algorithm has the following characteristics:
– Input: An algorithm may or may not require input
– Output: Each algorithm is expected to produce at
least one result
– Definiteness: Each instruction must be clear and
unambiguous.
– Finiteness: If the instructions of an algorithm are
executed, the algorithm should terminate after
finite number of steps
5
Characteristics of an Algorithm
• An algorithm has the following characteristics:
– Precision: The steps of an algorithm must be
accurately defined
– Uniqueness: Each step of the algorithm is uniquely
defined.
– Effectiveness: It must be possible to perform each
step of the algorithm correctly and in a finite amount
of time. That is, the steps must be basic enough so
that someone using a pencil and a paper could carry
them out exactly, and in a finite amount of time.
6
Control Structures Involved In
Algorithm and Flowchart
• The algorithm and flowchart include following three
types of control structures.
– Sequence: In the sequence structure, statements are
placed one after the other and the execution takes place
starting from up to down.
– Branching (Conditional): In branch control, there is a
condition and according to a condition, a decision of
either TRUE or FALSE is achieved. In the case of TRUE, one
of the two branches is explored; but in the case of
FALSE condition, the other alternative is taken. Generally,
the ‘IF-THEN’ construct is used to represent branch
control.
– Loop (Repetition): The Loop or Repetition allows a
statement(s) to be executed repeatedly based on certain
loop condition using WHILE, Do-WHILE and FOR loops.
7
Example of Pseudocode and Algorithm
• Example 1: Write the pseudocode and detailed algorithm
to determine a student’s final grade and indicate whether
the student is passing or failing. The final grade is
calculated as the average of four marks.
• Pseudocode:
– Input a set of 4 marks
– Calculate their average by adding the marks and
dividing the sum by 4
– If average is below 50
Print “FAIL”
else
Print “PASS
8
Example of Pseudocode and Algorithm
• Detailed Algorithm
– Step 1: Input M1,M2,M3,M4
– Step 2: GRADE = (M1+M2+M3+M4)/4
– Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
9
Advantages of Algorithm
11
Advantages of Flowchart
• Flowchart is an excellent way of communicating the logic of a
program.
• It provides an easy and efficient way to analyze the solution to
a problem.
• During program development cycle, the flowchart plays the
role of a blueprint, which makes the program development
process easier.
• After successful development of a program, it needs
continuous timely maintenance during the course of its
operation. The flowchart makes program or system
maintenance easier.
• It is easy to convert the flowchart into any programming
language code.
12
Standard Symbols Used in a Flowchart
13
Control Structures Representation in
Flowchart
14
Symbols Used in Algorithm and
Flowchart
• Assignment Symbol (← or =) is used to assign
value to the variable. E.g., to assign value 5 to
the variable HEIGHT, statement is HEIGHT ← 5
or HEIGHT = 5
• The symbol ‘=’ is used in most of the
programming language as an assignment symbol,
the same has been used in all the algorithms and
flowcharts in the manual
• The statement C = A + B means that add the
value stored in variable A and variable B then
assign/store the value in variable C
15
16
17
GO TO statement is also called unconditional transfer of
control statement is used to transfer control of execution to
another step/statement. E.g. the statement GOTO n will
transfer control to step/statement n.
19
Branching (Selection): Algorithm and
Flowchart
Algorithm to find the largest of three numbers:
Step 1. Start
Step 2. Read the three numbers to be compared, as A, B and C.
Step 3. Check if A is greater than B.
3.1 If true, then check if A is greater than C.
3.1.1 If true, print 'A' as the greatest number.
3.1.2 If false, print 'C' as the greatest number.
20
Branching (Selection): Algorithm and Flowchart
21
Looping: Algorithm and Flowchart
• Algorithm for calculate factorial value of a number:
Step 1. Start
Step 2. Read the number N
Step 3. [Initialize]
M = 1, F = 1
Step 4. Repeat Steps 4 through 6 until M = N
Step 5. F = F * M
Step 6. M = M+ 1
Step 7. Print F
Step 8. Stop
22
Looping: Algorithm and Flowchart
23
ANY DOUBTS?
1/22/2025 24
THANK YOU!
1/22/2025 25