SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
CS-311
Design and Analysis of
Algorithms
Muhammad Naman
Objectives
 Design algorithms using different
algorithms design techniques i.e. Divide
and Conquer, Dynamic Programming,
Greedy Algorithms & Backtracking etc for
different problem areas (sorting, pattern
matching, graphs, compression, encryption
etc.)
 Analyse Algorithms (estimate upper &
lower bounds without coding and running
the algorithms) and compare the efficiency
of more than one algorithm for a problem.
 Logically think and develop problem
solving skills
 Read and understand research papers in
this area
What is an Algorithm?
Although there is no universally
agreed-on wording to describe this
notion, there is general agreement
about what the concept means:
An algorithm is 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.
What is an Algorithm?
What is an Algorithm?
The reference to "instructions" in the
definition implies that there is something
or someone capable of understanding and
following the instructions given.
We call this a "computer," keeping in mind
that before the electronic computer was
invented, the word "computer" meant a
human being involved in performing
numeric calculations.
Nowadays, of course, "computers" are
those ubiquitous electronic devices that
have become indispensable in almost
everything we do.
illustrate several important points
As examples illustrating the notion of
algorithm, we consider three methods
for solving the same problem (detail
in Lecture 02):
Computing the greatest common
divisor of two integers.
These examples will help us to
illustrate several important points:
The non-ambiguity requirement for
each step of an algorithm cannot be
compromised.
illustrate several important points
The range of inputs for which an
algorithm works has to be specified
carefully.
The same algorithm can be
represented in several different ways.
Several algorithms for solving the
same problem may exist.
Algorithms for the same problem can
be based on very different ideas and
can solve the problem with
dramatically different speeds.
Process to Solve a Problem
Understand the problem
Formulate a solution / algorithm
Design a program
Implement the program
Execute the code
Measure the performance
See if the solution is ok
Sorting Problem
Consider the problem of sorting
numbers.
INPUT: Sequence of n numbers
<a1,a2,a3, ….an>
OUTPUT: Permutation (reordering)
<a1`,a2`,a3`,….an`> of the input
sequence such that
a1`<a2`<a3`<…..<an`
Many algorithms are available.
Selection Sort
1. Get a list of unsorted numbers
2. Set a marker for the unsorted section at
the front of the list
3. Repeat steps 4 - 6 until one number
remains in the unsorted section
4. Compare all unsorted numbers in order to
select the smallest one
5. Swap this number with the first number in
the unsorted section
6. Advance the marker to the right one
position
7. Stop
Merge Sort
Algorithm
Divide sequence of m elements into two
sequences of m/2 elements
Conquer both sub-sequences using Merge
Sort (recursively)
Combine two sorted sub-sequences using
merge
Sorting Problem…..
Which sorting algorithm is best.
Implement both algorithms
See the result of simulation
Sorting Problem…..
Sorting Analysis, processor speed 500MHz
Data Size
Selection Sort Merge Sort
10 K 1 0
20 K 4 0
30 K 11 0
50 K 31 0
75 K 72 0
1 Lac 132 0
2 Lac 586 1
1 Million 10
2 Million 21
3 Million 33
5 Million 60
7.5 Million 90
10 Million 136
Execution Time in Seconds
Sorting Problem…..
Sorting Analysis
0
100
200
300
400
500
600
700
1
0
K
3
0
K
7
5
K
2
L
a
c
2
M
i
l
l
i
o
n
5
M
i
l
l
i
o
n
1
0
M
i
l
l
i
o
n
Data Size
Execution
time
in
seconds
Data Size
Selection Sort
Merge Sort
Process to Solve a Problem
Understand the problem
Formulate a solution / algorithm
Analyze the algorithm
 Design a program
 Implement the program
 Execute the code
 Measure the performance
See if the solution is ok
Algorithm Analysis
How to analyze an algorithm?
Predict the resources that the
algorithm requires
Memory
Communications Bandwidth
Logic gates etc
Most important is Computational Time
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”.
Algorithm Analysis
How do we write algorithms?
Pseudo Code:
 Similar construct / keywords as in a
high level programming languages, e.g.
in C, Pascal etc.
 Structured semantics of the high level
languages without caring about the
syntactic errors / grammatical rules
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



m
i
i
t
T
1
Algorithm Analysis
That will be the execution time for a
given input size (say n)



m
i
i
n t
T
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
Algorithm Analysis
Construct:
 Sequence
 Selection
 Iterations
 Recursion
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 tests) 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.
Home Work
 Read Mathematics Revision Handouts
available at photocopy shop
Solve Exercises Given at the end
Assignment # 1
 Due date Monday (12 September 2022) at
Commencement of Class.

Contenu connexe

Similaire à Lecture 01-2.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.pptBhargaviDalal4
 
Data structures algorithms basics
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basicsayeshasafdar8
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Prashanth Shivakumar
 
Intro to DS.pptx
Intro to DS.pptxIntro to DS.pptx
Intro to DS.pptxUsman Ahmed
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.pptINAM352782
 
DAA 1 ppt.pptx
DAA 1 ppt.pptxDAA 1 ppt.pptx
DAA 1 ppt.pptxRAJESH S
 
DAA ppt.pptx
DAA ppt.pptxDAA ppt.pptx
DAA ppt.pptxRAJESH S
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.pptALIZAIB KHAN
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sitSaurabh846965
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and reviewAbdullah Al-hazmy
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdfGOWTHAMR721887
 

Similaire à Lecture 01-2.ppt (20)

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
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Data structures algorithms basics
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basics
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01
 
Intro to DS.pptx
Intro to DS.pptxIntro to DS.pptx
Intro to DS.pptx
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.ppt
 
DAA 1 ppt.pptx
DAA 1 ppt.pptxDAA 1 ppt.pptx
DAA 1 ppt.pptx
 
DAA ppt.pptx
DAA ppt.pptxDAA ppt.pptx
DAA ppt.pptx
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
 
Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Chapter one
Chapter oneChapter one
Chapter one
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and review
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
 

Dernier

10 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 202410 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 2024digital learning point
 
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Associazione Digital Days
 
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinGeneral Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinSamar Hossam ElDin Ahmed
 
CAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfCAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfAlasAlthaher
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxKevinYaelJimnezSanti
 
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Yantram Animation Studio Corporation
 
Sharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme ManagementSharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme ManagementMd. Shariful Hoque
 
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisFW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisPeclers Paris
 
Interior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioInterior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioRMG Project Studio
 
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...Pranav Subramanian
 
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...Pranav Subramanian
 
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...Pranav Subramanian
 
ArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern HomesArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern HomesVellyslav Petrov
 
NBA power point presentation final copy y
NBA power point presentation final copy yNBA power point presentation final copy y
NBA power point presentation final copy ysrajece
 
The spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyThe spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyChristopher Totten
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptJIT KUMAR GUPTA
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfLucyBonelli
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssNadaMohammed714321
 
Karim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppKarim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppNadaMohammed714321
 

Dernier (20)

10 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 202410 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 2024
 
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
 
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinGeneral Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
 
CAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfCAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdf
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptx
 
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
 
Sharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme ManagementSharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme Management
 
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisFW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
 
Interior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioInterior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project Studio
 
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
 
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
 
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
 
ArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern HomesArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern Homes
 
NBA power point presentation final copy y
NBA power point presentation final copy yNBA power point presentation final copy y
NBA power point presentation final copy y
 
ASME B31.4-2022 estandar ductos año 2022
ASME B31.4-2022 estandar ductos año 2022ASME B31.4-2022 estandar ductos año 2022
ASME B31.4-2022 estandar ductos año 2022
 
The spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyThe spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenology
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssss
 
Karim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppKarim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 ppppppppppppppp
 

