SlideShare a Scribd company logo
Instructor: Sadia Arshid
ANALYSIS OF ALGORITHM
Introduction to Algorithms
ANALYSIS OF ALGORITHM
 Detailed study of the basic notions of the design of
algorithms and the underlying data structures
 Several measures of complexity are introduced
 Emphasis on the structure, complexity, and efficiency
of algorithms.
 Prepare the Students for Analyzing algorithms solving
same problems & making them capable of writing
optimize algorithms
Instructor: Sadia Arshid
ANALYSIS OF ALGORITHM
 Text Book:
The Design And Analysis of Algorithmby Anany Levitin
Fundamentals of Algorithmby Richard Neopolitan
 Reference Material:
AlgorithmDesign by Micheal T. Good Rich
Introduction to Algorithms /2E, T. H. Cormen, C. E. Leiserson, and
R. L. Rivest, MIT Press, McGraw-Hill, New York, NY, 2001.
 Grading policy

Instructor: Sadia Arshid
Assignments 5%
Quizzes 10%
Project 15%
Midterm 20%
Final 50%
WHAT IS AN ALGORITHM?
 An algorithm is a set of rules for carrying out calculation
either by hand or on a machine.
 An algorithm is a finite step-by-step procedure to
achieve a required result.
 An algorithm is a sequence of computational steps that
transform the input into the output.
 An algorithm is a sequence of operations performed on
data that have to be organized in data structures.
 An algorithm is an abstraction of a program to be
