SlideShare a Scribd company logo
Chapter 2 : Divide & Conquer
Content to be cover.
• Introduction
• Binary Search Algorithm
• Merge Sort Using Divide & Conquer
• Quick Sort Using Divide & Conquer
• Strassen’s Matrix Multiplication
Content Covered : Introduction & Binary Search Algorithm
Introduction
• This chapter introduced and explains an algorithm design technique divide & conquer.
• Applied to large size problem.
• There are basically three tasks related to divide and conquer.
(i) D and C (P) : Divide and conquer
(ii) Small (p)
(iii) Combine
Chapter 2: Divide & Conquer
D and C (Binarysearch (i, j, item))
{
if (i = = j)
{
if (A [i] = = item)
return 1;
else
return 0;
}
else
{
mid = if (item = = A [mid])
return mid;
else if (item < A [mid])
D and C (Binarysearch (i, mid – 1, item))
else if (item > A [mid])
D and C (Binarysearch (mid + 1, j, item))
return;
}
}
Complexity of Binary Search : O(log2 n)
Divide & Conquer Binary Search Algorithm
Chapter 2: Divide & Conquer
Example of Binary Search Algorithm
Content Covered : Merge Sort Algorithm using divide & conquer
Algorithm for Merge Sort using divide & conquer:
D and C Mergesort (low, high)
{
if (low < high)
{
mid = (low + high) / 2
DandCMergesort (low, mid);
DandCMergesort (mid + 1, high);
Merge (low, mid, high)
}
}
Complexity = O (n log2 n)
Chapter 2: Divide & Conquer
Algorithm for Quick Sort Using Divide & Conquer
D and C Quicksort (i, j)
{
if (i < j) then divide the sequence into two subsequence
{
q = partition (i, j)
D and C Quicksort (i, q – 1)
D and C Quicksort (q + 1, j)
}
}
• Complexity of Quick Sort : O ( n log2 n )
Partition Algorithm :
1. i = 1, j = n
2. Compare A [i] and A [j]
3. if (A [i]  A [j])
{
j = j – 1 and go to step 2;
}
4. if (A [i] > A [j])
{
Interchange A [i] and A [j] and i = i + 1;
}
5. Compare A [i] and A [j]
6. if (A [i]  A [j])
{
i = i + 1 and go to step 5;
}
7. if (A [i] > A [j])
{
Interchange A [i] and A [j] and go to step 2;
}
Content Covered : Quick Sort Algorithm using divide & conquer
Chapter 2: Divide & Conquer
Example :
2 2 4 3 1
Solution :
Given array : 2 2 4 3 1
i = 1 j = 5
Now perform according to above algorithms
D and C Quicksort (i, j) i.e. D and C Quicksort (1, 5) Here i = 1 and j = 5
Since (i < j) i.e. (1 < 5) condition satisfied.
Divide this sequence into two subsequence, i.e. q = partition (i, j) = partition (1, 5)
Use partition algorithm and find out the pivot element q.
Then one sequence is (i to q – 1) and other sequence is (q + 1 to j).
Now apply partitioning algorithm. i = 1 and j = 5
Sort following array by using Divide and Conquer Quick sort algorithm.
Content Covered : Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer
Content Covered :Strassen’s Matrix Multiplication
Chapter 2: Divide & Conquer

More Related Content

What's hot

Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.
Nagesh NARASIMHA PRASAD
 
K means clustering
K means clusteringK means clustering
K means clustering
Thomas K T
 
K-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source codeK-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source code
gokulprasath06
 
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.Andrea Angella
 
K means clustering
K means clusteringK means clustering
K means clustering
Ahmedasbasb
 
The Speed of Two Objects
The Speed of Two ObjectsThe Speed of Two Objects
The Speed of Two ObjectsAlex Lee
 
Union find
Union findUnion find
Rough K Means - Numerical Example
Rough K Means - Numerical ExampleRough K Means - Numerical Example
Rough K Means - Numerical Example
Dr.E.N.Sathishkumar
 
Fortran induction project. DGTSV DGESV
Fortran induction project. DGTSV DGESVFortran induction project. DGTSV DGESV
Fortran induction project. DGTSV DGESV
Nagesh NARASIMHA PRASAD
 
Datastructure tree
Datastructure treeDatastructure tree
Datastructure tree
rantd
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
MapR Technologies
 
