SlideShare a Scribd company logo
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
DEPARTMENT OF INFORMATION TECHNOLOGY
 NAME: Rahul Kumar Shaw
 UNIVERSITY ROLL NUMBER: 14200223041
 SUBJECT: Design and Analysis of
Algorithms (PCC-CS404)
 DEPARTMENT: INFORMATION
TECHNOLOGY(IT)
 YEAR:2nd
 SEMESTER:4th
PPT (CA1)
ON
Divide & Conquer Algorithms
MAKAUT EVEN SEMESTER 2025
Definition
– Recursion lends itself to a general problem-solving
technique (algorithm design) called divide & conquer
• Divide the problem into 1 or more similar sub-problems
• Conquer each sub-problem, usually using a recursive call
• Combine the results from each sub-problem to form a
solution to the original problem
– Algorithmic Pattern:
DC( problem )
solution = 
if ( problem is small enough )
solution = problem.solve()
else
children = problem.divide()
for each c in children
solution = solution + c.solve()
return solution
Divide
Conquer
Combine
Applicability
– Use the divide-and-conquer algorithmic pattern when ALL of the following are
true:
• The problem lends itself to division into sub-problems of the same type
• The sub-problems are relatively independent of one another (ie, no overlap in effort)
• An acceptable solution to the problem can be constructed from acceptable solutions to
sub-problems
Well-Known Uses
– Searching
• Binary search
– Sorting
• Merge Sort
• Quick Sort
– Mathematics
• Polynomial and matrix
multiplication
• Exponentiation
• Large integer manipulation
– Points
• Closest Pair
• Merge Hull
• Quick Hull
When to avoid Divide-and-Conquer?
1. An instance of size n is divided into 2 or
more instances each almost of size n
2. An instance of size n is divided into almost
n instance of size n/c, where c is a constant
3. When smaller instances are related
MergeSort
Sort a collection of n items into increasing order
mergeSort(A) {
if(A.size() <= 1)
return A;
else {
left = A.subList(0, A.size()/2);
right = A.subList(A.size()/2, A.size());
sLeft = mergeSort(left);
sRight = mergeSort(right);
newA = merge(sLeft, sRight);
return newA;
}
QuickSort
Sort a collection of n items into increasing order
– Algorithm steps:
• Break the list into 2 pieces based on a pivot
– The pivot is usually the first item in the list
• All items smaller than the pivot go in the left and all items larger go in the right
• Sort each piece (recursion again)
• Combine the results together
To Develop a Divide & Conquer Algorithm
1. Determine how to obtain the solution to an instance from the solution to one or more smaller
instances
2. Determine the terminal conditions that the smaller instances are approaching
3. Determine the solution in the case of the terminal conditions
Binary Search
Find the location of an element in a sorted collection of n items (assuming it exists)
binarySearch( A, low, high, target )
mid = (high + low) / 2
if ( A[mid] == target )
return mid
else if ( A[mid] < target )
return binarySearch(A, mid+1, high, target)
else
return binarySearch(A, low, mid-1, target)
Matrix Multiplication
1x2 + 2x5 + 3x8 = 2 + 10 + 24 = 36
1 2 3
4 5 6
1 2 3
4 5 6
7 8 9
30 36 42
66 81 96
• rows from the first matrix
• columns from the second matrix
Matrix Multiplication
– “inner” dimensions must match
– result is “outer” dimension
– Examples:
• 2  3 X 3  3 = 2x3
• 3  4 X 4  5 = 3x5
• 2  3 X 4  3 = cannot multiply
Matrix Multiplication - Iterative
public static Matrix mult(Matrix m1, Matrix m2) {
Matrix result = new Matrix();
for (int i=0; i<m1.numRow(); i++) {
for (int j=0; j<m2.numCol(); j++) {
double total = 0.0;
for (int k=0; k<m1.numCol(); k++) {
total +=
(m1.m[i][k]*m2.m[k][j]);
}
result.m[i][j] = total;
}
}
return result;
}
Matrix Multiplication
Divide & Conquer:
– Easy to break into subproblems
– Multiplication can be performed blockwise
X × Y =
– Divide & Conquer steps…
– Divide each matrix into 4 blocks
– Recursively compute each multiplication
– Combine multiplications with a few additions and
assemble final matrix
– Run-time?
A B
×
E F
=
AE + BG AF + BH
C D G H CE + DG DF + DH
Closest-Pair Problem
Find the closest pair of points in a collection of n points in
a given plane (use Euclidean distance)
• Assume n = 2k
• If n = 2, answer is distance between these two points
• Otherwise,
– sort points by x-coordinate
– split sorted points into two piles of equal size (i.e., divide
by vertical line l)
• Three possibilities: closest pair is
– in Left side
– in Right side
– between Left and Right side
Application: Closest pair of airplanes
at a given altitude.
Closest-Pair Problem
• Closest pair is between Left and Right?
– Let d = min(LeftMin, RightMin)
– need to see if there are points in Left and Right that are closer
than d
– only need to check points within 2d of l
– sort points by y-coordinate
– can only be eight points in the 2d x d slice
Convex Hull
QuickHull Algorithm:
• This is actually a half-space hull finder
– You start with the leftmost (A) and rightmost (B) points
and all the points above them
– It finds the half hull to the top side
• One can then find the entire hull by running the same
algorithm on the bottom points
Applications:
• collision avoidance in
robotics;
• mapping the surface of an
object (like an asteroid);
• analyzing images of soil
particles;
• estimating percentage of
lung volume occupied by
pneumonia
Convex Hull
QuickHull Algorithm:
• Pick the point C that is furthest from the line AB
• Form two lines – AC and CB and place all points above
AC into one list and all points above CB into another list.
Ignore the inner
points
Convex Hull
QuickHull Algorithm:
• Recursively conquer each list of points.
• Return the line AB for each eventual
empty list of points
• Combine resulting AB lines into
polygon
Convex Hull
MergeHull Algorithm:
• This convex hull algorithm is similar to Merge Sort
(obviously given the name!)
• To make the algorithm as fast as possible we first need to
sort the points from left to right (based on x-coordinate)
• After that we apply a divide-and-conquer technique
Conclusion
Divide & Conquer is a fundamental algorithmic paradigm
that breaks complex problems into smaller, manageable
subproblems, solves them recursively, and combines their
solutions for the final result. It forms the backbone of many
efficient algorithms like Merge Sort, Quick Sort, and
Binary Search, offering enhanced performance and
modularity. Despite its potential challenges, such as
recursion overhead and unbalanced divisions, Divide &
Conquer remains an essential strategy in computer science,
powering various real-world applications from data
processing to numerical simulations.
Reference
•ONLINE RESOUCES:
•https://www.geeksforgeeks.org/introduction-to-divide-and-conqu
er-algorithm/
•https://en.wikipedia.org/wiki/Divide-and-conquer_algorithm
•https://www.programiz.com/dsa/divide-and-conquer
•https://www.khanacademy.org/computing/computer-science/
algorithms/merge-sort/a/divide-and-conquer-algorithms
/difference-between-array-and-linked-list-in-data-structure

More Related Content

PPTX
Divide and Conquer / Greedy Techniques
PPTX
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
PPTX
Lecture -16-merge sort (slides).pptx
PPTX
Are there trends, changes in the mi.pptx
PPT
Design and Analysis of algorithms unit 1 notes
PDF
Computer algorithm(Dynamic Programming).pdf
PPTX
algorithm cs3401 ppt unit 3 - cover all topics
DOCX
Data analysis and algorithm analysis presentation
Divide and Conquer / Greedy Techniques
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
Lecture -16-merge sort (slides).pptx
Are there trends, changes in the mi.pptx
Design and Analysis of algorithms unit 1 notes
Computer algorithm(Dynamic Programming).pdf
algorithm cs3401 ppt unit 3 - cover all topics
Data analysis and algorithm analysis presentation

Similar to Design and Analysis of Algorithm in Compter Science.pptx (20)

DOCX
AD3351 DAA ANSWER KEY question and answer .docx
PDF
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
PPTX
Data analysis and algorithms - UNIT 2.pptx
PPT
Uta005 lecture3
PPTX
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
PPTX
data structure and algorithm Array.pptx btech 2nd year
PPTX
RECURSION.pptx
PPTX
Introduction to data structures and complexity.pptx
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
PPTX
Algorithm in computer science
PPTX
Introduction to MATLAB Programming for Engineers
DOC
algorithm Unit 2
DOC
Unit 2 in daa
PPT
Matrix Multiplication(An example of concurrent programming)
PPT
Introduction to MATLAB
PPTX
Matlab-1.pptx
PPT
Design and Analysis of Algorithm Brute Force 1.ppt
PPTX
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
PPTX
Divide and Conquer
PPTX
Daa unit 2
AD3351 DAA ANSWER KEY question and answer .docx
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
Data analysis and algorithms - UNIT 2.pptx
Uta005 lecture3
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
data structure and algorithm Array.pptx btech 2nd year
RECURSION.pptx
Introduction to data structures and complexity.pptx
Book.pdf01_Intro.ppt algorithm for preperation stu used
Algorithm in computer science
Introduction to MATLAB Programming for Engineers
algorithm Unit 2
Unit 2 in daa
Matrix Multiplication(An example of concurrent programming)
Introduction to MATLAB
Matlab-1.pptx
Design and Analysis of Algorithm Brute Force 1.ppt
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
Divide and Conquer
Daa unit 2
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
English Language Teaching from Post-.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
From loneliness to social connection charting
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
Insiders guide to clinical Medicine.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Module 3: Health Systems Tutorial Slides S2 2025
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Open folder Downloads.pdf yes yes ges yes
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Anesthesia in Laparoscopic Surgery in India
English Language Teaching from Post-.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
human mycosis Human fungal infections are called human mycosis..pptx
From loneliness to social connection charting
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Revamp in MTO Odoo 18 Inventory - Odoo Slides
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharma ospi slides which help in ospi learning
Ad

Design and Analysis of Algorithm in Compter Science.pptx

  • 1. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. DEPARTMENT OF INFORMATION TECHNOLOGY  NAME: Rahul Kumar Shaw  UNIVERSITY ROLL NUMBER: 14200223041  SUBJECT: Design and Analysis of Algorithms (PCC-CS404)  DEPARTMENT: INFORMATION TECHNOLOGY(IT)  YEAR:2nd  SEMESTER:4th PPT (CA1) ON Divide & Conquer Algorithms MAKAUT EVEN SEMESTER 2025
  • 2. Definition – Recursion lends itself to a general problem-solving technique (algorithm design) called divide & conquer • Divide the problem into 1 or more similar sub-problems • Conquer each sub-problem, usually using a recursive call • Combine the results from each sub-problem to form a solution to the original problem – Algorithmic Pattern: DC( problem ) solution =  if ( problem is small enough ) solution = problem.solve() else children = problem.divide() for each c in children solution = solution + c.solve() return solution Divide Conquer Combine
  • 3. Applicability – Use the divide-and-conquer algorithmic pattern when ALL of the following are true: • The problem lends itself to division into sub-problems of the same type • The sub-problems are relatively independent of one another (ie, no overlap in effort) • An acceptable solution to the problem can be constructed from acceptable solutions to sub-problems Well-Known Uses – Searching • Binary search – Sorting • Merge Sort • Quick Sort – Mathematics • Polynomial and matrix multiplication • Exponentiation • Large integer manipulation – Points • Closest Pair • Merge Hull • Quick Hull When to avoid Divide-and-Conquer? 1. An instance of size n is divided into 2 or more instances each almost of size n 2. An instance of size n is divided into almost n instance of size n/c, where c is a constant 3. When smaller instances are related
  • 4. MergeSort Sort a collection of n items into increasing order mergeSort(A) { if(A.size() <= 1) return A; else { left = A.subList(0, A.size()/2); right = A.subList(A.size()/2, A.size()); sLeft = mergeSort(left); sRight = mergeSort(right); newA = merge(sLeft, sRight); return newA; }
  • 5. QuickSort Sort a collection of n items into increasing order – Algorithm steps: • Break the list into 2 pieces based on a pivot – The pivot is usually the first item in the list • All items smaller than the pivot go in the left and all items larger go in the right • Sort each piece (recursion again) • Combine the results together
  • 6. To Develop a Divide & Conquer Algorithm 1. Determine how to obtain the solution to an instance from the solution to one or more smaller instances 2. Determine the terminal conditions that the smaller instances are approaching 3. Determine the solution in the case of the terminal conditions Binary Search Find the location of an element in a sorted collection of n items (assuming it exists) binarySearch( A, low, high, target ) mid = (high + low) / 2 if ( A[mid] == target ) return mid else if ( A[mid] < target ) return binarySearch(A, mid+1, high, target) else return binarySearch(A, low, mid-1, target)
  • 7. Matrix Multiplication 1x2 + 2x5 + 3x8 = 2 + 10 + 24 = 36 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 30 36 42 66 81 96 • rows from the first matrix • columns from the second matrix
  • 8. Matrix Multiplication – “inner” dimensions must match – result is “outer” dimension – Examples: • 2  3 X 3  3 = 2x3 • 3  4 X 4  5 = 3x5 • 2  3 X 4  3 = cannot multiply Matrix Multiplication - Iterative public static Matrix mult(Matrix m1, Matrix m2) { Matrix result = new Matrix(); for (int i=0; i<m1.numRow(); i++) { for (int j=0; j<m2.numCol(); j++) { double total = 0.0; for (int k=0; k<m1.numCol(); k++) { total += (m1.m[i][k]*m2.m[k][j]); } result.m[i][j] = total; } } return result; }
  • 9. Matrix Multiplication Divide & Conquer: – Easy to break into subproblems – Multiplication can be performed blockwise X × Y = – Divide & Conquer steps… – Divide each matrix into 4 blocks – Recursively compute each multiplication – Combine multiplications with a few additions and assemble final matrix – Run-time? A B × E F = AE + BG AF + BH C D G H CE + DG DF + DH
  • 10. Closest-Pair Problem Find the closest pair of points in a collection of n points in a given plane (use Euclidean distance) • Assume n = 2k • If n = 2, answer is distance between these two points • Otherwise, – sort points by x-coordinate – split sorted points into two piles of equal size (i.e., divide by vertical line l) • Three possibilities: closest pair is – in Left side – in Right side – between Left and Right side Application: Closest pair of airplanes at a given altitude.
  • 11. Closest-Pair Problem • Closest pair is between Left and Right? – Let d = min(LeftMin, RightMin) – need to see if there are points in Left and Right that are closer than d – only need to check points within 2d of l – sort points by y-coordinate – can only be eight points in the 2d x d slice
  • 12. Convex Hull QuickHull Algorithm: • This is actually a half-space hull finder – You start with the leftmost (A) and rightmost (B) points and all the points above them – It finds the half hull to the top side • One can then find the entire hull by running the same algorithm on the bottom points Applications: • collision avoidance in robotics; • mapping the surface of an object (like an asteroid); • analyzing images of soil particles; • estimating percentage of lung volume occupied by pneumonia
  • 13. Convex Hull QuickHull Algorithm: • Pick the point C that is furthest from the line AB • Form two lines – AC and CB and place all points above AC into one list and all points above CB into another list. Ignore the inner points Convex Hull QuickHull Algorithm: • Recursively conquer each list of points. • Return the line AB for each eventual empty list of points • Combine resulting AB lines into polygon Convex Hull MergeHull Algorithm: • This convex hull algorithm is similar to Merge Sort (obviously given the name!) • To make the algorithm as fast as possible we first need to sort the points from left to right (based on x-coordinate) • After that we apply a divide-and-conquer technique
  • 14. Conclusion Divide & Conquer is a fundamental algorithmic paradigm that breaks complex problems into smaller, manageable subproblems, solves them recursively, and combines their solutions for the final result. It forms the backbone of many efficient algorithms like Merge Sort, Quick Sort, and Binary Search, offering enhanced performance and modularity. Despite its potential challenges, such as recursion overhead and unbalanced divisions, Divide & Conquer remains an essential strategy in computer science, powering various real-world applications from data processing to numerical simulations.