Algorithm
Session No.: 1
Course Name: Design and Analysis of Algorithm
Course Code:R1PC302B
Instructor Name:
Galgotias University 1
What do you think about Algorithm?
Galgotias University 2
Introduction of Algorithm
A procedure for solving a mathematical problem in a finite number of steps that
frequently involves repetition of an operation.
Set of rules to
obtain the
Input expected output Output
from the given
input
Algorithm
Aim
The aim of this lecture is to familiarize the student with the framework
of algorithm, pseudocode, and flowchart of a particular problem.
Therefore, students can understand the need of algorithms.
Galgotias University 4
At the end of this session students will be able to
Learning Outcome : Outline Algorithm, Characteristics of the algorithm, Need of algorithm, Types of
algorithm
Galgotias University 5
1. Review of Classification of data structure
2. Introduction of Algorithm
3. Pseudocode
Session 4. Flowchart
Outline 5. Characteristics of an Algorithm
6. Need of algorithms
7. Types of Algorithms
Galgotias University 6
Design an algorithm for making a sandwich
Galgotias University 7
An algorithm for making a sandwich can look like this:
Step 1: Cook the bacon, or whatever you like.
Step 2: Slice your tomatoes.
Step 3: Toast your bread.
Step 4: Add your favorite flavor of cheese spread to the Bread.
Step 5: Put it all together.
Step 6: Grill the sandwich.
Step 7: Eat and enjoy!
Galgotias University 8
ADDITION OF TWO NUMBERS
Algorithm:
STEP 1: Start the program.
STEP 2: Read the values of ‘a’&’b’.
STEP 3: Compute the sum of the entered numbers ‘a’,’b’,c=a+b.
STEP 4: Print the value of ‘c’.
STEP 5: Stop the program.
Galgotias University 9
Pseudocode
• A Pseudocode is defined as a step-by-step description of an algorithm.
• Pseudocode does not use any programming language in its representation instead
it uses the simple English language text as it is intended for human understanding
rather than machine reading.
• Pseudocode is the intermediate state between an idea and its
implementation(code) in a high-level language.
Algorithm Pseudocode Program
Galgotias University 10
Flowchart
Galgotias University 11
ADDITION OF TWO NUMBERS
Algorithm: Flow chart:
• STEP 1: Start the program.
• STEP 2: Read the values of ‘a’&’b’.
• STEP 3: Compute the sum of the entered numbers
‘a’,’b’,c=a+b.
• STEP 4: Print the value of ‘c’.
• STEP 5: Stop the program.
Pseudo code:
• BEGIN
• READ ‘a’&’b’
• COMPUTE c=a+b
• WRITE ‘c’
• END
Galgotias University 12
Learning Activity: Think-Pair-Share
Activity
• Think-Pair-Share Activity: Characteristics and Need of algorithms
• Objective:
• To enable students to Characteristics and Need of algorithms in data structures through individual
reflection, peer discussion, and collaborative sharing.
• Activity Steps:
1. Think (Individual Reflection – 2 minutes):
1. Each student will take a few minutes to think about the need for the algorithm.
2. They will write down their understanding, list examples, and note key characteristics of each type.
2. Pair (Discussion with a Partner – 5 minutes):
1. Students will pair up and discuss their thoughts.
2. They will compare their responses, clarify doubts, and refine their understanding.
3. Each pair will identify and note down at least two points of need of the algorithm.
3. Share (Class Discussion – 3 minutes):
1. Each pair will present their findings to the class.
2. The teacher will compile key points on the board and provide additional explanations if necessary.
Galgotias University 13
Characteristics of an Algorithm
Clear and
Unambigu Finite-ness
ous
Well- Characteristics Well-
Defined of an Defined
Inputs Algorithm Outputs
Language
Feasible
Independe
nt
Galgotias University 14
Characteristics of an Algorithm
• Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps should be clear in
all aspects and must lead to only one meaning.
• Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs. It may or
may not take input.
• Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be
well-defined as well. It should produce at least 1 output.
• Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
• Feasible: The algorithm must be simple, generic, and practical, such that it can be executed with the
available resources. It must not contain some future technology or anything.
• Language Independent: The Algorithm designed must be language-independent, i.e. it must be just
plain instructions that can be implemented in any language, and yet the output will be the same, as
expected.
Galgotias University 15
Need for algorithms
• Algorithms are necessary for solving complex problems efficiently and
effectively.
• They help to automate processes and make them more reliable, faster, and easier
to perform.
• Algorithms also enable computers to perform tasks that would be difficult or
impossible for humans to do manually.
• They are used in various fields such as mathematics, computer science,
engineering, finance, and many others to optimize processes, analyze data,
make predictions, and provide solutions to problems.
Galgotias University 16
Types of Algorithm
• Brute Force
• Divide and Conquer
• Greedy Algorithm
Galgotias University 17
Brute Force
Tries all possible solutions
Galgotias University 18
Divide and Conquer
Breaks the problem into
subproblems
Galgotias University 19
Greedy Algorithm
Takes the best possible
step at each stage
Galgotias University 20
Learning Activity : Quiz in Wooclap
Galgotias University 21
Quiz in Wooclap
• Objective:
The goal of this activity is to assess students' understanding of
algorithms. The quiz will also encourage students to reflect
on how these concepts are applied in programming.
• Activity Overview:
Students will participate in an interactive quiz hosted on
Wooclap, where they will answer multiple-choice questions
related to the session's topics. The quiz will test their ability
to define and differentiate between data structures, identify
real-world applications, and understand the key concepts
discussed in the session.
Galgotias University 22
Reflection-Learning Activity : Wooclap Quiz
The quiz helped assess my understanding of algorithm.
Galgotias University 23
Summary
The session covered essential concepts of algorithms.
Understand the set of rules designed to solve a specific problem. It takes input, processes
it, and produces an output.
By the end of the session, students will have a foundational understanding of algorithms,
Characteristics of the algorithm, Need of algorithm, and Types of algorithm.
Galgotias University 24
In the next session: Analysis of Algorithms.
Galgotias University 25
Review and Reflection
from students
Galgotias University 26