Radix-3 Algorithm for Realization of Type-II Discrete Sine Transform
Radix-3 Algorithm for Realization of Type-II Discrete Sine TransformRadix-3 Algorithm for Realization of Type-II Discrete Sine Transform
Radix-3 Algorithm for Realization of Type-II Discrete Sine Transform
IJERA Editor
 
Randomized algorithms all pairs shortest path
Randomized algorithms  all pairs shortest pathRandomized algorithms  all pairs shortest path
Randomized algorithms all pairs shortest path
Mohammad Akbarizadeh
 
Reanalysis Method: Direct Method
Reanalysis Method: Direct MethodReanalysis Method: Direct Method
Reanalysis Method: Direct Method
Ashvini Kumar
 
Enhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial DatasetEnhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial Dataset
AlaaZ
 
Cs36565569
Cs36565569Cs36565569
Cs36565569
IJERA Editor
 
Control assignment#3
Control assignment#3Control assignment#3
Control assignment#3
cairo university
 
Graph Based Clustering
Graph Based ClusteringGraph Based Clustering
Graph Based Clustering
SSA KPI
 
Indefinite Integrals QA 21
Indefinite Integrals QA 21Indefinite Integrals QA 21
Indefinite Integrals QA 21
Lakshmikanta Satapathy
 
Direct split-radix algorithm for fast computation of type-II discrete Hartley...
Direct split-radix algorithm for fast computation of type-II discrete Hartley...Direct split-radix algorithm for fast computation of type-II discrete Hartley...
Direct split-radix algorithm for fast computation of type-II discrete Hartley...
TELKOMNIKA JOURNAL
 

What's hot (20)

Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.
 
K means clustering
K means clusteringK means clustering
K means clustering
 
K-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source codeK-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source code
 
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
 
K means clustering
K means clusteringK means clustering
K means clustering
 
The Speed of Two Objects
The Speed of Two ObjectsThe Speed of Two Objects
The Speed of Two Objects
 
Union find
Union findUnion find
Union find
 
Rough K Means - Numerical Example
Rough K Means - Numerical ExampleRough K Means - Numerical Example
Rough K Means - Numerical Example
 
Fortran induction project. DGTSV DGESV
Fortran induction project. DGTSV DGESVFortran induction project. DGTSV DGESV
Fortran induction project. DGTSV DGESV
 
Datastructure tree
Datastructure treeDatastructure tree
Datastructure tree
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
 
Radix-3 Algorithm for Realization of Type-II Discrete Sine Transform
Radix-3 Algorithm for Realization of Type-II Discrete Sine TransformRadix-3 Algorithm for Realization of Type-II Discrete Sine Transform
Radix-3 Algorithm for Realization of Type-II Discrete Sine Transform
 
Randomized algorithms all pairs shortest path
Randomized algorithms  all pairs shortest pathRandomized algorithms  all pairs shortest path
Randomized algorithms all pairs shortest path
 
Reanalysis Method: Direct Method
Reanalysis Method: Direct MethodReanalysis Method: Direct Method
Reanalysis Method: Direct Method
 
Enhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial DatasetEnhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial Dataset
 
Cs36565569
Cs36565569Cs36565569
Cs36565569
 
Control assignment#3
Control assignment#3Control assignment#3
Control assignment#3
 
Graph Based Clustering
Graph Based ClusteringGraph Based Clustering
Graph Based Clustering
 
Indefinite Integrals QA 21
Indefinite Integrals QA 21Indefinite Integrals QA 21
Indefinite Integrals QA 21
 
Direct split-radix algorithm for fast computation of type-II discrete Hartley...
Direct split-radix algorithm for fast computation of type-II discrete Hartley...Direct split-radix algorithm for fast computation of type-II discrete Hartley...
Direct split-radix algorithm for fast computation of type-II discrete Hartley...
 

Similar to Chapter 2 divide &amp; conquer

module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
Shiwani Gupta
 
Lecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptxLecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptx
Fazlullah28
 
Digital signature
Digital signatureDigital signature
Digital signature
Shwetang (shweacha)
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
RUHULAMINHAZARIKA
 
Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)
Shiang-Yun Yang
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingzukun
 
Practical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient ApportionmentPractical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient Apportionment
Raphael Reitzig
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Melaku Bayih Demessie
 
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdfQuicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
anupamfootwear
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
Mumtaz Ali
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
AkashSingh625550
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
kalyanineve
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
Nv Thejaswini
 
