0% found this document useful (0 votes)
8 views

Algorithms

Uploaded by

Manas Kagankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Algorithms

Uploaded by

Manas Kagankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Data Structures & Algorithms

(Lecture 04)

Prof. P. T. Sawant
Asst. Prof.
Department of Computer Science & Information
Technology
Agenda
 Algorithm

 Properties of Algorithms

 Examples

 Time and Space Complexity

 Efficiency

 Assignment
Algorithm
• An algorithm is a finite set of instructions that,
if followed, accomplishes a particular task.

• An algorithm can be expressed in three ways:-


(i) in any natural language such as English.
(ii) in a programming language or
(iii) in the form of a flowchart.
Properties
• Input
• Output
• Definiteness
• Finiteness
• Effectiveness
Algorithm for addition of two
numbers
• Step 1: Start
• Step 2: Declare three variables num1, num2 and
result
• Step 3: Read values of num1 and num2
• Step 4: Add num1 and num2 and assign sum to result
• result <- num1 + num2
• Step 5: Display result
• Step 6: Stop
Algorithm for factorial of number
• Step 1: Start
• Step 2: Declare Variables num, fact, i
• Step 3: Read value of num
• Step 4: fact <- 1 and i <- 1
• Step 5: repeat steps until i<= num
• 5.1 fact <- fact * i
• 5.2 i <- i+1
• Step 6: Display Fact
• Step 7: Stop
TIME AND SPACE COMPLEXITY
• Complexity of algorithm is a function of size of input of a
given problem instance which determines how much running
time/memory space is needed by the algorithm in order to
run to completion.
1. Time Complexity: Time complexity of an algorithm is the
amount of time it needs in order to run to completion.
2. Space Complexity: Space Complexity of an algorithm is the
amount of space it needs in order to run to completion.
There are two points which we should consider about computer
programming:-
(i) An appropriate data structure and
(ii) An appropriate algorithm.
EFFICIENCY OF AN ALGORITHM
• In computer science, algorithmic efficiency are the
properties of an algorithm which relate to the
amount of resources used by the algorithm.
1. Worst case efficiency: It is the maximum number of steps
that an algorithm can take for any collection of data
values.
2. Best case efficiency: It is the minimum number of steps
that an algorithm can take any collection of data values.
3. Average case efficiency: It can be defined as the
efficiency averaged on all possible inputs
Assignment
• Write algorithm to search an element in array
of 10 elements
• Write an algorithm to identify whether number
is even or odd.
Thank You

You might also like