executed on a physical machine (model of
Instructor: Sadia Arshid
WHAT IS AN ALGORITHM?
An algorithmis a sequence of unambiguous
instructions for solving a problem, i.e., for obtaining
a required output for any legitimate input in a finite
amount of time.
Instructor: Sadia Arshid
WHAT IS AN ALGORITHM?
Instructor: Sadia Arshid
Problem
algorithm
“computer”input output
ALGORITHM
• Problem
• problem instance and solution
• Sort list of n numbers in ascending order
• Determine whether x is in list of n numbers
• Algorithm is a general solution which solves all
instances of a problem.
Instructor: Sadia Arshid
• Generality
• Finiteness
• Non-ambiguity
• Efficiency
Instructor: Sadia Arshid
What properties an algorithm should have ?
• The algorithm applies to all instances of input data not only
for particular instances
Example:
Let’s consider the problem of increasingly sorting a
sequence of values.
For instance:
(2,1,4,3,5) (1,2,3,4,5)
input data result
Instructor: Sadia Arshid
Generality
Method:
Instructor: Sadia Arshid
Generality (cont’d)
2 1 4 3 5Step 1:
1 2 4 3 5
1 2 4 3 5
1 2 3 4 5
Step 2:
Step 3:
Step 4:
Description:
- compare the first two
elements:
if there are not in the desired
order swap them
- compare the second and the
third element and do the same
…..
- continue until the last two
elements were compared
The sequence has been ordered
GENERALITY (CONT’D)
• Is this algorithm a general one ? I meant, does it
assure the ordering of ANY sequence of values ?
Instructor: Sadia Arshid
• Answer: NO
Counterexample:
3 2 1 4 5
2 3 1 4 5
2 1 3 4 5
2 1 3 4 5
In this case the method doesn’t work, it isn’t a general sorting
algorithm
FINITENESS
• An algorithm have to terminate, i.e. to stop after a finite
number of steps
Example
Step1: Assign 1 to x;
Step2: Increase x by 2;
Step3: If x=10 then STOP;
else GO TO Step 2
How does this algorithm work ?
Instructor: Sadia Arshid
FINITENESS (CONT’D)
How does this algorithm work and what does it produce?
Step1: Assign 1 to x;
Step2: Increase x by 2;
Step3: If x=10
then STOP;
else Print x; GO TO Step 2;
Instructor: Sadia Arshid
x=1
x=3 x=5 x=7 x=9 x=11
The algorithm generates odd numbers but it never stops !
FINITENESS (CONT’D)
The algorithm which generate all odd naturals smaller
than 10:
Step1: Assign 1 to x;
Step2: Increase x by 2;
Step3: If x>=10
then STOP;
else Print x; GO TO Step 2
Instructor: Sadia Arshid
NON-AMBIGUITY
The operations in an algorithm must be rigorously specified:
• At the execution of each step one have to know exactly which is the
next step which will be executed
Example:
Step 1: Set x to value 0
Step 2: Either increment x with 1 or decrement x with 1
Step 3: If x∈[-2,2] then go to Step 2; else Stop.
As long as does not exist a criterion by which one can decide if
x is incremented or decremented, the sequence above cannot be
Instructor: Sadia Arshid
NON-AMBIGUITY (CONT’D)
Let’s modify the previous algorithm as follows:
Step 1: Set x to value 0
Step 2: Flip a coin
Step 3: If one obtains head
then increment x with 1
else decrement x with 1
Step 3: If x∈[-2,2] then go to Step 2, else Stop.
• This time the algorithm can be executed but … different executions can be
different
Instructor: Sadia Arshid
EFFICIENCY
• The need to design efficient algorithms
• What is efficiency?
• Example
• Sequential search Vs. Binary Search
Instructor: Sadia Arshid
ALGORITHM ANALYSIS
• How to analyze an algorithm?
• Predicting the resources that the algorithm requires.
• Memory
• Communications Bandwidth
• Logic gates etc
• Most important is Computational Time
Instructor: Sadia Arshid
ALGORITHM ANALYSIS
• Important thing before analysis
• Model of the machine upon which the algorithms is
executed.
• Random Access Machine (RAM) (Sequential)
• Running Time: No. of primitive operations or
“steps executed”.Instructor: Sadia Arshid
RUNNING TIME
 Most algorithms transform
input objects into output
objects.
 The running time of an
algorithm typically grows
with the input size.
 Average case time is often
difficult to determine.
 We focus on the worst
case running time.
Easier to analyze
Crucial to applications such
as games, finance and
0
20
40
60
80
100
120
RunningTime
1000 2000 3000 4000
I nput Size
best case
average case
worst case
Instructor: Sadia Arshid
EXPERIMENTAL STUDIES
 Write a program
implementing the
algorithm
 Run the program with
inputs of varying size and
composition
 Use a method in “Time.h”
to get an accurate
measure of the actual
running time
 Plot the results
0
1000
2000
3000
4000
5000
6000
7000
8000
9000
0 50 100
I nput Size
Time(ms)
Instructor: Sadia Arshid
LIMITATIONS OF EXPERIMENTS
• It is necessary to implement the algorithm, which may
be difficult
• Results may not be indicative of the running time on
other inputs not included in the experiment.
• In order to compare two algorithms, the same hardware
and software environments must be used
Instructor: Sadia Arshid
THEORETICAL ANALYSIS
• Uses a high-level description of the algorithm instead
of an implementation
• Characterizes running time as a function of the input
size, n.
• Takes into account all possible inputs
• Allows us to evaluate the speed of an algorithm
independent of the hardware/software environment
Instructor: Sadia Arshid
ALGORITHM ANALYSIS
• Running Time
• We need a measure that is independent of computer,
programming language and the programmer.
• Concept of basic operation
• In sorting comparison is a basic operation.
Instructor: Sadia Arshid
ALGORITHM ANALYSIS
• How much time each construct / keyword of a
pseudo code takes to execute. Assume it takes ti
(the ith construct)
• Sum / Add up the execution time of all the
constructs / keywords. if there are m constructs
then
Instructor: Sadia Arshid
∑=
=
m
i
itT
1
ALGORITHM ANALYSIS
• That will be the execution time for a given input size
(say n)
Instructor: Sadia Arshid
∑=
=
m
i
in tT
1
♦Running time as the function of the input size
T(n)
ALGORITHM ANALYSIS
• What are the constructs / Keywords.
• Time for each construct
• Total Time
• Total time as a function of input size
Instructor: Sadia Arshid
ALGORITHM ANALYSIS
• Construct:
• Sequence
• Selection
• Iterations
• Recursion
Instructor: Sadia Arshid
ALGORITHM ANALYSIS
 Sequence Statements: Just add the running time of the
statements
 If-Then-Else: if (condition) S1 else S2
Running time of the test plus the larger of the running times
of S1 and S2.
 Iteration is at most the running time of the statements
inside the loop, including the times the number of
iterations.
 Nested Loops: Analyze these inside out. The total Running
time of a statement inside a group of nested loops is the
running time of the statement multiplied by the product of
the size of all the loops.
 Function Calls: Analyzing from inside to out. If there
are function calls, these must be analyzed first.
Instructor: Sadia Arshid
EXAMPLE
Instructor: Sadia Arshid
Algorithm arrayMax(A, n)
Input array A of n integers
Output maximum element of A
currentMax ← A[0]
for i ← 1 to n − 1 do
if A[i] > currentMax then
currentMax ← A[i]
return currentMax
Example: find max element of
an array
COUNTING PRIMITIVE
OPERATIONS
 By inspecting the pseudocode, we can determine the
maximum number of primitive operations executed by an
algorithm, as a function of the input size
AlgorithmarrayMax(A, n) # operations
currentMax ← A[0] 2
fori ← 1 to n − 1 do 1 + n
if A[i] > currentMax then 2(n − 1)
currentMax ← A[i] 2(n − 1)
{ increment counter i } 2(n − 1)
return currentMax 1
Total 7n − 2
Instructor: Sadia Arshid
ESTIMATING RUNNING TIME
• Algorithm arrayMax executes 7n− 2 primitive operations in the worst
case.
• This notation is complex to use. To simplify it we will be using order of
growth that is dominating term of expression; which is n (will be
discuss in detail later)
• Instead of computing running time of every statement of the algorithm
we can further simplify it by calculating running time of basic
operation only(Time Complexity) (will be discuss in detail later)
• In This example
• basic operation is comparison
• Executed n-1 number of times
• Order of growth is n
• Same as order of growth of computing running time of every statement.Instructor: Sadia Arshid
IMPORTANT PROBLEM TYPES
• Sorting
• Sorting keys
• Stable
• Inplace
• Searching
• String processing
Instructor: Sadia Arshid
IMPORTANT PROBLEM TYPES
• Graph problems
• Combinatorial Problems
• Geometric Problems
• Numerical Problems
Instructor: Sadia Arshid
FUNDAMENTAL DATA
STRUCTURES Linear data Structures
Arrays
Link list
Stack
Queue
 Graphs
Adjacency Matrix
Adjacency Link list
 Trees
 Set & Dictionaries
Instructor: Sadia Arshid

More Related Content

What's hot

Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
smruti sarangi
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
smruti sarangi
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Swapnil Agrawal
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
Rajendra Dangwal
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
jehan1987
 
asymptotic notation
asymptotic notationasymptotic notation
asymptotic notation
SangeethaSasi1
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
Mohamed Loey
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
Rajendran
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
B.Kirron Reddi
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
Ra'Fat Al-Msie'deen
 
Daa unit 5
Daa unit 5Daa unit 5
Daa unit 5
Abhimanyu Mishra
 

What's hot (20)

Cis435 week01
Cis435 week01Cis435 week01
Cis435 week01
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
chapter 1
chapter 1chapter 1
chapter 1
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Unit 1
Unit 1Unit 1
Unit 1
 
asymptotic notation
asymptotic notationasymptotic notation
asymptotic notation
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
 
Daa unit 5
Daa unit 5Daa unit 5
Daa unit 5
 

Similar to 01 intro to algorithm--updated 2015

Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
Dabbal Singh Mahara
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
rajesshs31r
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
Amna Saeed
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
GovindUpadhyay25
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
racha49
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
SamridhiGulati4
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
BhargaviDalal4
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
ibrahim386946
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
RobinRohit2
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 introchidabdu
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
 
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITYDESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
AneetaGrace1
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.ppt
RaoHamza24
 
Algorithms overview
Algorithms overviewAlgorithms overview
Algorithms overview
Deborah Akuoko
 

Similar to 01 intro to algorithm--updated 2015 (20)

Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
 
Daa
DaaDaa
Daa
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITYDESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.ppt
 
Algorithms overview
Algorithms overviewAlgorithms overview
Algorithms overview
 

More from Hira Gul

Final iwvc
Final iwvcFinal iwvc
Final iwvc
Hira Gul
 
Oerating system project
Oerating system projectOerating system project
Oerating system project
Hira Gul
 
project Judaism iwvc presentation
project Judaism iwvc presentation project Judaism iwvc presentation
project Judaism iwvc presentation
Hira Gul
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
Hira Gul
 
08 decrease and conquer spring 15
08 decrease and conquer spring 1508 decrease and conquer spring 15
08 decrease and conquer spring 15
Hira Gul
 
07 dc3
07 dc307 dc3
07 dc3
Hira Gul
 
06 dc2
06 dc206 dc2
06 dc2
Hira Gul
 
05 dc1
05 dc105 dc1
05 dc1
Hira Gul
 
04 brute force
04 brute force04 brute force
04 brute force
Hira Gul
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
Hira Gul
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
Hira Gul
 

More from Hira Gul (12)

Final iwvc
Final iwvcFinal iwvc
Final iwvc
 
Oerating system project
Oerating system projectOerating system project
Oerating system project
 
project Judaism iwvc presentation
project Judaism iwvc presentation project Judaism iwvc presentation
project Judaism iwvc presentation
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
 
08 decrease and conquer spring 15
08 decrease and conquer spring 1508 decrease and conquer spring 15
08 decrease and conquer spring 15
 
07 dc3
07 dc307 dc3
07 dc3
 
06 dc2
06 dc206 dc2
06 dc2
 
05 dc1
05 dc105 dc1
05 dc1
 
04 brute force
04 brute force04 brute force
04 brute force
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
 
03 dc
03 dc03 dc
03 dc
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 

Recently uploaded

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

01 intro to algorithm--updated 2015

  • 1. Instructor: Sadia Arshid ANALYSIS OF ALGORITHM Introduction to Algorithms
  • 2. ANALYSIS OF ALGORITHM  Detailed study of the basic notions of the design of algorithms and the underlying data structures  Several measures of complexity are introduced  Emphasis on the structure, complexity, and efficiency of algorithms.  Prepare the Students for Analyzing algorithms solving same problems & making them capable of writing optimize algorithms Instructor: Sadia Arshid
  • 3. ANALYSIS OF ALGORITHM  Text Book: The Design And Analysis of Algorithmby Anany Levitin Fundamentals of Algorithmby Richard Neopolitan  Reference Material: AlgorithmDesign by Micheal T. Good Rich Introduction to Algorithms /2E, T. H. Cormen, C. E. Leiserson, and R. L. Rivest, MIT Press, McGraw-Hill, New York, NY, 2001.  Grading policy  Instructor: Sadia Arshid Assignments 5% Quizzes 10% Project 15% Midterm 20% Final 50%
  • 4. WHAT IS AN ALGORITHM?  An algorithm is a set of rules for carrying out calculation either by hand or on a machine.  An algorithm is a finite step-by-step procedure to achieve a required result.  An algorithm is a sequence of computational steps that transform the input into the output.  An algorithm is a sequence of operations performed on data that have to be organized in data structures.  An algorithm is an abstraction of a program to be executed on a physical machine (model of Instructor: Sadia Arshid
  • 5. WHAT IS AN ALGORITHM? An algorithmis a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time. Instructor: Sadia Arshid
  • 6. WHAT IS AN ALGORITHM? Instructor: Sadia Arshid Problem algorithm “computer”input output
  • 7. ALGORITHM • Problem • problem instance and solution • Sort list of n numbers in ascending order • Determine whether x is in list of n numbers • Algorithm is a general solution which solves all instances of a problem. Instructor: Sadia Arshid
  • 8. • Generality • Finiteness • Non-ambiguity • Efficiency Instructor: Sadia Arshid What properties an algorithm should have ?
  • 9. • The algorithm applies to all instances of input data not only for particular instances Example: Let’s consider the problem of increasingly sorting a sequence of values. For instance: (2,1,4,3,5) (1,2,3,4,5) input data result Instructor: Sadia Arshid Generality
  • 10. Method: Instructor: Sadia Arshid Generality (cont’d) 2 1 4 3 5Step 1: 1 2 4 3 5 1 2 4 3 5 1 2 3 4 5 Step 2: Step 3: Step 4: Description: - compare the first two elements: if there are not in the desired order swap them - compare the second and the third element and do the same ….. - continue until the last two elements were compared The sequence has been ordered
  • 11. GENERALITY (CONT’D) • Is this algorithm a general one ? I meant, does it assure the ordering of ANY sequence of values ? Instructor: Sadia Arshid • Answer: NO Counterexample: 3 2 1 4 5 2 3 1 4 5 2 1 3 4 5 2 1 3 4 5 In this case the method doesn’t work, it isn’t a general sorting algorithm
  • 12. FINITENESS • An algorithm have to terminate, i.e. to stop after a finite number of steps Example Step1: Assign 1 to x; Step2: Increase x by 2; Step3: If x=10 then STOP; else GO TO Step 2 How does this algorithm work ? Instructor: Sadia Arshid
  • 13. FINITENESS (CONT’D) How does this algorithm work and what does it produce? Step1: Assign 1 to x; Step2: Increase x by 2; Step3: If x=10 then STOP; else Print x; GO TO Step 2; Instructor: Sadia Arshid x=1 x=3 x=5 x=7 x=9 x=11 The algorithm generates odd numbers but it never stops !
  • 14. FINITENESS (CONT’D) The algorithm which generate all odd naturals smaller than 10: Step1: Assign 1 to x; Step2: Increase x by 2; Step3: If x>=10 then STOP; else Print x; GO TO Step 2 Instructor: Sadia Arshid
  • 15. NON-AMBIGUITY The operations in an algorithm must be rigorously specified: • At the execution of each step one have to know exactly which is the next step which will be executed Example: Step 1: Set x to value 0 Step 2: Either increment x with 1 or decrement x with 1 Step 3: If x∈[-2,2] then go to Step 2; else Stop. As long as does not exist a criterion by which one can decide if x is incremented or decremented, the sequence above cannot be Instructor: Sadia Arshid
  • 16. NON-AMBIGUITY (CONT’D) Let’s modify the previous algorithm as follows: Step 1: Set x to value 0 Step 2: Flip a coin Step 3: If one obtains head then increment x with 1 else decrement x with 1 Step 3: If x∈[-2,2] then go to Step 2, else Stop. • This time the algorithm can be executed but … different executions can be different Instructor: Sadia Arshid
  • 17. EFFICIENCY • The need to design efficient algorithms • What is efficiency? • Example • Sequential search Vs. Binary Search Instructor: Sadia Arshid
  • 18. ALGORITHM ANALYSIS • How to analyze an algorithm? • Predicting the resources that the algorithm requires. • Memory • Communications Bandwidth • Logic gates etc • Most important is Computational Time Instructor: Sadia Arshid
  • 19. ALGORITHM ANALYSIS • Important thing before analysis • Model of the machine upon which the algorithms is executed. • Random Access Machine (RAM) (Sequential) • Running Time: No. of primitive operations or “steps executed”.Instructor: Sadia Arshid
  • 20. RUNNING TIME  Most algorithms transform input objects into output objects.  The running time of an algorithm typically grows with the input size.  Average case time is often difficult to determine.  We focus on the worst case running time. Easier to analyze Crucial to applications such as games, finance and 0 20 40 60 80 100 120 RunningTime 1000 2000 3000 4000 I nput Size best case average case worst case Instructor: Sadia Arshid
  • 21. EXPERIMENTAL STUDIES  Write a program implementing the algorithm  Run the program with inputs of varying size and composition  Use a method in “Time.h” to get an accurate measure of the actual running time  Plot the results 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 0 50 100 I nput Size Time(ms) Instructor: Sadia Arshid
  • 22. LIMITATIONS OF EXPERIMENTS • It is necessary to implement the algorithm, which may be difficult • Results may not be indicative of the running time on other inputs not included in the experiment. • In order to compare two algorithms, the same hardware and software environments must be used Instructor: Sadia Arshid
  • 23. THEORETICAL ANALYSIS • Uses a high-level description of the algorithm instead of an implementation • Characterizes running time as a function of the input size, n. • Takes into account all possible inputs • Allows us to evaluate the speed of an algorithm independent of the hardware/software environment Instructor: Sadia Arshid
  • 24. ALGORITHM ANALYSIS • Running Time • We need a measure that is independent of computer, programming language and the programmer. • Concept of basic operation • In sorting comparison is a basic operation. Instructor: Sadia Arshid
  • 25. ALGORITHM ANALYSIS • How much time each construct / keyword of a pseudo code takes to execute. Assume it takes ti (the ith construct) • Sum / Add up the execution time of all the constructs / keywords. if there are m constructs then Instructor: Sadia Arshid ∑= = m i itT 1
  • 26. ALGORITHM ANALYSIS • That will be the execution time for a given input size (say n) Instructor: Sadia Arshid ∑= = m i in tT 1 ♦Running time as the function of the input size T(n)
  • 27. ALGORITHM ANALYSIS • What are the constructs / Keywords. • Time for each construct • Total Time • Total time as a function of input size Instructor: Sadia Arshid
  • 28. ALGORITHM ANALYSIS • Construct: • Sequence • Selection • Iterations • Recursion Instructor: Sadia Arshid
  • 29. ALGORITHM ANALYSIS  Sequence Statements: Just add the running time of the statements  If-Then-Else: if (condition) S1 else S2 Running time of the test plus the larger of the running times of S1 and S2.  Iteration is at most the running time of the statements inside the loop, including the times the number of iterations.  Nested Loops: Analyze these inside out. The total Running time of a statement inside a group of nested loops is the running time of the statement multiplied by the product of the size of all the loops.  Function Calls: Analyzing from inside to out. If there are function calls, these must be analyzed first. Instructor: Sadia Arshid
  • 30. EXAMPLE Instructor: Sadia Arshid Algorithm arrayMax(A, n) Input array A of n integers Output maximum element of A currentMax ← A[0] for i ← 1 to n − 1 do if A[i] > currentMax then currentMax ← A[i] return currentMax Example: find max element of an array
  • 31. COUNTING PRIMITIVE OPERATIONS  By inspecting the pseudocode, we can determine the maximum number of primitive operations executed by an algorithm, as a function of the input size AlgorithmarrayMax(A, n) # operations currentMax ← A[0] 2 fori ← 1 to n − 1 do 1 + n if A[i] > currentMax then 2(n − 1) currentMax ← A[i] 2(n − 1) { increment counter i } 2(n − 1) return currentMax 1 Total 7n − 2 Instructor: Sadia Arshid
  • 32. ESTIMATING RUNNING TIME • Algorithm arrayMax executes 7n− 2 primitive operations in the worst case. • This notation is complex to use. To simplify it we will be using order of growth that is dominating term of expression; which is n (will be discuss in detail later) • Instead of computing running time of every statement of the algorithm we can further simplify it by calculating running time of basic operation only(Time Complexity) (will be discuss in detail later) • In This example • basic operation is comparison • Executed n-1 number of times • Order of growth is n • Same as order of growth of computing running time of every statement.Instructor: Sadia Arshid
  • 33. IMPORTANT PROBLEM TYPES • Sorting • Sorting keys • Stable • Inplace • Searching • String processing Instructor: Sadia Arshid
  • 34. IMPORTANT PROBLEM TYPES • Graph problems • Combinatorial Problems • Geometric Problems • Numerical Problems Instructor: Sadia Arshid
  • 35. FUNDAMENTAL DATA STRUCTURES Linear data Structures Arrays Link list Stack Queue  Graphs Adjacency Matrix Adjacency Link list  Trees  Set & Dictionaries Instructor: Sadia Arshid