SlideShare a Scribd company logo
Algorithm Analysis
Chapter 2
Mary Margarat Valentine
Objectives
This Chapter introduces students to the analysis
and design of computer algorithms. Upon
completion of this chapter, students will be able to
do the following:
 Analyze the asymptotic performance of algorithms.
 Demonstrate a familiarity with major algorithms and data
structures.
 Apply important algorithmic design paradigms and
methods of analysis.
 Synthesize efficient algorithms in common engineering
design situations.
2
What is an Algorithm?
3
What is an Algorithm?
 Algorithms are the ideas behind computer
programs.
 Algorithm is any well-defined computational
procedure that takes some value, or set of
values, as input and produces some value,
or set of values, as output.
 Algorithm is thus a sequence of
computational steps that transform the
input into the output. 4
What is an Algorithm?
Example:
 Directions to somebody’s house is an
algorithm.
 A recipe for cooking a cake is an algorithm.
5
What is a Program?
 A program is a set of instructions which the
computer will follow to solve a problem
6
Introduction
 Why we need algorithm analysis ?
 Writing a working program is not good enough.
 The program may be inefficient!
 If the program is run on a large data set, then
the running time becomes an issue.
7
What to Analyze ?
 Correctness
 Does the input/output relation match algorithm
requirement?
 Amount of work done
 Basic operations to do task finite amount of time
 Amount of space used
 Memory used
8
What to Analyze ?
 Simplicity, clarity
 Verification and implementation.
 Optimality
 Is it impossible to do better?
9
What to Analyze ?
 Time Complexity
 Amount of computer time it needs to
execute the program to get the intended
result.
 Space Complexity
 Memory requirements based on the
problem size.
10
11
Properties of algorithms
 Input: what the algorithm takes in as input
 Output: what the algorithm produces as output
 Definiteness: the steps are defined precisely
 Correctness: should produce the correct output
 Finiteness: the steps required should be finite
 Effectiveness: each step must be able to be
performed in a finite amount of time.
What is DS & Algorithm ?
 Data Structure is a systematic way of
organizing and accessing data.
 Algorithm is a step-by-step procedure for
performing some task in a finite amount of
time.
Types of DS
 Linear data structures:
 Array
 Linked list
 Stack
 Queue
 Non-linear data structures:
 Graphs
 Trees
Linear & nonlinear Data Structures
 Main difference between linear & nonlinear
data structures lie in the way they organize
data elements.
 In linear data structures, data elements are
organized sequentially and therefore they
are easy to implement in the computer’s
memory.
 In nonlinear data structures, a data element
can be attached to several other data
elements to represent specific relationships
that exist among them. 18
Linear & nonlinear Data Structures
 Due to this nonlinear structure, they might
be difficult to be implemented in computer’s
linear memory compared to implementing
linear data structures.
 Selecting one data structure type over the
other should be done carefully by
considering the relationship among the
data elements that needs to be stored.
19
Array
 An array is a collection of homogeneous
type of data elements.
An array is consisting of a collection of
elements .
20
Stack
A Stack is a list of elements in which an
element may be inserted or deleted at one
end which is known as TOP of the stack.
21
22
STACKS
 A stack is a restricted linear list in which all additions
and deletions are made at one end, the top.
 If we insert a series of data items into a stack and then
remove them, the order of the data is reversed.
 This reversing attribute is why stacks are known as
last in, first out (LIFO) data structures.
Figure:-Three representations of stacks
Applications
Data Structures are applied extensively in
 Operating System,
 Database Management System,
 Statistical analysis package,
 Numerical Analysis
 Graphics,
 Artificial Intelligence,
 Simulation
ASYMPTOTIC NOTATION
25
Asymptotic Notation (O, ,  )
26
 Asymptotic notations are the terminology
that enables meaningful statements about
time & space complexity.
 To Calculate Running Time of an algorithm
Asymptotic Notation (O, ,  )
27
The time required by the given algorithm
falls under three types
1. Best-case time or the minimum time required
in executing the program.
2. Average case time or the average time
required in executing program.
3. Worst-case time or the maximum time
required in executing program.
Asymptotic Notation (O, ,  )
28
 Big “oh” (O)
 upper bound
 Omega ()
 lower bound
 Theta ()
 upper and lower bound
