SlideShare a Scribd company logo
Divide and Conquer
Pasi Fränti
2.11.2016
2
Divide and Conquer
1. Divide to sub-problems
2. Solve the sub-problems
3. Conquer the solutions
By recursion!
3
StupidExample(N)
IF N=0 THEN RETURN O(1)
ELSE
FOR i←1 TO N DO N
WRITE(‘x’); O(1)
StupidExample(N-1); T(N-1)
END;
1)1()(  NTNNT
Stupid example
    
 
      
   
          
   
   2
1
1
0
1
2
1
1
0
...
4134321
)3(321
31221
)2(21
2111
)1(1)(
NN
NN
Ni
TkiN
NTNNNNN
NTNNN
NTNNN
NTNN
NTNN
NTNNT
N
i
k
i















Analysis by substitution method
)1(1)(  NTNNT
k=N
RepeatuntilT(0)
k+…+3+2+1 → 1+2+3+…+k
Sort(A[i, j])
q  FindMin(A[i, j]);
Swap(A[i],A[q])
Sort(A[i+1, j]);
FindMin(A[i, j])
q  FindMin(A[i+1, j]);
IF A[i]<A[q] THEN RETURN i
ELSE RETURN q;
)(
)1(1)(
2
NO
NTNNT


Sorting algorithm
Recursive “through the bones”


 

otherwise
if)(
)(
a
cNedNcNTb
NT
Master Theorem
Arithmetic case
Time complexity function:
Solution:









1)(
0,1)(
0,1)(
)(
)/(
2
bbO
dbNO
dbNO
NT
cN
    
      
      cNcNcN
bbecbcNbNdcTb
bbecNbcNbNdcNTb
becNbNdcNTb
edNcNbTNT
///
223
2
...1...
12)3(
1)2(
)()(




Master Theorem
Proof for arithmetic case
Substitution:
      cNcNcN
bbecbcNbNdcTb ///
...1... 
Master Theorem
Proof for arithmetic case
Case 1: 0,1  db
a1 0   1cN
   NacNNT 
N/c terms
      cNcNcN
bbecbcNbNdcTb ///
...1... 
Master Theorem
Proof for arithmetic case
Case 2: 0,1  db
a1 cid
cN
i
1
       2
2
2
22
21 N
c
N
c
N
cNcNNT 
  1cN
Arithmetic
sum
      cNcNcN
bbecbcNbNdcTb ///
...1... 
Master Theorem
Proof for arithmetic case
Case 3: 1b
ab cN
 cN
bd 
cN
be
Dominating
term
     cNcN
bbedaNT 
Quicksort(A[i, j])
IF i < j THEN O(1)
k ← Partition(A[i, j]); O(N)
Quicksort(A[i, k]); T(N/2)
Quicksort(A[k+1, j]); T(N/2)
ELSE RETURN;
     221 NTNTNNT 
Quicksort
Partition algorithm
 Choose (any) element as pivot-value p.
 Arrange all x≤p to the left side of list.
 Arrange all x>p to the right side.
 Time complexity O(N).
7 3 112 20 136 1 10 145 8
7 3 11 2 20 13 6 1 10 14 5 8
p=7
x≤7 x>7
Partition(A[i, j])
pivot = A[j];
r = i-1;
FOR k = i TO j-1 DO
IF (A[k] ≤ pivot) THEN
r = r + 1;
SWAP(A[r], A[k]);
SWAP(A[r+1], A[j]);
RETURN r+1;
r∙∙∙ k
x≤p x>p
∙∙∙
unprocessed
FOR increases k
R increases
when needed
Partition algorithm
Selection(A[i, j], k)
IF i=j THEN
RETURN A[i];
ELSE
q ← Partition(A, i, j);
size ← (q-i)+1;
IF k ≤ size THEN Selection(A[i, q], k);
ELSE Selection(A[q+1, j], k-size);
2)
2
()(  dN
N
TNT
Selection in linear time
Find the kth smallest
edNcNTbNT  )()(
Master Theorem
Geometric case









cbNO
cbNNO
cbNO
NT
bc
)(
)log(
),(
)(
log
Time complexity function:
Solution:
Master Theorem
Proof of geometric case
   
    
   
      
        
)1(
...1
...
)1(
)1(
21
2
122
122
2









bbbe
bcbcbcbdTb
bebcbcbdcTb
becbcdcTb
eNdecNdcNTbb
edNcNTbNT
pp
ppp
pppp
ppp
Np
cN
c
p
log

Extract
psteps
Case 1: cb 
Master Theorem
Proof of geometric case
  )1(...1 12
2




























 p
p
pp
bbbe
b
c
b
c
b
c
bdTb 
Np
cN
c
p
log

Nb Nc
log
 N
N
b
dc
cc
b
d
c
b
d
b
c
bd
p
p
p
p








 

1
1
Nb Nc
log
1
11
0 




 a
a
a
nn
i
i
Geometric sum
Geometric sum
a>1
Case 2: cb 
Master Theorem
Proof of geometric case
Nb Nc
log
Nb Nc
log
Log N terms
Np
cN
c
p
log

NN log
=1
N
Geometric sum
   NNNT log
  )1(...1 12
2




























 p
p
pp
bbbe
b
c
b
c
b
c
bdTb 
Case 3: cb 
Master Theorem
Proof of geometric case
p
b
…summation…
p
bp
b
Np
cN
c
p
log

  bNp cc
NbbNT loglog

 
 
b
bN
bN
Nb
NbN
c
cc
cc
cc
ccc
N
c
c
c
cb
log
loglog
loglog
loglog
logloglog







  )1(...1 12
2




























 p
p
pp
bbbe
b
c
b
c
b
c
bdTb 
<1
MergeSort(A[i, j])
IF i<j THEN
k := (i+j)/2; O(1)
MergeSort (A[i, k]); T(N/2)
MergeSort(A[k+1, j]); T(N/2)
Merge(A[i, j], k); c∙N
Merge sort
Main algorithm
Merge(A[i, j], k)
{
l←i; m←k+1; t←i;
WHILE (l ≤ k) OR (m ≤ j)
IF l>k THEN B[t]←A[m]; m←m+1;
ELSEIF m>j THEN B[t]←A[l]; l←l+1;
ELSEIF A[l]<A[m] THEN B[t]←A[m]; m←m+1;
ELSE B[t]←A[l]; l←l+1;
t←t+1;
FOR t ← i TO j DO A[t]←B[t];
}
Merge sort
Merge step
47)2/(21)2/(2)(
)()37()(


NNTTNTNT
NONONT
merge
merge
Since we have b=c  O(N log N)
Merge sort
Time complexity
47)2/(2)(  NNTNT
)log(
49log7
247log2
)221(473)2(2
24244777)2(2
24477)4)2(7)2(2(2
24477)2(22
47)427)2(2(2
log
0
2
log
333
233
232
2
2
2
NNO
NNN
NN
NNT
NNNNT
NNNNT
NNNT
NNNT
N
i
iN









Merge sort
Substitution method
3 6 2 4
 2 3 4 5
1 8 1 2 0
1 4 4 9 6
1 0 8 7 2
7 2 4 8
8 4 9 8 2 8 0
Karatsuba-Ofman multiplication
Multiplication of two n-digit numbers
School book algorithm:
)()( 2
nOnT 
Karatsuba-Ofman multiplication
Straightforward divide-and-conquer
tvktusvksu
tvktuksvksu
vuktskyx
nn
nnn
nn



2
22
22
)(
)()(
vkuy
tksx
n
n


2
2
One n-digit number divided into two n/2-digit
numbers (most and least significant)
3624=36∙102+24
2345=23∙102+45
Multiplication reformulated:
Karatsuba-Ofman multiplication
Time complexity analysis
tvktusvksu nn
 2
)(






2
n
T 





2
n
T 





2
n
T 





2
n
T
2
n
n
     24log2
5.4
2
4 nnn
n
TnT 






n nn
Karatsuba-Ofman multiplication
Divide-and-Conquer revised
     tvktvsuvutsksu
tvktusvksu
nn
nn


2
2
)(






2
n
T 





2
n
T 





2
n
T
     58.13log2
5.7
2
3 nnn
n
TnT 






+ 6 summations and 1.5 multiplications by kn
Daa divide-n-conquer
Daa divide-n-conquer

More Related Content

What's hot

Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
mustafa sarac
 
ENFPC 2013
ENFPC 2013ENFPC 2013
ENFPC 2013
Leandro da Silva
 
Nyquist and polar plot 118 &amp; 117
Nyquist and polar plot 118 &amp; 117Nyquist and polar plot 118 &amp; 117
Nyquist and polar plot 118 &amp; 117
RishabhKashyap2
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landau
angely alcendra
 
Development of Matlab Programme to study nonlinear vibration of a cantilever ...
Development of Matlab Programme to study nonlinear vibration of a cantilever ...Development of Matlab Programme to study nonlinear vibration of a cantilever ...
Development of Matlab Programme to study nonlinear vibration of a cantilever ...
ijiert bestjournal
 
Kalman
KalmanKalman
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
A Note on TopicRNN
A Note on TopicRNNA Note on TopicRNN
A Note on TopicRNN
Tomonari Masada
 
Poisson factorization
Poisson factorizationPoisson factorization
Poisson factorization
Tomonari Masada
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrences
Ankita Karia
 
R. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical ObservationsR. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical Observations
SEENET-MTP
 
Graph Kernelpdf
Graph KernelpdfGraph Kernelpdf
Graph Kernelpdf
pratik shukla
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)
Tomonari Masada
 
discrete-hmm
discrete-hmmdiscrete-hmm
discrete-hmm
Md Pavel Mahmud
 
Operational research
Operational researchOperational research
Operational research
Albi Thomas
 
Using blurred images to assess damage in bridge structures?
Using blurred images to assess damage in bridge structures?Using blurred images to assess damage in bridge structures?
Using blurred images to assess damage in bridge structures?
Alessandro Palmeri
 
Alex1 group2
Alex1 group2Alex1 group2
Alex1 group2
Shiang-Yun Yang
 
MinFill_Presentation
MinFill_PresentationMinFill_Presentation
MinFill_Presentation
Anna Lasota
 
Merge Sort
Merge SortMerge Sort

What's hot (20)

Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
ENFPC 2013
ENFPC 2013ENFPC 2013
ENFPC 2013
 
Nyquist and polar plot 118 &amp; 117
Nyquist and polar plot 118 &amp; 117Nyquist and polar plot 118 &amp; 117
Nyquist and polar plot 118 &amp; 117
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landau
 
Development of Matlab Programme to study nonlinear vibration of a cantilever ...
Development of Matlab Programme to study nonlinear vibration of a cantilever ...Development of Matlab Programme to study nonlinear vibration of a cantilever ...
Development of Matlab Programme to study nonlinear vibration of a cantilever ...
 
Kalman
KalmanKalman
Kalman
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
A Note on TopicRNN
A Note on TopicRNNA Note on TopicRNN
A Note on TopicRNN
 
Poisson factorization
Poisson factorizationPoisson factorization
Poisson factorization
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrences
 
R. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical ObservationsR. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical Observations
 
Graph Kernelpdf
Graph KernelpdfGraph Kernelpdf
Graph Kernelpdf
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)
 
