SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
DIVIDE & CONQUER
ALGORITHMS
Shashikant V. Athawale
Assistant Professor ,Computer Engineering Department
AISSMS College of Engineering,
Kennedy Road, Pune , MS, India - 411001
1
DIVIDE & CONQUER
The most well known algorithm design strategy:
1. Divide the problem into two or more smaller
subproblems.
2. Conquer the subproblems by solving them
recursively.
3. Combine the solutions to the subproblems into
the solutions for the original problem.
2
THE DIVIDE AND CONQUER
ALGORITHM
Divide_Conquer(problem P)
{
if Small(P) return S(P);
else {
divide P into smaller instances P1, P2, …,
Pk, k≥1;
Apply Divide_Conquer to each of these
subproblems;
return Combine(Divide_Conque(P1),
Divide_Conque(P2),…, Divide_Conque(Pk));
}
} 3
DIVIDE AND CONQUER EXAMPLES
 Merge sort
 Quick sort
 Binary Search
4
MERGE SORT
 The merge sort algorithm works from “the
bottom up”
 start by solving the smallest pieces of the main
problem
 keep combining their results into larger solutions
 eventually the original problem will be solved
5
MERGE SORT
 Sort into nondecreasing order
 log2n passes are required.
 time complexity: O(nlogn)
[25][57][48][37][12][92][86][33]
[25 57][37 48][12 92][33 86]
[25 37 48 57][12 33 86 92]
[12 25 33 37 48 57 86 92]
pass 1
pass 2
pass 3
6
QUICK SORT
 Select a pivot whose value we are going to divide the
sublist. (e.g., p = A[l])
 Rearrange the list so that it starts with the pivot
followed by a ≤ sublist (a sublist whose elements are
all smaller than or equal to the pivot) and a ≥ sublist
(a sublist whose elements are all greater than or equal
to the pivot ) (See algorithm Partition in section 4.2)
 Exchange the pivot with the last element in the first
sublist(i.e., ≤ sublist) – the pivot is now in its final
position
 Sort the two sublists recursively using quicksort.
p
A[i]≤p A[i] ≥ p
7
QUICK SORT
5 3 1 9 8 2 4 7
 2 3 1 4 5 8 9 7
 1 2 3 4 5 7 8 9
 1 2 3 4 5 7 8 9
 1 2 3 4 5 7 8 9
 1 2 3 4 5 7 8 9
8
BINARY SEARCH
ALGORITHM
BinarySearch(A[0..n-1], K)
//Implements nonrecursive binary search
//Input: An array A[0..n-1] sorted in ascending order and
// a search key K
//Output: An index of the array’s element that is equal to K
// or –1 if there is no such element
l  0, r  n – 1
while l ≤ r do //l and r crosses over can’t find
K.
m (l + r) / 2
if K = A[m] return m //the key is found
else
if K < A[m] r m – 1//the key is on the left half of the
array
else l  m + 1 // the key is on the right half of
the array
return -1
9
Thank You
10

More Related Content

PPTX
Quick sort
PPT
Divide and Conquer
PPT
Dinive conquer algorithm
PPTX
Divide and conquer - Quick sort
PDF
Algorithms Lecture 3: Analysis of Algorithms II
PPTX
Quick sort
PPTX
Asymptotic Notations
PPT
Lower bound
Quick sort
Divide and Conquer
Dinive conquer algorithm
Divide and conquer - Quick sort
Algorithms Lecture 3: Analysis of Algorithms II
Quick sort
Asymptotic Notations
Lower bound

What's hot (20)

PPTX
daa-unit-3-greedy method
PPTX
Travelling salesman dynamic programming
PPTX
Graph in data structure
PPTX
8 queens problem using back tracking
PPT
Greedy Algorihm
PPTX
Analysis and Design of Algorithms
PDF
UNIT-V.pdf daa unit material 5 th unit ppt
PPTX
Greedy algorithms
PPTX
Sorting Algorithms
PPTX
Merge sort algorithm
PPT
Minimum spanning tree
PPT
Complexity of Algorithm
PPT
Sum of subsets problem by backtracking 
PPT
Asymptotic notations
PPTX
Greedy Algorithms
PPTX
Single source Shortest path algorithm with example
PPTX
Priority Queue in Data Structure
PPTX
Breadth First Search & Depth First Search
PPTX
The n Queen Problem
PPTX
Stressen's matrix multiplication
daa-unit-3-greedy method
Travelling salesman dynamic programming
Graph in data structure
8 queens problem using back tracking
Greedy Algorihm
Analysis and Design of Algorithms
UNIT-V.pdf daa unit material 5 th unit ppt
Greedy algorithms
Sorting Algorithms
Merge sort algorithm
Minimum spanning tree
Complexity of Algorithm
Sum of subsets problem by backtracking 
Asymptotic notations
Greedy Algorithms
Single source Shortest path algorithm with example
Priority Queue in Data Structure
Breadth First Search & Depth First Search
The n Queen Problem
Stressen's matrix multiplication
Ad

Similar to Divide and conquer (20)

PPTX
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
PDF
Bs,qs,divide and conquer 1
PPTX
Chapter 4.2 - ADTree_Divide_n_Conquer 2021
PDF
Unit ii divide and conquer -1
PPTX
Module 2_ Divide and Conquer Approach.pptx
PPT
Designing Algorithms using Divide and Conquer Approach
PPTX
All Searching and Sorting Techniques in Data Structures
PPTX
09 QUICK SORT Design and Analysis of algorithms
PPT
DAA-Divide and Conquer methodology, DAA 2024
PPT
Presentation on binary search, quick sort, merge sort and problems
PPTX
Data analysis and algorithms - UNIT 2.pptx
PPT
MergesortQuickSort.ppt
PPT
presentation_mergesortquicksort_1458716068_193111.ppt
PDF
module2_dIVIDEncONQUER_2022.pdf
PPTX
data_structure_Chapter two_computer.pptx
PDF
Sienna 4 divideandconquer
PPTX
Divide-and-conquer
PPTX
Chapter 2 divide &amp; conquer
PPTX
AJisthewewrtyuiojhghfdfsgvhjhklopi87ytrytfghjk
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
Bs,qs,divide and conquer 1
Chapter 4.2 - ADTree_Divide_n_Conquer 2021
Unit ii divide and conquer -1
Module 2_ Divide and Conquer Approach.pptx
Designing Algorithms using Divide and Conquer Approach
All Searching and Sorting Techniques in Data Structures
09 QUICK SORT Design and Analysis of algorithms
DAA-Divide and Conquer methodology, DAA 2024
Presentation on binary search, quick sort, merge sort and problems
Data analysis and algorithms - UNIT 2.pptx
MergesortQuickSort.ppt
presentation_mergesortquicksort_1458716068_193111.ppt
module2_dIVIDEncONQUER_2022.pdf
data_structure_Chapter two_computer.pptx
Sienna 4 divideandconquer
Divide-and-conquer
Chapter 2 divide &amp; conquer
AJisthewewrtyuiojhghfdfsgvhjhklopi87ytrytfghjk
Ad

More from Dr Shashikant Athawale (20)

PPT
multi threaded and distributed algorithms
PPT
Amortized analysis
PPT
Complexity theory
PPT
Model and Design
PPT
Fundamental of Algorithms
PPT
CUDA Architecture
PPT
Parallel Algorithms- Sorting and Graph
PPT
Analytical Models of Parallel Programs
PPT
Basic Communication
PPT
Parallel Processing Concepts
PPT
Parallel Processing Concepts
PPT
Dynamic programming
PPT
Parallel algorithms
PPT
Greedy method
PPT
Branch and bound
PPT
Asymptotic notation
PPT
String matching algorithms
PPTX
Advanced Wireless Technologies
PPTX
Vehicular network
multi threaded and distributed algorithms
Amortized analysis
Complexity theory
Model and Design
Fundamental of Algorithms
CUDA Architecture
Parallel Algorithms- Sorting and Graph
Analytical Models of Parallel Programs
Basic Communication
Parallel Processing Concepts
Parallel Processing Concepts
Dynamic programming
Parallel algorithms
Greedy method
Branch and bound
Asymptotic notation
String matching algorithms
Advanced Wireless Technologies
Vehicular network