Time Complexity ---- For Loop
Statement
for(i=0; i <n; i++)
Total time=time(stmt1)+time(stmt2)+….+time(stmt n)
Note: For declarations, time count is 0
29
n+11 n
Total : 1+n+1+n = 2n+2 O(n)
Time Complexity ---- If-Else
Statement
if(condition)
{
stmt 1;
}
else
{
stmt2;
}
30
Either Stmt1 or Stmt2 will execute.
So, Worst case is
Max(time(stmt1, stmt2)
Max (O(n), O(1))  O(n)
Nested For loops
for(i=0; i <n; i++)
{
for(i=0; i <n; i++)
{
Stmts;
}
}
Note: For all the “for loop” statement multiplied
by the product.
31
Total : n *n O(n2)
Tabular Method
32
Iterative function to sum a list of numbers
Statement Frequency
float sum(float list[ ], int n)
{
float tempsum = 0;
int i;
for(i=0; i <n; i++)
tempsum += list[i];
return tempsum;
}
0
0
1
0
n+1
n
1
0
Total 2n+3
steps/execution
33
Statement s/e Frequency Total steps
float rsum(float list[ ], int n)
{
if (n)
return rsum(list, n-1)+list[n-1];
return list[0];
}
0 0 0
0 0 0
1 n+1 n+1
1 n n
1 1 1
0 0 0
Total 2n+2
Step count table for recursive summing function
Examples
Examples of Big Oh (O) Notation
34
O(1) Constant
O(n) Linear
O(n2) Quadratic
O(n3) Cubic
O(2n) Exponential
O(log n) Logarithm
35
Analysis of Algorithms
An algorithm is a finite set of precise instructions
for performing a computation or for solving a
problem.
What is the goal of analysis of algorithms?
 To compare algorithms mainly in terms of
running time but also in terms of other factors
(e.g., memory requirements, programmer's
effort etc.)
What do we mean by running time analysis?
 Determine how running time increases as the
size of the problem increases.
36
How do we compare algorithms?
We need to define a number of objective
measures.
(1) Compare execution times?
Not good: times are specific to a particular
computer !!
(2) Count the number of statements executed?
Not good: number of statements vary with
the programming language as well as the
style of the individual programmer.
37
Ideal Solution
Express running time as a function of the
input size n (i.e., f(n)).
Compare different functions corresponding
to running times.
Such an analysis is independent of machine
time, programming style, etc.
Asymptotic Notation (O, ,  )
39
 Big “oh” (O)
 upper bound
 Omega ()
 lower bound
 Theta ()
 upper and lower bound
40
Asymptotic Notation
 O notation: asymptotic “less than”:
 f(n)=O(g(n)) implies: f(n) “≤” g(n)
  notation: asymptotic “greater than”:
 f(n)=  (g(n)) implies: f(n) “≥” g(n)
  notation: asymptotic “equality”:
 f(n)=  (g(n)) implies: f(n) “=” g(n)
Big Oh- Notation
 Denoted by “O”.
 Using this we can compute the max possible
amount of time that an algorithm will take for
its application.
 Consider f(n) and g(n) to be two positive
function of “n” where the “n” is the input size.
f(n) = Og(n) iff f(n)<=c.g(n)
C>0 ; n0<n
41
42
Asymptotic notations
O-notation :
Big Oh- Notation
Example:
Derive Big-Oh Notation if f(n)=8n+7 & g(n)=n
Solution:
Assume if n=1
f(1) = 8+7 = 15 g(1) = 1
f(n) = Og(n) iff f(n)<=c.g(n)
Assume if c=15
f(n)<=c.g(n)
f(1)<=15.g(1)
15 <= 15
So f(n) = Og(n) 43
Big Oh- Notation
Step- II
Assume if n=2
f(2) = 16+7 = 23 g(2) = 2
f(2)<=15.g(2)
23 <= 30
So f(n) = Og(n)
44
Big Oh- Notation
Step- III
Assume if n=3
f(3) = 24+7 = 31 g(3) = 3
f(2)<=15.g(2)
31 <= 45
So f(n) = Og(n)
Conclusion: f(n)<=c.g(n); for c=15 & n0 = 1
45
Omega Notation
 Denoted by “”.
 Using this we can compute the minimum
amount of time that an algorithm will take for
its computation.
 Consider f(n) and g(n) to be two positive
function of “n” where the “n” is the input size.
f(n) =  g(n) iff f(n)>=c.g(n)
C>0 ; n0<n
46
47
Asymptotic notations (cont.)
 - notation
Theta Notation
 Denoted by “”.
 Using this we can compute the average
amount of time that an algorithm will take for
its computation.
f(n) =  g(n)
iff c1.g(n) <= f(n) <=c2.g(n)
48
49
Asymptotic notations (cont.)
-notation
University Questions – Ch 1 & 2
Distinguish between datatype and data structure.
Define O notation.
What is recursive function? State its advantages
What are linear and non-linear Data Structures
What are Asymptotic Notation
Why is it necessary to analyze an algorithm
What is Data Structure and Abstract Data Type?
Explain the Asymptotic notation to measure the
time complexity of an algorithm?
50
University Questions – Ch 1 & 2
What is Recursion? Give disadvantages of recursion.
Write a program to implement Towers of Hanoi .10 M
Explain Asymptotic Notations and write the properties
of asymptotic notations 10 M
51
Ad

More Related Content

What's hot (20)

Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
EllenGrace9
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
Vrushali Dhanokar
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
Ashutosh Satapathy
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
Soujanya V
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
Rajendra Dangwal
 
Big o notation
Big o notationBig o notation
Big o notation
hamza mushtaq
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
EllenGrace9
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
Vrushali Dhanokar
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
Soujanya V
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 

Similar to Data Structures and Algorithm Analysis (20)

DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
 
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptxData Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
RashidFaridChishti
 
Performance Analysis,Time complexity, Asymptotic Notations
Performance Analysis,Time complexity, Asymptotic NotationsPerformance Analysis,Time complexity, Asymptotic Notations
Performance Analysis,Time complexity, Asymptotic Notations
DrSMeenakshiSundaram1
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
Natarajan Angappan
 
Chapter 1 - Introduction to data structure.pptx
Chapter 1 - Introduction to data structure.pptxChapter 1 - Introduction to data structure.pptx
Chapter 1 - Introduction to data structure.pptx
gadisaAdamu
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
MemMem25
 
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
BCSE202LkkljkljkbbbnbnghghjghghghghghghghghBCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
shivapatil54
 
Data Structure - Lecture 1 - Introduction.pdf
Data Structure  - Lecture 1 - Introduction.pdfData Structure  - Lecture 1 - Introduction.pdf
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
DATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTESDATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTES
Aniruddha Paul
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
TechVision8
 
Chapter two
Chapter twoChapter two
Chapter two
mihiretu kassaye
 
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjcModule-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
shashashashashank
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
Tribhuvan University
 
Algorithms
Algorithms Algorithms
Algorithms
yashodhaHR2
 
assignment character education assignment
assignment character education assignmentassignment character education assignment
assignment character education assignment
tsegayeblen57
 
Analysis Framework, Asymptotic Notations
Analysis Framework, Asymptotic NotationsAnalysis Framework, Asymptotic Notations
Analysis Framework, Asymptotic Notations
DrSMeenakshiSundaram1
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptxData Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
RashidFaridChishti
 
Performance Analysis,Time complexity, Asymptotic Notations
Performance Analysis,Time complexity, Asymptotic NotationsPerformance Analysis,Time complexity, Asymptotic Notations
Performance Analysis,Time complexity, Asymptotic Notations
DrSMeenakshiSundaram1
 
Chapter 1 - Introduction to data structure.pptx
Chapter 1 - Introduction to data structure.pptxChapter 1 - Introduction to data structure.pptx
Chapter 1 - Introduction to data structure.pptx
gadisaAdamu
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
MemMem25
 
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
BCSE202LkkljkljkbbbnbnghghjghghghghghghghghBCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
shivapatil54
 
Data Structure - Lecture 1 - Introduction.pdf
Data Structure  - Lecture 1 - Introduction.pdfData Structure  - Lecture 1 - Introduction.pdf
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
DATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTESDATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTES
Aniruddha Paul
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
TechVision8
 
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjcModule-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
shashashashashank
 
assignment character education assignment
assignment character education assignmentassignment character education assignment
assignment character education assignment
tsegayeblen57
 
Analysis Framework, Asymptotic Notations
Analysis Framework, Asymptotic NotationsAnalysis Framework, Asymptotic Notations
Analysis Framework, Asymptotic Notations
DrSMeenakshiSundaram1
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
 
Ad

Recently uploaded (20)

Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Ad

Data Structures and Algorithm Analysis

  • 2. Objectives This Chapter introduces students to the analysis and design of computer algorithms. Upon completion of this chapter, students will be able to do the following:  Analyze the asymptotic performance of algorithms.  Demonstrate a familiarity with major algorithms and data structures.  Apply important algorithmic design paradigms and methods of analysis.  Synthesize efficient algorithms in common engineering design situations. 2
  • 3. What is an Algorithm? 3
  • 4. What is an Algorithm?  Algorithms are the ideas behind computer programs.  Algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output.  Algorithm is thus a sequence of computational steps that transform the input into the output. 4
  • 5. What is an Algorithm? Example:  Directions to somebody’s house is an algorithm.  A recipe for cooking a cake is an algorithm. 5
  • 6. What is a Program?  A program is a set of instructions which the computer will follow to solve a problem 6
  • 7. Introduction  Why we need algorithm analysis ?  Writing a working program is not good enough.  The program may be inefficient!  If the program is run on a large data set, then the running time becomes an issue. 7
  • 8. What to Analyze ?  Correctness  Does the input/output relation match algorithm requirement?  Amount of work done  Basic operations to do task finite amount of time  Amount of space used  Memory used 8
  • 9. What to Analyze ?  Simplicity, clarity  Verification and implementation.  Optimality  Is it impossible to do better? 9
  • 10. What to Analyze ?  Time Complexity  Amount of computer time it needs to execute the program to get the intended result.  Space Complexity  Memory requirements based on the problem size. 10
  • 11. 11 Properties of algorithms  Input: what the algorithm takes in as input  Output: what the algorithm produces as output  Definiteness: the steps are defined precisely  Correctness: should produce the correct output  Finiteness: the steps required should be finite  Effectiveness: each step must be able to be performed in a finite amount of time.
  • 12. What is DS & Algorithm ?  Data Structure is a systematic way of organizing and accessing data.  Algorithm is a step-by-step procedure for performing some task in a finite amount of time.
  • 13. Types of DS  Linear data structures:  Array  Linked list  Stack  Queue  Non-linear data structures:  Graphs  Trees
  • 14. Linear & nonlinear Data Structures  Main difference between linear & nonlinear data structures lie in the way they organize data elements.  In linear data structures, data elements are organized sequentially and therefore they are easy to implement in the computer’s memory.  In nonlinear data structures, a data element can be attached to several other data elements to represent specific relationships that exist among them. 18
  • 15. Linear & nonlinear Data Structures  Due to this nonlinear structure, they might be difficult to be implemented in computer’s linear memory compared to implementing linear data structures.  Selecting one data structure type over the other should be done carefully by considering the relationship among the data elements that needs to be stored. 19
  • 16. Array  An array is a collection of homogeneous type of data elements. An array is consisting of a collection of elements . 20
  • 17. Stack A Stack is a list of elements in which an element may be inserted or deleted at one end which is known as TOP of the stack. 21
  • 18. 22
  • 19. STACKS  A stack is a restricted linear list in which all additions and deletions are made at one end, the top.  If we insert a series of data items into a stack and then remove them, the order of the data is reversed.  This reversing attribute is why stacks are known as last in, first out (LIFO) data structures. Figure:-Three representations of stacks
  • 20. Applications Data Structures are applied extensively in  Operating System,  Database Management System,  Statistical analysis package,  Numerical Analysis  Graphics,  Artificial Intelligence,  Simulation
  • 22. Asymptotic Notation (O, ,  ) 26  Asymptotic notations are the terminology that enables meaningful statements about time & space complexity.  To Calculate Running Time of an algorithm
  • 23. Asymptotic Notation (O, ,  ) 27 The time required by the given algorithm falls under three types 1. Best-case time or the minimum time required in executing the program. 2. Average case time or the average time required in executing program. 3. Worst-case time or the maximum time required in executing program.
  • 24. Asymptotic Notation (O, ,  ) 28  Big “oh” (O)  upper bound  Omega ()  lower bound  Theta ()  upper and lower bound
  • 25. Time Complexity ---- For Loop Statement for(i=0; i <n; i++) Total time=time(stmt1)+time(stmt2)+….+time(stmt n) Note: For declarations, time count is 0 29 n+11 n Total : 1+n+1+n = 2n+2 O(n)
  • 26. Time Complexity ---- If-Else Statement if(condition) { stmt 1; } else { stmt2; } 30 Either Stmt1 or Stmt2 will execute. So, Worst case is Max(time(stmt1, stmt2) Max (O(n), O(1))  O(n)
  • 27. Nested For loops for(i=0; i <n; i++) { for(i=0; i <n; i++) { Stmts; } } Note: For all the “for loop” statement multiplied by the product. 31 Total : n *n O(n2)
  • 28. Tabular Method 32 Iterative function to sum a list of numbers Statement Frequency float sum(float list[ ], int n) { float tempsum = 0; int i; for(i=0; i <n; i++) tempsum += list[i]; return tempsum; } 0 0 1 0 n+1 n 1 0 Total 2n+3 steps/execution
  • 29. 33 Statement s/e Frequency Total steps float rsum(float list[ ], int n) { if (n) return rsum(list, n-1)+list[n-1]; return list[0]; } 0 0 0 0 0 0 1 n+1 n+1 1 n n 1 1 1 0 0 0 Total 2n+2 Step count table for recursive summing function
  • 30. Examples Examples of Big Oh (O) Notation 34 O(1) Constant O(n) Linear O(n2) Quadratic O(n3) Cubic O(2n) Exponential O(log n) Logarithm
  • 31. 35 Analysis of Algorithms An algorithm is a finite set of precise instructions for performing a computation or for solving a problem. What is the goal of analysis of algorithms?  To compare algorithms mainly in terms of running time but also in terms of other factors (e.g., memory requirements, programmer's effort etc.) What do we mean by running time analysis?  Determine how running time increases as the size of the problem increases.
  • 32. 36 How do we compare algorithms? We need to define a number of objective measures. (1) Compare execution times? Not good: times are specific to a particular computer !! (2) Count the number of statements executed? Not good: number of statements vary with the programming language as well as the style of the individual programmer.
  • 33. 37 Ideal Solution Express running time as a function of the input size n (i.e., f(n)). Compare different functions corresponding to running times. Such an analysis is independent of machine time, programming style, etc.
  • 34. Asymptotic Notation (O, ,  ) 39  Big “oh” (O)  upper bound  Omega ()  lower bound  Theta ()  upper and lower bound
  • 35. 40 Asymptotic Notation  O notation: asymptotic “less than”:  f(n)=O(g(n)) implies: f(n) “≤” g(n)   notation: asymptotic “greater than”:  f(n)=  (g(n)) implies: f(n) “≥” g(n)   notation: asymptotic “equality”:  f(n)=  (g(n)) implies: f(n) “=” g(n)
  • 36. Big Oh- Notation  Denoted by “O”.  Using this we can compute the max possible amount of time that an algorithm will take for its application.  Consider f(n) and g(n) to be two positive function of “n” where the “n” is the input size. f(n) = Og(n) iff f(n)<=c.g(n) C>0 ; n0<n 41
  • 38. Big Oh- Notation Example: Derive Big-Oh Notation if f(n)=8n+7 & g(n)=n Solution: Assume if n=1 f(1) = 8+7 = 15 g(1) = 1 f(n) = Og(n) iff f(n)<=c.g(n) Assume if c=15 f(n)<=c.g(n) f(1)<=15.g(1) 15 <= 15 So f(n) = Og(n) 43
  • 39. Big Oh- Notation Step- II Assume if n=2 f(2) = 16+7 = 23 g(2) = 2 f(2)<=15.g(2) 23 <= 30 So f(n) = Og(n) 44
  • 40. Big Oh- Notation Step- III Assume if n=3 f(3) = 24+7 = 31 g(3) = 3 f(2)<=15.g(2) 31 <= 45 So f(n) = Og(n) Conclusion: f(n)<=c.g(n); for c=15 & n0 = 1 45
  • 41. Omega Notation  Denoted by “”.  Using this we can compute the minimum amount of time that an algorithm will take for its computation.  Consider f(n) and g(n) to be two positive function of “n” where the “n” is the input size. f(n) =  g(n) iff f(n)>=c.g(n) C>0 ; n0<n 46
  • 43. Theta Notation  Denoted by “”.  Using this we can compute the average amount of time that an algorithm will take for its computation. f(n) =  g(n) iff c1.g(n) <= f(n) <=c2.g(n) 48
  • 45. University Questions – Ch 1 & 2 Distinguish between datatype and data structure. Define O notation. What is recursive function? State its advantages What are linear and non-linear Data Structures What are Asymptotic Notation Why is it necessary to analyze an algorithm What is Data Structure and Abstract Data Type? Explain the Asymptotic notation to measure the time complexity of an algorithm? 50
  • 46. University Questions – Ch 1 & 2 What is Recursion? Give disadvantages of recursion. Write a program to implement Towers of Hanoi .10 M Explain Asymptotic Notations and write the properties of asymptotic notations 10 M 51