discrete-hmm
discrete-hmmdiscrete-hmm
discrete-hmm
 
Operational research
Operational researchOperational research
Operational research
 
Using blurred images to assess damage in bridge structures?
Using blurred images to assess damage in bridge structures?Using blurred images to assess damage in bridge structures?
Using blurred images to assess damage in bridge structures?
 
Alex1 group2
Alex1 group2Alex1 group2
Alex1 group2
 
MinFill_Presentation
MinFill_PresentationMinFill_Presentation
MinFill_Presentation
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 

Similar to Daa divide-n-conquer

Design and Analysis of Algorithms - Divide and Conquer
Design and Analysis of Algorithms - Divide and ConquerDesign and Analysis of Algorithms - Divide and Conquer
Design and Analysis of Algorithms - Divide and Conquer
Seshu Chakravarthy
 
lecture 3
lecture 3lecture 3
lecture 3
sajinsc
 
Recurrences
RecurrencesRecurrences
Recurrences
DEVTYPE
 
Recurrences
RecurrencesRecurrences
Recurrences
Ala' Mohammad
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Computer science-formulas
Computer science-formulasComputer science-formulas
Computer science-formulas
RAJIV GANDHI INSTITUTE OF TECHNOLOGY
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
The Statistical and Applied Mathematical Sciences Institute
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
Tareq Hasan
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
bryan111472
 