DAA Notes.pdf
DAA Notes.pdfDAA Notes.pdf
DAA Notes.pdf
SauravPawar14
 
Dynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
KrishnakoumarC
 

Similar to Chapter 2 divide &amp; conquer (20)

module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Lecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptxLecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptx
 
Digital signature
Digital signatureDigital signature
Digital signature
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
 
Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracing
 
Practical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient ApportionmentPractical and Worst-Case Efficient Apportionment
Practical and Worst-Case Efficient Apportionment
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdfQuicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
Quicksort AlgorithmQuicksort is a divide and conquer algorithm. Q.pdf
 
Cis435 week02
Cis435 week02Cis435 week02
Cis435 week02
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
 
doc
docdoc
doc
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
DAA Notes.pdf
DAA Notes.pdfDAA Notes.pdf
DAA Notes.pdf
 
Dynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
 

Recently uploaded

Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 

Recently uploaded (20)

Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 

Chapter 2 divide &amp; conquer

  • 1. Chapter 2 : Divide & Conquer Content to be cover. • Introduction • Binary Search Algorithm • Merge Sort Using Divide & Conquer • Quick Sort Using Divide & Conquer • Strassen’s Matrix Multiplication
  • 2. Content Covered : Introduction & Binary Search Algorithm Introduction • This chapter introduced and explains an algorithm design technique divide & conquer. • Applied to large size problem. • There are basically three tasks related to divide and conquer. (i) D and C (P) : Divide and conquer (ii) Small (p) (iii) Combine Chapter 2: Divide & Conquer
  • 3. D and C (Binarysearch (i, j, item)) { if (i = = j) { if (A [i] = = item) return 1; else return 0; } else { mid = if (item = = A [mid]) return mid; else if (item < A [mid]) D and C (Binarysearch (i, mid – 1, item)) else if (item > A [mid]) D and C (Binarysearch (mid + 1, j, item)) return; } } Complexity of Binary Search : O(log2 n) Divide & Conquer Binary Search Algorithm Chapter 2: Divide & Conquer
  • 4. Example of Binary Search Algorithm
  • 5. Content Covered : Merge Sort Algorithm using divide & conquer Algorithm for Merge Sort using divide & conquer: D and C Mergesort (low, high) { if (low < high) { mid = (low + high) / 2 DandCMergesort (low, mid); DandCMergesort (mid + 1, high); Merge (low, mid, high) } } Complexity = O (n log2 n) Chapter 2: Divide & Conquer
  • 6. Algorithm for Quick Sort Using Divide & Conquer D and C Quicksort (i, j) { if (i < j) then divide the sequence into two subsequence { q = partition (i, j) D and C Quicksort (i, q – 1) D and C Quicksort (q + 1, j) } } • Complexity of Quick Sort : O ( n log2 n ) Partition Algorithm : 1. i = 1, j = n 2. Compare A [i] and A [j] 3. if (A [i]  A [j]) { j = j – 1 and go to step 2; } 4. if (A [i] > A [j]) { Interchange A [i] and A [j] and i = i + 1; } 5. Compare A [i] and A [j] 6. if (A [i]  A [j]) { i = i + 1 and go to step 5; } 7. if (A [i] > A [j]) { Interchange A [i] and A [j] and go to step 2; } Content Covered : Quick Sort Algorithm using divide & conquer Chapter 2: Divide & Conquer
  • 7. Example : 2 2 4 3 1 Solution : Given array : 2 2 4 3 1 i = 1 j = 5 Now perform according to above algorithms D and C Quicksort (i, j) i.e. D and C Quicksort (1, 5) Here i = 1 and j = 5 Since (i < j) i.e. (1 < 5) condition satisfied. Divide this sequence into two subsequence, i.e. q = partition (i, j) = partition (1, 5) Use partition algorithm and find out the pivot element q. Then one sequence is (i to q – 1) and other sequence is (q + 1 to j). Now apply partitioning algorithm. i = 1 and j = 5 Sort following array by using Divide and Conquer Quick sort algorithm.
  • 8.
  • 9. Content Covered : Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 10. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 11. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 12. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 13. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 14. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 15. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer
  • 16. Content Covered :Strassen’s Matrix Multiplication Chapter 2: Divide & Conquer