CSE2201: Algorithms
Introduction To Algorithms
Md. Aktaruzzaman Pramanik
Lecturer
Department of CSE, ULAB
1
Today’s Contents
• What is a Algorithm?
• Criteria of Algorithm
• Methods for analyzing algorithms
• Need for Algorithm
• Different types of Algorithm
• Application of Algorithms in Real Life
• How to Write an Algorithm?
2
3
Let’s make a Cup of Tea now
4
Instructions for Perfect Cup of Tea
▪ Add 1 cup of freshly boiled water to your tea bag (in a mug)
▪ Allow the tea bag to brew for 2 minutes.
▪ Remove the tea bag.
▪ Add milk / lemon.
▪ Add sugar
▪ Your tea is ready to drink
Yes, This is the Algorithm of making a Cup of Tea
5
What is Algorithm?
▪ Algorithm is a step-by-step procedure to solve any Problem
▪ Well-defined computational procedure that takes some input
and produce required output.
▪ A step-by-step procedure, which defines a set of instructions to
be executed in a certain order to get the desired output.
▪ In Simple words, it is the a tool for solving well-specified
computational problems. 6
What is Algorithm?
▪ It is a logical and mathematical approach to solve or crack a
problem using any possible method.
▪ Algorithms are generally created independent of underlying
languages, i.e. an algorithm can be implemented in more than
one programming language
7
Need for Algorithm in Practical Life
Your Life is an Algorithm, Your Brain
is an Operating System.
-By DOMINIC BASULTO
8
Need for Algorithm in Practical Life
Basically, algorithm is a process to solve a problem in
step by step.
When we face a problem in our real life , if we try to solve
this problem randomly then it’s turn into more difficult.
But when we will try to solve this problem step by step
with planning, it will be easier to solve those problem.
In that reason , we use algorithm to solve a problem by
easier way and free from any difficulty.
It will saves our valuable time , money energy etc.
9
Advantages for Algorithm
▪ The algorithms are very easy to understand and can be
written in simple language which can be understood by
anyone
▪ By using algorithms, we can easily understand the
sequence to be followed in processing.
▪ We can check and fix any kind of complexity easily.
10
Criteria of a Algorithm
1. Input
2. Output
3. Definiteness
4. Finiteness
5. Effectiveness
11
Criteria of a Algorithm
12
Criteria of Algorithm
▪ Input
− An algorithm should have 0 or more well-defined inputs.
▪ Output
− An algorithm should have 1 or more well-defined desired outputs
▪ Definiteness
− Each step of an algorithm must be precisely defined.
Each of its steps and their inputs/outputs should be clear and must lead
to only one meaning.
13
Criteria of a Algorithm (cont.)
▪ Finiteness
− Algorithms must terminate after a finite number of steps.
▪ Effectiveness
− Must produce the desired result.
14
Methods for analyzing Algorithms
1. Correctness
2. Time Complexity
3. Space Complexity
15
Methods for analyzing algorithms
▪ Correctness
− Algorithm accomplishing its purpose accurately in k finite steps.
▪ Time Complexity
− Running time or execution time of operations must be as small as
possible.
▪ Space Complexity
− Memory usage should be as little as possible.
16
Why Need an efficient Algorithm
▪ With an efficient algorithm we can solve a problem
within a very short time, even with a slow computer.
17
Different types of Algorithms
18
Different types of Algorithms
1. Searching Algorithms
2. Sorting Algorithms
3. Divide and conquer algorithms
4. Recursive algorithms
5. Backtracking algorithms
6. Brute force algorithms
7. Greedy Algorithms
8. Dynamic programming algorithms
19
Application of Algorithms
1. Searching Data
2. Sorting Data
3. Find out the Shortest Path
4. Best Possible solution
20
Some Real Life Examples
21
Some Real Life Examples
▪ Search Engine (Google, Microsoft Edge, Mozilla, Opera etc)
▪ Social networking (Facebook)
▪ Travelling route (Air Flight route, Google Map, Shipping route etc)
▪ Facial Recognition Algorithm
▪ Genetic Engineering
▪ Stock Market
▪ Artificial Intelligence
▪ Machine Learning
▪ Robotics
………………And many more
22
How to Write an Algorithm?
▪ There are no well-defined standards for writing algorithms.
▪ Rather, it is problem and resource dependent.
▪ Combination of human Language and Programming
Language, so that it is easily understandable even by non-
programmers.
▪ Algorithms are never written to support a particular
programming code.
23
Design an algorithm to add two numbers and
display the result
Step 1 − START Step 1: START
Step 2 − declare three integers a, b & c Step 2: declare three integers a, b & c
Step 3 − define values of a & b Step 3: take input in a & b
Step 4 − add values of a & b Step 4: calculate a + b
Step 5 − store output of step 4 to c Step 5: c a+b
Step 6 − print c Step 6: print c
Step 7 − STOP Step 7: STOP
24
Design an algorithm to add two numbers and
display the result
1. START START
2. declare three integers a, b & c declare three integers a, b & c
3. take input in a & b take input in a & b
4. calculate a + b calculate a + b
5. c a+b c a+b
6. print c print c
7. STOP STOP
25
Your Task
Now Design an algorithm to find the maximum
of Two Integer values and display the result
26
Thank you!
27