SlideShare a Scribd company logo
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
Ad

More Related Content

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

Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/kAlg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
227567
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
Geoffrey Fox
 
Computer Science Exam Help
Computer Science Exam Help Computer Science Exam Help
Computer Science Exam Help
Programming Exam Help
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
chidabdu
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
Muhammad Kashif
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
rajatmay1992
 
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
 
Design and Analysis of Algorithm in Compter Science.pptx
Design and  Analysis of Algorithm in Compter Science.pptxDesign and  Analysis of Algorithm in Compter Science.pptx
Design and Analysis of Algorithm in Compter Science.pptx
rahulshawit2023
 
BCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdfBCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
PrabhakarSingh646829
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
chidabdu
 
IntroductionToAlgo_v1_1709293290768 (2).pptx
IntroductionToAlgo_v1_1709293290768 (2).pptxIntroductionToAlgo_v1_1709293290768 (2).pptx
IntroductionToAlgo_v1_1709293290768 (2).pptx
prasanna220904
 
(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
 
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
daa_unit THIS IS GNDFJG SDGSGS SFDF .pptdaa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
DrKBManwade
 
Strassen's Matrix Multiplication divide and conquere algorithm
Strassen's Matrix Multiplication divide and conquere algorithmStrassen's Matrix Multiplication divide and conquere algorithm
Strassen's Matrix Multiplication divide and conquere algorithm
Ahmad177077
 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and Analysis
Sayed Chhattan Shah
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
ESUG
 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
chidabdu
 
Introduction to Design and Analysis of Algorithms
Introduction to Design and Analysis of AlgorithmsIntroduction to Design and Analysis of Algorithms
Introduction to Design and Analysis of Algorithms
ssusered62011
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/kAlg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
227567
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
Geoffrey Fox
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
chidabdu
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
rajatmay1992
 
Design and Analysis of Algorithm in Compter Science.pptx
Design and  Analysis of Algorithm in Compter Science.pptxDesign and  Analysis of Algorithm in Compter Science.pptx
Design and Analysis of Algorithm in Compter Science.pptx
rahulshawit2023
 
BCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdfBCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
chidabdu
 
IntroductionToAlgo_v1_1709293290768 (2).pptx
IntroductionToAlgo_v1_1709293290768 (2).pptxIntroductionToAlgo_v1_1709293290768 (2).pptx
IntroductionToAlgo_v1_1709293290768 (2).pptx
prasanna220904
 
(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
 
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
daa_unit THIS IS GNDFJG SDGSGS SFDF .pptdaa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
DrKBManwade
 
Strassen's Matrix Multiplication divide and conquere algorithm
Strassen's Matrix Multiplication divide and conquere algorithmStrassen's Matrix Multiplication divide and conquere algorithm
Strassen's Matrix Multiplication divide and conquere algorithm
Ahmad177077
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
ESUG
 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
chidabdu
 
Introduction to Design and Analysis of Algorithms
Introduction to Design and Analysis of AlgorithmsIntroduction to Design and Analysis of Algorithms
Introduction to Design and Analysis of Algorithms
ssusered62011
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 

Recently uploaded (20)

Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025
Web Designer
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025
Web Designer
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Ad

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
  • 20. The combine step 20 𝜹𝑳 𝜹𝑹 𝜹𝑳 𝜹𝑳 Which points do we need to focus on for the closest pairs ?
  • 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
  翻译: