SlideShare a Scribd company logo
Unit-2
Algorithms Using
Divide-and-conquer
Introduction
 Divide-and-conquer is a top-down
technique for designing algorithms
that consists of dividing the problem
into smaller sub problems hoping
that the solutions of the sub
problems are easier to find and then
composing the partial solutions into
the solution of the original problem.
Divide-and-conquer
 1. Divide: Break the problem into
sub-problems of same type.
2. Conquer: Recursively solve
these sub-problems.
3. Combine: Combine the solution
sub-problems.
Divide-and-conquer
 For Example: Assuming that each
divide step creates two sub-
problems
Divide-and-conquer
Example-2
Divide-and-conquer
 For Example: If we can divide the
problem into more than two, it
looks like this
Divide-and-conquer Detail
Divide/Break
 This step involves breaking the problem
into smaller sub-problems.
 Sub-problems should represent a part of
the original problem.
 This step generally takes a recursive
approach to divide the problem until no
sub-problem is further divisible.
 At this stage, sub-problems become
atomic in nature but still represent some
part of the actual problem.
Divide-and-conquer Detail
Conquer/Solve
 This step receives a lot of smaller sub-
problems to be solved.
 Generally, at this level, the problems are
considered 'solved' on their own.
Divide-and-conquer Detail
Merge/Combine
 When the smaller sub-problems are
solved, this stage recursively combines
them until they formulate a solution of
the original problem.
 This algorithmic approach works
recursively and conquer & merge steps
works so close that they appear as one.
Standard Algorithms
based on D & C
 The following algorithms are based on
divide-and-conquer algorithm design
paradigm.
 Merge Sort
 Quick Sort
 Binary Search
 Strassen's Matrix Multiplication
 Closest pair (points)
 Cooley–Tukey Fast Fourier Transform
(FFT) algorithm
Advantages of D & C
1. Solving difficult problems:
Divide and conquer is a powerful tool for solving
conceptually difficult problems: all it requires is a
way of breaking the problem into sub-problems,
of solving the trivial cases and of combining sub-
problems to the original problem.
2. Parallelism:
Divide and conquer algorithms are naturally
adapted for execution in multi-processor
machines, especially shared-memory systems
where the communication of data between
processors does not need to be planned in
advance, because distinct sub-problems can be
executed on different processors.
Advantages of D & C
3. Memory Access:
Divide-and-conquer algorithms naturally tend to
make efficient use of memory caches. The reason
is that once a sub-problem is small enough, it and
all its sub-problems can, in principle, be solved
within the cache, without accessing the slower
main memory.
4. Roundoff control:
In computations with rounded arithmetic, e.g.
with floating point numbers, a divide-and-conquer
algorithm may yield more accurate results than a
superficially equivalent iterative method.
Advantages of D & C
 For solving difficult problems like Tower
Of Hanoi, divide & conquer is a powerful
tool
 Results in efficient algorithms.
 Divide & Conquer algorithms are adapted
foe execution in multi-processor
machines
 Results in algorithms that use memory
cache efficiently.
Limitations of D & C
 Recursion is slow.
 Very simple problem may be more
complicated than an iterative approach.
Example: adding n numbers etc
Example of Multiplication of
N digit integers.
 Multiplication can be perform using divide
and conquer technique.
 First we know the decimal system of
number which are shown as under.
Number is 3754
3*103 + 7*102 + 5*101 + 4*100
Example of Multiplication of
N digit integers.
 2345 * 6789
2*103 + 3*102 + 4*101 + 5*100
6*103 + 7*102 + 8*101 + 9*100
4 3 2 1
Example of Multiplication of
N digit integers.
 2345 * 6789
2*103 + 3*102 + 4*101 + 5*100
6*103 + 7*102 + 8*101 + 9*100
4 3 2 1
Example of Multiplication of
N digit integers.
 2345 * 6789
2*103 + 3*102 + 4*101 + 5*100
6*103 + 7*102 + 8*101 + 9*100
4 3 2 1
Closest-Pair Problem:
Divide and Conquer
 Brute force approach requires comparing every point
with every other point
 Given n points, we must perform 1 + 2 + 3 + … + n-
2 + n-1 comparisons.
 Brute force  O(n2)
 The Divide and Conquer algorithm yields  O(n log
n)
 Reminder: if n = 1,000,000 then
 n2 = 1,000,000,000,000 whereas
 n log n = 20,000,000
2
)1(1
1
nn
k
n
k




Closest-Pair Algorithm
Given: A set of points in 2-D
Closest-Pair Algorithm
Step 1: Sort the points in one D
Lets sort based on the X-axis
O(n log n) using quicksort or mergesort
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
Step 2: Split the points, i.e.,
Draw a line at the mid-point between 7
and 8
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
Sub-Problem
1
Sub-Problem
2
Advantage: Normally, we’d have to
compare each of the 14 points with every
other point.
(n-1)n/2 = 13*14/2 = 91 comparisons
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
Sub-Problem
1
Sub-Problem
2
Advantage: Now, we have two sub-
problems of half the size. Thus, we have to
do 6*7/2 comparisons twice, which is 42
comparisons
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
d1
d2
Sub-Problem
1
Sub-Problem
2
solution d = min(d1, d2)
Advantage: With just one split we cut the
number of comparisons in half. Obviously,
we gain an even greater advantage if we
split the sub-problems.
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
d1
d2
Sub-Problem
1
Sub-Problem
2
d = min(d1, d2)
Problem: However, what if the closest two
points are each from different sub-
problems?
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
d1
d2
Sub-Problem
1
Sub-Problem
2
Here is an example where we have to
compare points from sub-problem 1 to the
points in sub-problem 2.
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
d1
d2
Sub-Problem
1
Sub-Problem
2
However, we only have to compare points
inside the following “strip.”
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
d1
d2
Sub-Problem
1
Sub-Problem
2
dd
d = min(d1, d2)
Step 3: In fact we can continue to split
until each sub-problem is trivial, i.e., takes
one comparison.
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
Finally: The solution to each sub-problem
is combined until the final solution is
obtained
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
Finally: On the last step the ‘strip’ will
likely be very small. Thus, combining the
two largest sub-problems won’t require
much work.
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3 1
4
Closest-Pair Algorithm
 In this example, it takes 22 comparisons to
find the closets-pair.
 The brute force algorithm would have taken
91 comparisons.
 But, the real advantage occurs when there are
millions of points.
Closest-Pair Algo
Float DELTA-LEFT, DELTA-RIGHT;
Float DELTA;
If n= 2 then
return distance form p(1) to p(2);
Else
P-LEFT <- (p(1),p(2),p(n/2));
P-RIGHT <- (p(n/2 + 1),p(n/2 + 2),p(n));
DELTA-LEFT <- Closest_pair(P-LEFT,n2);
DELTA-RIGHT <- Closest_pair(P-RIGHT,n2);
DELTA<- minimum(DELTA-LEFT,DELTA-RIGHT)
Closest-Pair Algo
For I in 1---s do
for j in i+1..s do
if(|x[i] – x[j] | > DELTA and
|y[i] – y[j]|> DELTA ) then
exit;
end
if(distance(q[I],q[j] <DELTA)) then
DELTA <- distance (q[i],q[j]);
end
end
Merge Sort
Closest-Pair Algo
Array a[]
Array b[]
Integer h,i,j,k;
h<- low;
i <- low;
j=<- mid + 1;
While( h<= mid and j<= high) do
if(a[h] <= a[j]) then
b[i]<- a[h]
h<-h+1
Closest-Pair Algo
Else
b[i]<- a[j]
j<- j+1;
end
i<- i+1;
End
If(h>mid) then
for(k<-j to high) do
b[i] <- a[k];
i<-i+1;
Closest-Pair Algo
Else
for(k<- to mid) do
b[i] <- a[k]
i=i+1;
End
For(k<-low to high)
a[k]<- b[k]
end
Timing Analysis
 D&C algorithm running time in
mainly affected by 3 factors
 The number of sub-instance(α)
into which a problem is split.
 The ratio of initial problem size to
sub problem size(ß)
 The number of steps required to
divide the initial instance and to
combine sub-solutions expressed
as a function of the input size n.
Timing Analysis
 P is D & C Where α sub instance each of
size n/ß
 Let Tp(n) donete the number of steps
taken by P on instances of size n.
Tp(n0) = constant (recursive-base);
Tp(n)= αTp (n/ß)+y(n);
α is number
of sub
instance
ß is number
of sub size
y is constant

More Related Content

What's hot

The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
Coin Change Problem
Coin Change ProblemCoin Change Problem
Coin Change Problem
DEVTYPE
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
Fenil Shah
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)
Ridhima Chowdhury
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
sandeep54552
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Fractional knapsack class 13
Fractional knapsack class 13Fractional knapsack class 13
Fractional knapsack class 13Kumar
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Amrinder Arora
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)CLOSEST PAIR (Final)
CLOSEST PAIR (Final)Aruneel Das
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
NagajothiN1
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
Dr Sandeep Kumar Poonia
 

What's hot (20)

The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Coin Change Problem
Coin Change ProblemCoin Change Problem
Coin Change Problem
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Fractional knapsack class 13
Fractional knapsack class 13Fractional knapsack class 13
Fractional knapsack class 13
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)CLOSEST PAIR (Final)
CLOSEST PAIR (Final)
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 

Similar to Algorithm Using Divide And Conquer

Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
Ashwin Shiv
 
Shor's discrete logarithm quantum algorithm for elliptic curves
 Shor's discrete logarithm quantum algorithm for elliptic curves Shor's discrete logarithm quantum algorithm for elliptic curves
Shor's discrete logarithm quantum algorithm for elliptic curves
XequeMateShannon
 
Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case Study
KushagraChadha1
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
B.Kirron Reddi
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
jinalgoti
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
GOWTHAMR721887
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
Pramit Kumar
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx
3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx
3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx
Agoyi1
 
Divide and Conquer Approach.pptx
Divide and Conquer Approach.pptxDivide and Conquer Approach.pptx
Divide and Conquer Approach.pptx
MuktarulHoque1
 
smu msc it 2 sem spring 2018 july/aug 2018 exam solved assignment
smu msc it  2 sem spring 2018 july/aug 2018 exam solved assignment smu msc it  2 sem spring 2018 july/aug 2018 exam solved assignment
smu msc it 2 sem spring 2018 july/aug 2018 exam solved assignment
Rahul Saini
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
 
Chapter 6-INTEGER PROGRAMMING note.pdf
Chapter 6-INTEGER PROGRAMMING  note.pdfChapter 6-INTEGER PROGRAMMING  note.pdf
Chapter 6-INTEGER PROGRAMMING note.pdf
Tsegay Berhe
 
Unit i
Unit iUnit i
Unit i
guna287176
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
B.Kirron Reddi
 
Unit 2
Unit 2Unit 2
Unit 2
guna287176
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
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
 

Similar to Algorithm Using Divide And Conquer (20)

Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
 
Shor's discrete logarithm quantum algorithm for elliptic curves
 Shor's discrete logarithm quantum algorithm for elliptic curves Shor's discrete logarithm quantum algorithm for elliptic curves
Shor's discrete logarithm quantum algorithm for elliptic curves
 
Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case Study
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
 
3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx
3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx
3. CPT121 - Introduction to Problem Solving - Module 1 - Unit 3.pptx
 
Divide and Conquer Approach.pptx
Divide and Conquer Approach.pptxDivide and Conquer Approach.pptx
Divide and Conquer Approach.pptx
 
smu msc it 2 sem spring 2018 july/aug 2018 exam solved assignment
smu msc it  2 sem spring 2018 july/aug 2018 exam solved assignment smu msc it  2 sem spring 2018 july/aug 2018 exam solved assignment
smu msc it 2 sem spring 2018 july/aug 2018 exam solved assignment
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
Unit i
Unit iUnit i
Unit i
 
Chapter 6-INTEGER PROGRAMMING note.pdf
Chapter 6-INTEGER PROGRAMMING  note.pdfChapter 6-INTEGER PROGRAMMING  note.pdf
Chapter 6-INTEGER PROGRAMMING note.pdf
 
Unit i
Unit iUnit i
Unit i
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 
Unit 2
Unit 2Unit 2
Unit 2
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
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
 

Recently uploaded

Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project PresentationPredicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Boston Institute of Analytics
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
ewymefz
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Subhajit Sahu
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
balafet
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
nscud
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 

Recently uploaded (20)

Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project PresentationPredicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 

Algorithm Using Divide And Conquer

  • 2. Introduction  Divide-and-conquer is a top-down technique for designing algorithms that consists of dividing the problem into smaller sub problems hoping that the solutions of the sub problems are easier to find and then composing the partial solutions into the solution of the original problem.
  • 3. Divide-and-conquer  1. Divide: Break the problem into sub-problems of same type. 2. Conquer: Recursively solve these sub-problems. 3. Combine: Combine the solution sub-problems.
  • 4. Divide-and-conquer  For Example: Assuming that each divide step creates two sub- problems
  • 6. Divide-and-conquer  For Example: If we can divide the problem into more than two, it looks like this
  • 7.
  • 8. Divide-and-conquer Detail Divide/Break  This step involves breaking the problem into smaller sub-problems.  Sub-problems should represent a part of the original problem.  This step generally takes a recursive approach to divide the problem until no sub-problem is further divisible.  At this stage, sub-problems become atomic in nature but still represent some part of the actual problem.
  • 9. Divide-and-conquer Detail Conquer/Solve  This step receives a lot of smaller sub- problems to be solved.  Generally, at this level, the problems are considered 'solved' on their own.
  • 10. Divide-and-conquer Detail Merge/Combine  When the smaller sub-problems are solved, this stage recursively combines them until they formulate a solution of the original problem.  This algorithmic approach works recursively and conquer & merge steps works so close that they appear as one.
  • 11. Standard Algorithms based on D & C  The following algorithms are based on divide-and-conquer algorithm design paradigm.  Merge Sort  Quick Sort  Binary Search  Strassen's Matrix Multiplication  Closest pair (points)  Cooley–Tukey Fast Fourier Transform (FFT) algorithm
  • 12. Advantages of D & C 1. Solving difficult problems: Divide and conquer is a powerful tool for solving conceptually difficult problems: all it requires is a way of breaking the problem into sub-problems, of solving the trivial cases and of combining sub- problems to the original problem. 2. Parallelism: Divide and conquer algorithms are naturally adapted for execution in multi-processor machines, especially shared-memory systems where the communication of data between processors does not need to be planned in advance, because distinct sub-problems can be executed on different processors.
  • 13. Advantages of D & C 3. Memory Access: Divide-and-conquer algorithms naturally tend to make efficient use of memory caches. The reason is that once a sub-problem is small enough, it and all its sub-problems can, in principle, be solved within the cache, without accessing the slower main memory. 4. Roundoff control: In computations with rounded arithmetic, e.g. with floating point numbers, a divide-and-conquer algorithm may yield more accurate results than a superficially equivalent iterative method.
  • 14. Advantages of D & C  For solving difficult problems like Tower Of Hanoi, divide & conquer is a powerful tool  Results in efficient algorithms.  Divide & Conquer algorithms are adapted foe execution in multi-processor machines  Results in algorithms that use memory cache efficiently.
  • 15. Limitations of D & C  Recursion is slow.  Very simple problem may be more complicated than an iterative approach. Example: adding n numbers etc
  • 16. Example of Multiplication of N digit integers.  Multiplication can be perform using divide and conquer technique.  First we know the decimal system of number which are shown as under. Number is 3754 3*103 + 7*102 + 5*101 + 4*100
  • 17. Example of Multiplication of N digit integers.  2345 * 6789 2*103 + 3*102 + 4*101 + 5*100 6*103 + 7*102 + 8*101 + 9*100 4 3 2 1
  • 18. Example of Multiplication of N digit integers.  2345 * 6789 2*103 + 3*102 + 4*101 + 5*100 6*103 + 7*102 + 8*101 + 9*100 4 3 2 1
  • 19. Example of Multiplication of N digit integers.  2345 * 6789 2*103 + 3*102 + 4*101 + 5*100 6*103 + 7*102 + 8*101 + 9*100 4 3 2 1
  • 20. Closest-Pair Problem: Divide and Conquer  Brute force approach requires comparing every point with every other point  Given n points, we must perform 1 + 2 + 3 + … + n- 2 + n-1 comparisons.  Brute force  O(n2)  The Divide and Conquer algorithm yields  O(n log n)  Reminder: if n = 1,000,000 then  n2 = 1,000,000,000,000 whereas  n log n = 20,000,000 2 )1(1 1 nn k n k    
  • 21. Closest-Pair Algorithm Given: A set of points in 2-D
  • 22. Closest-Pair Algorithm Step 1: Sort the points in one D
  • 23. Lets sort based on the X-axis O(n log n) using quicksort or mergesort 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm
  • 24. Step 2: Split the points, i.e., Draw a line at the mid-point between 7 and 8 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm Sub-Problem 1 Sub-Problem 2
  • 25. Advantage: Normally, we’d have to compare each of the 14 points with every other point. (n-1)n/2 = 13*14/2 = 91 comparisons 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm Sub-Problem 1 Sub-Problem 2
  • 26. Advantage: Now, we have two sub- problems of half the size. Thus, we have to do 6*7/2 comparisons twice, which is 42 comparisons 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm d1 d2 Sub-Problem 1 Sub-Problem 2 solution d = min(d1, d2)
  • 27. Advantage: With just one split we cut the number of comparisons in half. Obviously, we gain an even greater advantage if we split the sub-problems. 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm d1 d2 Sub-Problem 1 Sub-Problem 2 d = min(d1, d2)
  • 28. Problem: However, what if the closest two points are each from different sub- problems? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm d1 d2 Sub-Problem 1 Sub-Problem 2
  • 29. Here is an example where we have to compare points from sub-problem 1 to the points in sub-problem 2. 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm d1 d2 Sub-Problem 1 Sub-Problem 2
  • 30. However, we only have to compare points inside the following “strip.” 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm d1 d2 Sub-Problem 1 Sub-Problem 2 dd d = min(d1, d2)
  • 31. Step 3: In fact we can continue to split until each sub-problem is trivial, i.e., takes one comparison. 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm
  • 32. Finally: The solution to each sub-problem is combined until the final solution is obtained 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm
  • 33. Finally: On the last step the ‘strip’ will likely be very small. Thus, combining the two largest sub-problems won’t require much work. 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm
  • 34. 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 Closest-Pair Algorithm  In this example, it takes 22 comparisons to find the closets-pair.  The brute force algorithm would have taken 91 comparisons.  But, the real advantage occurs when there are millions of points.
  • 35. Closest-Pair Algo Float DELTA-LEFT, DELTA-RIGHT; Float DELTA; If n= 2 then return distance form p(1) to p(2); Else P-LEFT <- (p(1),p(2),p(n/2)); P-RIGHT <- (p(n/2 + 1),p(n/2 + 2),p(n)); DELTA-LEFT <- Closest_pair(P-LEFT,n2); DELTA-RIGHT <- Closest_pair(P-RIGHT,n2); DELTA<- minimum(DELTA-LEFT,DELTA-RIGHT)
  • 36. Closest-Pair Algo For I in 1---s do for j in i+1..s do if(|x[i] – x[j] | > DELTA and |y[i] – y[j]|> DELTA ) then exit; end if(distance(q[I],q[j] <DELTA)) then DELTA <- distance (q[i],q[j]); end end
  • 38. Closest-Pair Algo Array a[] Array b[] Integer h,i,j,k; h<- low; i <- low; j=<- mid + 1; While( h<= mid and j<= high) do if(a[h] <= a[j]) then b[i]<- a[h] h<-h+1
  • 39. Closest-Pair Algo Else b[i]<- a[j] j<- j+1; end i<- i+1; End If(h>mid) then for(k<-j to high) do b[i] <- a[k]; i<-i+1;
  • 40. Closest-Pair Algo Else for(k<- to mid) do b[i] <- a[k] i=i+1; End For(k<-low to high) a[k]<- b[k] end
  • 41. Timing Analysis  D&C algorithm running time in mainly affected by 3 factors  The number of sub-instance(α) into which a problem is split.  The ratio of initial problem size to sub problem size(ß)  The number of steps required to divide the initial instance and to combine sub-solutions expressed as a function of the input size n.
  • 42. Timing Analysis  P is D & C Where α sub instance each of size n/ß  Let Tp(n) donete the number of steps taken by P on instances of size n. Tp(n0) = constant (recursive-base); Tp(n)= αTp (n/ß)+y(n); α is number of sub instance ß is number of sub size y is constant