Lecture 01-2.ppt

  • 1. CS-311 Design and Analysis of Algorithms Muhammad Naman
  • 2. Objectives  Design algorithms using different algorithms design techniques i.e. Divide and Conquer, Dynamic Programming, Greedy Algorithms & Backtracking etc for different problem areas (sorting, pattern matching, graphs, compression, encryption etc.)  Analyse Algorithms (estimate upper & lower bounds without coding and running the algorithms) and compare the efficiency of more than one algorithm for a problem.  Logically think and develop problem solving skills  Read and understand research papers in this area
  • 3. What is an Algorithm? Although there is no universally agreed-on wording to describe this notion, there is general agreement about what the concept means: An algorithm is 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.
  • 4. What is an Algorithm?
  • 5. What is an Algorithm? The reference to "instructions" in the definition implies that there is something or someone capable of understanding and following the instructions given. We call this a "computer," keeping in mind that before the electronic computer was invented, the word "computer" meant a human being involved in performing numeric calculations. Nowadays, of course, "computers" are those ubiquitous electronic devices that have become indispensable in almost everything we do.
  • 6. illustrate several important points As examples illustrating the notion of algorithm, we consider three methods for solving the same problem (detail in Lecture 02): Computing the greatest common divisor of two integers. These examples will help us to illustrate several important points: The non-ambiguity requirement for each step of an algorithm cannot be compromised.
  • 7. illustrate several important points The range of inputs for which an algorithm works has to be specified carefully. The same algorithm can be represented in several different ways. Several algorithms for solving the same problem may exist. Algorithms for the same problem can be based on very different ideas and can solve the problem with dramatically different speeds.
  • 8. Process to Solve a Problem Understand the problem Formulate a solution / algorithm Design a program Implement the program Execute the code Measure the performance See if the solution is ok
  • 9. Sorting Problem Consider the problem of sorting numbers. INPUT: Sequence of n numbers <a1,a2,a3, ….an> OUTPUT: Permutation (reordering) <a1`,a2`,a3`,….an`> of the input sequence such that a1`<a2`<a3`<…..<an` Many algorithms are available.
  • 10. Selection Sort 1. Get a list of unsorted numbers 2. Set a marker for the unsorted section at the front of the list 3. Repeat steps 4 - 6 until one number remains in the unsorted section 4. Compare all unsorted numbers in order to select the smallest one 5. Swap this number with the first number in the unsorted section 6. Advance the marker to the right one position 7. Stop
  • 11. Merge Sort Algorithm Divide sequence of m elements into two sequences of m/2 elements Conquer both sub-sequences using Merge Sort (recursively) Combine two sorted sub-sequences using merge
  • 12. Sorting Problem….. Which sorting algorithm is best. Implement both algorithms See the result of simulation
  • 13. Sorting Problem….. Sorting Analysis, processor speed 500MHz Data Size Selection Sort Merge Sort 10 K 1 0 20 K 4 0 30 K 11 0 50 K 31 0 75 K 72 0 1 Lac 132 0 2 Lac 586 1 1 Million 10 2 Million 21 3 Million 33 5 Million 60 7.5 Million 90 10 Million 136 Execution Time in Seconds
  • 15. Process to Solve a Problem Understand the problem Formulate a solution / algorithm Analyze the algorithm  Design a program  Implement the program  Execute the code  Measure the performance See if the solution is ok
  • 16. Algorithm Analysis How to analyze an algorithm? Predict the resources that the algorithm requires Memory Communications Bandwidth Logic gates etc Most important is Computational Time
  • 17. 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”.
  • 18. Algorithm Analysis How do we write algorithms? Pseudo Code:  Similar construct / keywords as in a high level programming languages, e.g. in C, Pascal etc.  Structured semantics of the high level languages without caring about the syntactic errors / grammatical rules
  • 19. 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    m i i t T 1
  • 20. Algorithm Analysis That will be the execution time for a given input size (say n)    m i i n t T 1 Running time as the function of the input size T(n)
  • 21. Algorithm Analysis What are the constructs / Keywords. Time for each construct Total Time Total time as a function of input size
  • 22. Algorithm Analysis Construct:  Sequence  Selection  Iterations  Recursion
  • 23. 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 tests) 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.
  • 24. Home Work  Read Mathematics Revision Handouts available at photocopy shop Solve Exercises Given at the end Assignment # 1  Due date Monday (12 September 2022) at Commencement of Class.