Recently uploaded (20)

PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Well-logging-methods_new................
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Sustainable Sites - Green Building Construction
DOCX
573137875-Attendance-Management-System-original
PPTX
web development for engineering and engineering
PPT
Mechanical Engineering MATERIALS Selection
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Lesson 3_Tessellation.pptx finite Mathematics
Arduino robotics embedded978-1-4302-3184-4.pdf
Geodesy 1.pptx...............................................
OOP with Java - Java Introduction (Basics)
Model Code of Practice - Construction Work - 21102022 .pdf
CYBER-CRIMES AND SECURITY A guide to understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Digital Logic Computer Design lecture notes
Well-logging-methods_new................
UNIT 4 Total Quality Management .pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Foundation to blockchain - A guide to Blockchain Tech
Internet of Things (IOT) - A guide to understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Sustainable Sites - Green Building Construction
573137875-Attendance-Management-System-original
web development for engineering and engineering
Mechanical Engineering MATERIALS Selection
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT-1 - COAL BASED THERMAL POWER PLANTS

Divide and conquer

  • 1. DIVIDE & CONQUER ALGORITHMS Shashikant V. Athawale Assistant Professor ,Computer Engineering Department AISSMS College of Engineering, Kennedy Road, Pune , MS, India - 411001 1
  • 2. DIVIDE & CONQUER The most well known algorithm design strategy: 1. Divide the problem into two or more smaller subproblems. 2. Conquer the subproblems by solving them recursively. 3. Combine the solutions to the subproblems into the solutions for the original problem. 2
  • 3. THE DIVIDE AND CONQUER ALGORITHM Divide_Conquer(problem P) { if Small(P) return S(P); else { divide P into smaller instances P1, P2, …, Pk, k≥1; Apply Divide_Conquer to each of these subproblems; return Combine(Divide_Conque(P1), Divide_Conque(P2),…, Divide_Conque(Pk)); } } 3
  • 4. DIVIDE AND CONQUER EXAMPLES  Merge sort  Quick sort  Binary Search 4
  • 5. MERGE SORT  The merge sort algorithm works from “the bottom up”  start by solving the smallest pieces of the main problem  keep combining their results into larger solutions  eventually the original problem will be solved 5
  • 6. MERGE SORT  Sort into nondecreasing order  log2n passes are required.  time complexity: O(nlogn) [25][57][48][37][12][92][86][33] [25 57][37 48][12 92][33 86] [25 37 48 57][12 33 86 92] [12 25 33 37 48 57 86 92] pass 1 pass 2 pass 3 6
  • 7. QUICK SORT  Select a pivot whose value we are going to divide the sublist. (e.g., p = A[l])  Rearrange the list so that it starts with the pivot followed by a ≤ sublist (a sublist whose elements are all smaller than or equal to the pivot) and a ≥ sublist (a sublist whose elements are all greater than or equal to the pivot ) (See algorithm Partition in section 4.2)  Exchange the pivot with the last element in the first sublist(i.e., ≤ sublist) – the pivot is now in its final position  Sort the two sublists recursively using quicksort. p A[i]≤p A[i] ≥ p 7
  • 8. QUICK SORT 5 3 1 9 8 2 4 7  2 3 1 4 5 8 9 7  1 2 3 4 5 7 8 9  1 2 3 4 5 7 8 9  1 2 3 4 5 7 8 9  1 2 3 4 5 7 8 9 8
  • 9. BINARY SEARCH ALGORITHM BinarySearch(A[0..n-1], K) //Implements nonrecursive binary search //Input: An array A[0..n-1] sorted in ascending order and // a search key K //Output: An index of the array’s element that is equal to K // or –1 if there is no such element l  0, r  n – 1 while l ≤ r do //l and r crosses over can’t find K. m (l + r) / 2 if K = A[m] return m //the key is found else if K < A[m] r m – 1//the key is on the left half of the array else l  m + 1 // the key is on the right half of the array return -1 9