SlideShare a Scribd company logo
1 of 30
Download to read offline
Design and Analysis of Algorithms
Lecture 1
β€’ Overview of the course
β€’ Closest Pair problem
1
https://moodle.cse.iitk.ac.in
CS345A
Algorithms-II
Aim of the course
To empower each student with the skills to design algorithms
β€’ With provable guarantee on correctness.
β€’ With provable guarantee on their efficiency.
2
Algorithm Paradigm
Motivation:
β€’ Many problems whose algorithms are based on a common approach.
βž” A need of a systematic study of the characteristics of such approaches.
Algorithm Paradigms:
β€’ Divide and Conquer
β€’ Greedy Strategy
β€’ Dynamic Programming
3
(advanced)
(advanced)
Maximum Flow
Given a network for transporting certain commodity (water/bits)
from a designated source vertex 𝒔 and sink vertex 𝒕.
Each edge has a certain capacity (max rate per unit time at which commodity
can be pumped along that edge),
Compute the maximum rate at which we can pump flow from 𝒔 to 𝒕.
Constraints: capacity constraint and conservation constraint. 4
𝒔
𝒗
𝒖
𝒙
π’š
𝒕
2
17
5
6
8
17
4
15
16
7
14
Miscellaneous
β€’ Matching in Graphs
Maximum matching, Stable matching
β€’ Amortized Analysis
A powerful technique to analyse time complexity of algorithms
β€’ String Matching
β€’ Linear Programming
5
Last topic on Algorithms
β€’ NP Complete problems
β€’ Approximation/randomized Algorithms
6
Data Structures
7
Data structures
β€’ Augmented Binary Search Trees
β€’ Range Minima Data structure (optimal size)
β€’ Fibonacci Heap
8
: Additional information
Orthogonal Range searching
Problem: Preprocess a set of 𝒏 points so that given any query rectangle,
the number of points lying inside it can be reported efficiently.
Data structure:
size = O(𝒏 log 𝒏), Query = O( log2 𝒏),
size = O(𝒏), Query = O( 𝑛), 9
Rectangle
A novel application of augmented BST
Try to solve it…
You can surely do itβ€¦β˜Ί
Rectangle
Divide and Conquer
10
A paradigm for Algorithm Design
An Overview
A problem in this paradigm is solved in the following way.
1. Divide the problem instance into two or more instances of the same problem.
2. Solve each smaller instance recursively (base case suitably defined).
3. Combine the solutions of the smaller instances
to get the solution of the original instance.
11
This is usually the main nontrivial step
in the design of an algorithm using
divide and conquer strategy
Example Problems
1. Merge Sort
2. Multiplication of two 𝒏-bit integers.
3. Counting the number of inversions in an array.
4. Median finding in linear time.
12
PROBLEM 1
Closest Pair of Points
13
The Closest Pair Problem
14
𝜹
Closest Pair of Points
Problem Definition:
Given a set 𝑷 of 𝒏 > 𝟏 points in plane,
compute the pair of points with minimum Euclidean distance.
Deterministic algorithms:
β€’ O(π’πŸ) : Trivial algorithm
β€’ O(𝒏 π₯𝐨𝐠 𝒏) : Divide and Conquer based algorithm
15
Hint/Tool No. 1
Exercise:
What is the maximum number of points that can be placed in a unit square
such that the minimum distance is at least 1 ?
Answer: 4.
16
1
1
2
A discrete math exercise
If there are more than
4 points, at least one
of the four small
squares will have
more than 1 points.
Hint/Tool No. 2
Question:
For which algorithmic problems do we need a suitable data structure ?
Answer:
If the problem involves β€œmany” operations of same type on a given data.
For example, it is worth sorting an array only if there are going to be many
search queries on it.
Let us see if you can use this principle in today’s class itself ☺
17
When do we use a data structure ?
The divide step
18
𝒏
𝟐
points
𝒏
𝟐
points
The conquer step
19
πœΉπ‘³
πœΉπ‘Ή
Compute closest pair of the
left half set
Compute closest pair of the
right half set
Notice πœΉπ‘³ < πœΉπ‘Ή for this given instance
The combine step
20
πœΉπ‘³
πœΉπ‘Ή
πœΉπ‘³
πœΉπ‘³
Which points do
we need to focus
on for the closest
pairs ?
The combine step
21
πœΉπ‘³
πœΉπ‘Ή
πœΉπ‘³
πœΉπ‘³
But there may still be Θ(𝑛2
)
pairs of points here So what
to do ?
The combine step
22
πœΉπ‘³
πœΉπ‘Ή
πœΉπ‘³
πœΉπ‘³
Focus on a point 𝒑 in
left strip.
Where do we have to search for the
points in the right strip that can form a
pair with 𝒑 at distance < πœΉπ‘³ ?
𝒑
The combine step
23
πœΉπ‘³
πœΉπ‘Ή
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
𝒑
The combine step
24
πœΉπ‘³
πœΉπ‘Ή
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
Only the points lying in these
2 red squares are relevant as
far as 𝒑 is concerned.
𝒑
How many points can
there be in these 2 red
squares each of lengthπœΉπ‘³?
Surely not more than 8
(using Hint 1)
How to find the points in
these red square for point 𝒑 ?
It will take O(𝒏) time for a given 𝒑.
It is time to use Hint/Tool no. 2.
Think for a while before going to
the next slide.
The combine step
25
πœΉπ‘³
πœΉπ‘Ή
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
We need to find points in the
2 red square for every point
in the left strip.
So build a suitable data structure
for points in the right strip so that
we can answer such query efficiently
for each point in the left strip.
What will be
the data structure ?
An array storing the points of
the right strip in increasing
order of y-coordinates.
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
πœΉπ‘³
Divide and Conquer based algorithm
CP-Distance(𝑃)
{ If (| 𝑃 |=1 ) return infinity;
{ Compute π‘₯-median of 𝑃;
(𝑃𝐿, 𝑃𝑅)οƒŸSplit-by-π‘₯-median(𝑃);
πœΉπ‘³οƒŸ CP-Distance(𝑃𝐿) ;
πœΉπ‘ΉοƒŸ CP-Distance(𝑃𝑅) ;
πœΉοƒŸ min(πœΉπ‘³, πœΉπ‘Ή);
𝑆𝐿 οƒŸ strip of 𝑃𝐿;
𝑆𝑅 οƒŸ strip of 𝑃𝑅;
𝐴 οƒŸ Sorted array of 𝑆𝑅;
For each 𝑝 ∈ 𝑆𝐿,
π’š οƒŸ y-coordinate of 𝑝;
Search 𝐴 for points with y-coordinate within π’š Β± 𝜹;
Compute distance from 𝑝 to each of these points;
Update 𝜹 accordingly;
return 𝜹;
}
26
Divide step
Combine/conquer step
𝑢( 𝐏 log 𝐏) time
𝑢( 𝐏 ) + 2 T(|𝐏|/2) time
Running time of the algorithm
What is the recurrence for running time?
T(𝑛) = c 𝑛 log 𝑛 + 2 T(𝑛/2)
βž”
T(𝑛) = O( 𝑛 log2𝑛)
Theorem:
There exists an O( 𝑛 log2𝑛) time algorithm to compute closest pair of 𝑛 points
in plane.
27
Conclusion
Homework:
1. Try to improve the running time to O( 𝑛 log 𝑛).
Hint: β€œthe code will look similar to that of MergeSort”.
2. Ponder over the data structure for orthogonal range searching.
28
How does one design an algorithm ?
If you wish to find the answer on your own,
try to solve the first assignment problem on your own.
29
Without any help from the web
Without any help from the your friends
Assignment 1
Smallest Enclosing circle
Problem definition: Given 𝒏 points in a plane,
compute the smallest radius circle that encloses all 𝒏 point.
30

More Related Content

Similar to CS345-Algorithms-II-Lecture-1-CS345-2016.pdf

Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithmsrajatmay1992
Β 
chapter 1
chapter 1chapter 1
chapter 1yatheesha
Β 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
Β 
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...Naoki Shibata
Β 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and AnalysisSayed Chhattan Shah
Β 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical MethodsESUG
Β 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm reviewchidabdu
Β 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdfpasinduneshan
Β 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdfGOWTHAMR721887
Β 
Discrete structure ch 3 short question's
Discrete structure ch 3 short question'sDiscrete structure ch 3 short question's
Discrete structure ch 3 short question'shammad463061
Β 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxssuser01e301
Β 
04 Multi-layer Feedforward Networks
04 Multi-layer Feedforward Networks04 Multi-layer Feedforward Networks
04 Multi-layer Feedforward NetworksTamer Ahmed Farrag, PhD
Β 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfAkashSingh625550
Β 
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...AmirParnianifard1
Β 
Paper Study: Melding the data decision pipeline
Paper Study: Melding the data decision pipelinePaper Study: Melding the data decision pipeline
Paper Study: Melding the data decision pipelineChenYiHuang5
Β 

Similar to CS345-Algorithms-II-Lecture-1-CS345-2016.pdf (20)

Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
Β 
chapter 1
chapter 1chapter 1
chapter 1
Β 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
Β 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
Β 
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
Β 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and Analysis
Β 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
Β 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
Β 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
Β 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
Β 
A0280115(1)
A0280115(1)A0280115(1)
A0280115(1)
Β 
Discrete structure ch 3 short question's
Discrete structure ch 3 short question'sDiscrete structure ch 3 short question's
Discrete structure ch 3 short question's
Β 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
Β 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
Β 
Cis435 week02
Cis435 week02Cis435 week02
Cis435 week02
Β 
04 Multi-layer Feedforward Networks
04 Multi-layer Feedforward Networks04 Multi-layer Feedforward Networks
04 Multi-layer Feedforward Networks
Β 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
Β 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
Β 
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Β 
Paper Study: Melding the data decision pipeline
Paper Study: Melding the data decision pipelinePaper Study: Melding the data decision pipeline
Paper Study: Melding the data decision pipeline
Β 

Recently uploaded

Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”soniya singh
Β 
εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·
εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·
εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·umasea
Β 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
Β 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
Β 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
Β 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
Β 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
Β 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
Β 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
Β 
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...gurkirankumar98700
Β 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
Β 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
Β 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
Β 
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...soniya singh
Β 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
Β 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
Β 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
Β 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
Β 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
Β 

Recently uploaded (20)

Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Call Girls in Naraina Delhi πŸ’―Call Us πŸ”8264348440πŸ”
Β 
εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·
εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·
εŠžη†ε­¦δ½θ―(UQ文凭证书)ζ˜†ε£«ε…°ε€§ε­¦ζ―•δΈšθ―ζˆη»©ε•εŽŸη‰ˆδΈ€ζ¨‘δΈ€ζ ·
Β 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
Β 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Β 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
Β 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
Β 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Β 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
Β 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
Β 
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
Β 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
Β 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
Β 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
Β 
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Β 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
Β 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
Β 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Β 
Call Girls In Mukherjee Nagar πŸ“± 9999965857 🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar πŸ“±  9999965857  🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar πŸ“±  9999965857  🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar πŸ“± 9999965857 🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Β 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Β 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
Β 

CS345-Algorithms-II-Lecture-1-CS345-2016.pdf

  • 1. Design and Analysis of Algorithms Lecture 1 β€’ Overview of the course β€’ Closest Pair problem 1 https://moodle.cse.iitk.ac.in CS345A Algorithms-II
  • 2. Aim of the course To empower each student with the skills to design algorithms β€’ With provable guarantee on correctness. β€’ With provable guarantee on their efficiency. 2
  • 3. Algorithm Paradigm Motivation: β€’ Many problems whose algorithms are based on a common approach. βž” A need of a systematic study of the characteristics of such approaches. Algorithm Paradigms: β€’ Divide and Conquer β€’ Greedy Strategy β€’ Dynamic Programming 3 (advanced) (advanced)
  • 4. Maximum Flow Given a network for transporting certain commodity (water/bits) from a designated source vertex 𝒔 and sink vertex 𝒕. Each edge has a certain capacity (max rate per unit time at which commodity can be pumped along that edge), Compute the maximum rate at which we can pump flow from 𝒔 to 𝒕. Constraints: capacity constraint and conservation constraint. 4 𝒔 𝒗 𝒖 𝒙 π’š 𝒕 2 17 5 6 8 17 4 15 16 7 14
  • 5. Miscellaneous β€’ Matching in Graphs Maximum matching, Stable matching β€’ Amortized Analysis A powerful technique to analyse time complexity of algorithms β€’ String Matching β€’ Linear Programming 5
  • 6. Last topic on Algorithms β€’ NP Complete problems β€’ Approximation/randomized Algorithms 6
  • 8. Data structures β€’ Augmented Binary Search Trees β€’ Range Minima Data structure (optimal size) β€’ Fibonacci Heap 8 : Additional information
  • 9. Orthogonal Range searching Problem: Preprocess a set of 𝒏 points so that given any query rectangle, the number of points lying inside it can be reported efficiently. Data structure: size = O(𝒏 log 𝒏), Query = O( log2 𝒏), size = O(𝒏), Query = O( 𝑛), 9 Rectangle A novel application of augmented BST Try to solve it… You can surely do itβ€¦β˜Ί Rectangle
  • 10. Divide and Conquer 10 A paradigm for Algorithm Design
  • 11. An Overview A problem in this paradigm is solved in the following way. 1. Divide the problem instance into two or more instances of the same problem. 2. Solve each smaller instance recursively (base case suitably defined). 3. Combine the solutions of the smaller instances to get the solution of the original instance. 11 This is usually the main nontrivial step in the design of an algorithm using divide and conquer strategy
  • 12. Example Problems 1. Merge Sort 2. Multiplication of two 𝒏-bit integers. 3. Counting the number of inversions in an array. 4. Median finding in linear time. 12
  • 13. PROBLEM 1 Closest Pair of Points 13
  • 14. The Closest Pair Problem 14 𝜹
  • 15. Closest Pair of Points Problem Definition: Given a set 𝑷 of 𝒏 > 𝟏 points in plane, compute the pair of points with minimum Euclidean distance. Deterministic algorithms: β€’ O(π’πŸ) : Trivial algorithm β€’ O(𝒏 π₯𝐨𝐠 𝒏) : Divide and Conquer based algorithm 15
  • 16. Hint/Tool No. 1 Exercise: What is the maximum number of points that can be placed in a unit square such that the minimum distance is at least 1 ? Answer: 4. 16 1 1 2 A discrete math exercise If there are more than 4 points, at least one of the four small squares will have more than 1 points.
  • 17. Hint/Tool No. 2 Question: For which algorithmic problems do we need a suitable data structure ? Answer: If the problem involves β€œmany” operations of same type on a given data. For example, it is worth sorting an array only if there are going to be many search queries on it. Let us see if you can use this principle in today’s class itself ☺ 17 When do we use a data structure ?
  • 19. The conquer step 19 πœΉπ‘³ πœΉπ‘Ή Compute closest pair of the left half set Compute closest pair of the right half set Notice πœΉπ‘³ < πœΉπ‘Ή for this given instance
  • 21. The combine step 21 πœΉπ‘³ πœΉπ‘Ή πœΉπ‘³ πœΉπ‘³ But there may still be Θ(𝑛2 ) pairs of points here So what to do ?
  • 22. The combine step 22 πœΉπ‘³ πœΉπ‘Ή πœΉπ‘³ πœΉπ‘³ Focus on a point 𝒑 in left strip. Where do we have to search for the points in the right strip that can form a pair with 𝒑 at distance < πœΉπ‘³ ? 𝒑
  • 24. The combine step 24 πœΉπ‘³ πœΉπ‘Ή πœΉπ‘³ πœΉπ‘³ πœΉπ‘³ πœΉπ‘³ Only the points lying in these 2 red squares are relevant as far as 𝒑 is concerned. 𝒑 How many points can there be in these 2 red squares each of lengthπœΉπ‘³? Surely not more than 8 (using Hint 1) How to find the points in these red square for point 𝒑 ? It will take O(𝒏) time for a given 𝒑. It is time to use Hint/Tool no. 2. Think for a while before going to the next slide.
  • 25. The combine step 25 πœΉπ‘³ πœΉπ‘Ή πœΉπ‘³ πœΉπ‘³ πœΉπ‘³ πœΉπ‘³ We need to find points in the 2 red square for every point in the left strip. So build a suitable data structure for points in the right strip so that we can answer such query efficiently for each point in the left strip. What will be the data structure ? An array storing the points of the right strip in increasing order of y-coordinates. πœΉπ‘³ πœΉπ‘³ πœΉπ‘³ πœΉπ‘³
  • 26. Divide and Conquer based algorithm CP-Distance(𝑃) { If (| 𝑃 |=1 ) return infinity; { Compute π‘₯-median of 𝑃; (𝑃𝐿, 𝑃𝑅)οƒŸSplit-by-π‘₯-median(𝑃); πœΉπ‘³οƒŸ CP-Distance(𝑃𝐿) ; πœΉπ‘ΉοƒŸ CP-Distance(𝑃𝑅) ; πœΉοƒŸ min(πœΉπ‘³, πœΉπ‘Ή); 𝑆𝐿 οƒŸ strip of 𝑃𝐿; 𝑆𝑅 οƒŸ strip of 𝑃𝑅; 𝐴 οƒŸ Sorted array of 𝑆𝑅; For each 𝑝 ∈ 𝑆𝐿, π’š οƒŸ y-coordinate of 𝑝; Search 𝐴 for points with y-coordinate within π’š Β± 𝜹; Compute distance from 𝑝 to each of these points; Update 𝜹 accordingly; return 𝜹; } 26 Divide step Combine/conquer step 𝑢( 𝐏 log 𝐏) time 𝑢( 𝐏 ) + 2 T(|𝐏|/2) time
  • 27. Running time of the algorithm What is the recurrence for running time? T(𝑛) = c 𝑛 log 𝑛 + 2 T(𝑛/2) βž” T(𝑛) = O( 𝑛 log2𝑛) Theorem: There exists an O( 𝑛 log2𝑛) time algorithm to compute closest pair of 𝑛 points in plane. 27
  • 28. Conclusion Homework: 1. Try to improve the running time to O( 𝑛 log 𝑛). Hint: β€œthe code will look similar to that of MergeSort”. 2. Ponder over the data structure for orthogonal range searching. 28
  • 29. How does one design an algorithm ? If you wish to find the answer on your own, try to solve the first assignment problem on your own. 29 Without any help from the web Without any help from the your friends
  • 30. Assignment 1 Smallest Enclosing circle Problem definition: Given 𝒏 points in a plane, compute the smallest radius circle that encloses all 𝒏 point. 30