02 DSA PPT Introduction To Algorithms

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Transforming Education

Introduction to Algorithms
Concepts

a) Introduction to Algorithms
i) Characteristics of Algorithm
b) Time and Space Complexity
c) Importance of efficient algorithms
i) Priori Analysis
ii) Posterior Analysis

3
Questions for this session

1. How do you design the solution to a problem statement?

2. How can we analyse the performance of the solution designed for a

problem statement?

4
How do you design
the solution to a
problem statement?

5
Algorithm

Algorithm Calculate_Factorial (n,fact)- This algorithm is used for


1. Step-by-step procedure for
calculating the factorial of a number say n, whose value is entered
solving a problem
by the user. Variable ‘fact’ is used for the result.
2. Independent of the Step 1- Start
underlying platform Step 2- Ask the user to enter a number and store it in an integer

3. Can be implemented in variable, say n

multiple programming Step 3- Set i=n, fact=1

languages Step 4- while (i>0) repeat Steps 5 and 6


Step 5- fact=fact*i
Step 6- Set i--
Step 7- Print the value of fact that stores factorial of n
Step 8- Exit

6
Choose the Correct Option: Algorithm (1 min)

The method which uses well-defined instructions to complete a task from a given initial state
to end state is called ……………………….

A. Program
B. Flowchart
C. Algorithm
D. Both A and C

7
Characteristics of an Algorithm

8
How can we analyse the
performance of the
solution designed for a
problem statement?

9
Algorithmic Complexity

● Refers to the amount of processing time and memory space required for execution.

● Measuring the performance/efficiency of an algorithm-

○ Time Complexity

○ Space Complexity

10
Difference Between Time and Space Complexity

Time Complexity Space Complexity

● Amount of processing time for ● Amount of memory space required for


execution execution
● It is calculated by two components ● It is calculated by two components
○ Constant time part ○ Fixed Part
○ Variable time part ○ Variable Part
● Time Complexity ● Space Complexity
T(P) = C+TP(I) S(P)=C+SP(I)

11
Importance of efficient algorithms

● A problem can have multiple solutions (algorithms)

● Finding the most efficient solution

Priori Analysis Posterior Analysis


● Analysing the algorithm before its ● Evaluating the algorithm after its

implementation. implementation using a programming


● Algorithm is evaluated when it is written language
in the theoretical steps. ● Actual analysis report

12
InClass Activity: Design an Algorithm for Fibonacci Series

Activity Type- Problem Solving


Students can divide themselves into groups of 4
Time Allotted for the activity is 15 minutes
The algorithm along with appropriate explanation should be added to a .docx document and
uploaded on the platform

Question:

Design an Algorithm for generating the Fibonacci Series for n numbers

13
Solution: Design an Algorithm for Fibonacci Series
Algorithm Generate_Fibonacci (a, b, n)
Step 1- Start
Step 2- Declare variables a, b, res, n and i
Step 3- Set a=0, b=1 and i=1
Step 4- Display values of a and b
Step 5- while (i<=n) repeat Steps 6 and 10
Step 6- Compute res= a+b
Step 7- Set a=b
Step 8- Set b=res
Step 9- Display res
Step 10- Set i++
Step 11- Exit
14
Learning Outcomes
In this session, you have learnt to:

1. Students will learn about algorithms used for solving a given problem statement

2. List the characteristics of a good algorithm

3. Explain the concepts of time complexity which quantifies the amount of time taken for executing
an algorithm

4. Summarize the basics of space complexity which quantifies the amount of memory taken by an
algorithm during its execution

5. Design and develop algorithm(s) representing solutions to real-world problems and applications

Go through the following learning resources on the platform

● Introduction to Algorithms

15
Q&A

If you have more questions, please post them in the community on the platform.

16
What Next?

In the next session the following concepts will be covered

● Installation- Visual C++ IDE 2008 Express Edition

Go through the following learning resources on the platform

● Integrated Development Environment for C

17

You might also like