Lec10
Lec10Lec10
quick and merge.pptx
quick and merge.pptxquick and merge.pptx
quick and merge.pptx
LakshayYadav46
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
sohelranasweet
 
【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood
【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood
【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood
Deep Learning JP
 
07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer
Neeldhara Misra
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquer
Joepang2015
 
Mergesort
MergesortMergesort
Mergesort
luzenith_g
 
Introduction
IntroductionIntroduction
Introduction
pilavare
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 

Similar to Daa divide-n-conquer (20)

Design and Analysis of Algorithms - Divide and Conquer
Design and Analysis of Algorithms - Divide and ConquerDesign and Analysis of Algorithms - Divide and Conquer
Design and Analysis of Algorithms - Divide and Conquer
 
lecture 3
lecture 3lecture 3
lecture 3
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Computer science-formulas
Computer science-formulasComputer science-formulas
Computer science-formulas
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
Lec10
Lec10Lec10
Lec10
 
quick and merge.pptx
quick and merge.pptxquick and merge.pptx
quick and merge.pptx
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood
【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood
【DL輪読会】Unbiased Gradient Estimation for Marginal Log-likelihood
 
07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquer
 
Mergesort
MergesortMergesort
Mergesort
 
Introduction
IntroductionIntroduction
Introduction
 
03 dc
03 dc03 dc
03 dc
 

Recently uploaded

一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
AlvianRamadhani5
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
Dwarkadas J Sanghvi College of Engineering
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Bayesian Decision Theory details ML.pptx
Bayesian Decision Theory details ML.pptxBayesian Decision Theory details ML.pptx
Bayesian Decision Theory details ML.pptx
amrita chaturvedi
 
5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf
devtomar25
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 

Recently uploaded (20)

一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Bayesian Decision Theory details ML.pptx
Bayesian Decision Theory details ML.pptxBayesian Decision Theory details ML.pptx
Bayesian Decision Theory details ML.pptx
 
5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 

Daa divide-n-conquer

  • 1. Divide and Conquer Pasi Fränti 2.11.2016
  • 2. 2 Divide and Conquer 1. Divide to sub-problems 2. Solve the sub-problems 3. Conquer the solutions By recursion!
  • 3. 3 StupidExample(N) IF N=0 THEN RETURN O(1) ELSE FOR i←1 TO N DO N WRITE(‘x’); O(1) StupidExample(N-1); T(N-1) END; 1)1()(  NTNNT Stupid example
  • 4.                                     2 1 1 0 1 2 1 1 0 ... 4134321 )3(321 31221 )2(21 2111 )1(1)( NN NN Ni TkiN NTNNNNN NTNNN NTNNN NTNN NTNN NTNNT N i k i                Analysis by substitution method )1(1)(  NTNNT k=N RepeatuntilT(0) k+…+3+2+1 → 1+2+3+…+k
  • 5. Sort(A[i, j]) q  FindMin(A[i, j]); Swap(A[i],A[q]) Sort(A[i+1, j]); FindMin(A[i, j]) q  FindMin(A[i+1, j]); IF A[i]<A[q] THEN RETURN i ELSE RETURN q; )( )1(1)( 2 NO NTNNT   Sorting algorithm Recursive “through the bones”
  • 6.      otherwise if)( )( a cNedNcNTb NT Master Theorem Arithmetic case Time complexity function: Solution:          1)( 0,1)( 0,1)( )( )/( 2 bbO dbNO dbNO NT cN
  • 7.                   cNcNcN bbecbcNbNdcTb bbecNbcNbNdcNTb becNbNdcNTb edNcNbTNT /// 223 2 ...1... 12)3( 1)2( )()(     Master Theorem Proof for arithmetic case Substitution:
  • 8.       cNcNcN bbecbcNbNdcTb /// ...1...  Master Theorem Proof for arithmetic case Case 1: 0,1  db a1 0   1cN    NacNNT  N/c terms
  • 9.       cNcNcN bbecbcNbNdcTb /// ...1...  Master Theorem Proof for arithmetic case Case 2: 0,1  db a1 cid cN i 1        2 2 2 22 21 N c N c N cNcNNT    1cN Arithmetic sum
  • 10.       cNcNcN bbecbcNbNdcTb /// ...1...  Master Theorem Proof for arithmetic case Case 3: 1b ab cN  cN bd  cN be Dominating term      cNcN bbedaNT 
  • 11. Quicksort(A[i, j]) IF i < j THEN O(1) k ← Partition(A[i, j]); O(N) Quicksort(A[i, k]); T(N/2) Quicksort(A[k+1, j]); T(N/2) ELSE RETURN;      221 NTNTNNT  Quicksort
  • 12. Partition algorithm  Choose (any) element as pivot-value p.  Arrange all x≤p to the left side of list.  Arrange all x>p to the right side.  Time complexity O(N). 7 3 112 20 136 1 10 145 8 7 3 11 2 20 13 6 1 10 14 5 8 p=7 x≤7 x>7
  • 13. Partition(A[i, j]) pivot = A[j]; r = i-1; FOR k = i TO j-1 DO IF (A[k] ≤ pivot) THEN r = r + 1; SWAP(A[r], A[k]); SWAP(A[r+1], A[j]); RETURN r+1; r∙∙∙ k x≤p x>p ∙∙∙ unprocessed FOR increases k R increases when needed Partition algorithm
  • 14. Selection(A[i, j], k) IF i=j THEN RETURN A[i]; ELSE q ← Partition(A, i, j); size ← (q-i)+1; IF k ≤ size THEN Selection(A[i, q], k); ELSE Selection(A[q+1, j], k-size); 2) 2 ()(  dN N TNT Selection in linear time Find the kth smallest
  • 15. edNcNTbNT  )()( Master Theorem Geometric case          cbNO cbNNO cbNO NT bc )( )log( ),( )( log Time complexity function: Solution:
  • 16. Master Theorem Proof of geometric case                              )1( ...1 ... )1( )1( 21 2 122 122 2          bbbe bcbcbcbdTb bebcbcbdcTb becbcdcTb eNdecNdcNTbb edNcNTbNT pp ppp pppp ppp Np cN c p log  Extract psteps
  • 17. Case 1: cb  Master Theorem Proof of geometric case   )1(...1 12 2                              p p pp bbbe b c b c b c bdTb  Np cN c p log  Nb Nc log  N N b dc cc b d c b d b c bd p p p p            1 1 Nb Nc log 1 11 0       a a a nn i i Geometric sum Geometric sum a>1
  • 18. Case 2: cb  Master Theorem Proof of geometric case Nb Nc log Nb Nc log Log N terms Np cN c p log  NN log =1 N Geometric sum    NNNT log   )1(...1 12 2                              p p pp bbbe b c b c b c bdTb 
  • 19. Case 3: cb  Master Theorem Proof of geometric case p b …summation… p bp b Np cN c p log    bNp cc NbbNT loglog      b bN bN Nb NbN c cc cc cc ccc N c c c cb log loglog loglog loglog logloglog          )1(...1 12 2                              p p pp bbbe b c b c b c bdTb  <1
  • 20. MergeSort(A[i, j]) IF i<j THEN k := (i+j)/2; O(1) MergeSort (A[i, k]); T(N/2) MergeSort(A[k+1, j]); T(N/2) Merge(A[i, j], k); c∙N Merge sort Main algorithm
  • 21. Merge(A[i, j], k) { l←i; m←k+1; t←i; WHILE (l ≤ k) OR (m ≤ j) IF l>k THEN B[t]←A[m]; m←m+1; ELSEIF m>j THEN B[t]←A[l]; l←l+1; ELSEIF A[l]<A[m] THEN B[t]←A[m]; m←m+1; ELSE B[t]←A[l]; l←l+1; t←t+1; FOR t ← i TO j DO A[t]←B[t]; } Merge sort Merge step
  • 24. 3 6 2 4  2 3 4 5 1 8 1 2 0 1 4 4 9 6 1 0 8 7 2 7 2 4 8 8 4 9 8 2 8 0 Karatsuba-Ofman multiplication Multiplication of two n-digit numbers School book algorithm: )()( 2 nOnT 
  • 26. Karatsuba-Ofman multiplication Time complexity analysis tvktusvksu nn  2 )(       2 n T       2 n T       2 n T       2 n T 2 n n      24log2 5.4 2 4 nnn n TnT        n nn
  • 27. Karatsuba-Ofman multiplication Divide-and-Conquer revised      tvktvsuvutsksu tvktusvksu nn nn   2 2 )(       2 n T       2 n T       2 n T      58.13log2 5.7 2 3 nnn n TnT        + 6 summations and 1.5 multiplications by kn