SlideShare a Scribd company logo
Algorithm Designing
using Divide and
Conquer
Divide and Conquer Algorithms
 Top-down technique for designing
algorithms.
 Divides the problem into smaller sub
problems and then composes the partial
solutions into the solutions of the original
problem
Basic problem-solving approach
The Working:
1- Divide
2- Conquer
3- Combine
Divide and Conquer
Algorithms based on Divide and Conquer:
 Merge Sort
 Quick Sort
 Binary Search
 Tower of Hanoi
Merge sort
IDEA: Break down a list into several sub-lists
until each sub list consists of a single element
and merge those sub lists in a manner that
results into a sorted list.
Merge function()
Merge sort
Quick sort
 Doesn’t use additional storage
 Selects a pivot value to assist with splitting the
array
 The actual position where the pivot value
belongs in the final sorted array, commonly
called as split point , will be used to divide the
array for subsequent calls to the quick sort .
Quick Sort
Different versions:
 Always pick first element as pivot.
 Always pick last element as pivot.
 Pick a random element as pivot.
 Pick median as pivot.
Quick sort
 Step 1 - Choose the first index value has pivot.
 Step 2 − Take two variables to point left and right of the array.
 Step 3 − left points to the low index.
 Step 4 − right points to the high index.
 Step 5 − while value at left is less than pivot move right
 Step 6 − while value at right is greater than pivot move left
 Step 7 − if both step 5 and step 6 does not match swap left and right
 Step 8 − if left ≥ right, the point where they met is new pivot
Partition fun()
Quick sort
Binary Search
 Works on sorted array.
 Uses the middle array to compare.
2 3 6 8 10 12 15
MIDDLE
1. Check if the Middle number is equal to our number
True Terminate
False Continue
2. Check if our number is less than the middle no
True
2 3 6
MIDDLE
Continue from Step 1 with
this array
False Continue
3. Check if our number is greater than the middle no
True
10 12 15
MIDDLE
False “Element not there in the array ”
Continue from Step 1
with this array
Binary search
Tower of Hanoi
 A mathematical puzzle where we have three
rods and n disks.
 Objective:
To move the entire stack to another rod
 Rules:
1) Only one disk can be moved at a time.
2) a disk can only be moved if it is the
uppermost disk on a stack.
3) No disk may be placed on top of a smaller
disk.
Tower of Hanoi
Advantages
 Optimal for a general case solution,
like merge sort.
 Parallel processing.
 Memory Access
Disadvantages
 Problem decomposition
 Recursive nature
 Lead to Huge recursive stacks

More Related Content

PPT
Divide and conquer
Dr Shashikant Athawale
 
PPTX
Divide and conquer - Quick sort
Madhu Bala
 
PPT
Mergesort
luzenith_g
 
PDF
Divide and conquer
Emmanuel college
 
PDF
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
PPTX
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
PPT
Sorting
Ghaffar Khan
 
PPT
Lect11 Sorting
ryokollll
 
Divide and conquer
Dr Shashikant Athawale
 
Divide and conquer - Quick sort
Madhu Bala
 
Mergesort
luzenith_g
 
Divide and conquer
Emmanuel college
 
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Sorting
Ghaffar Khan
 
Lect11 Sorting
ryokollll
 

What's hot (20)

RTF
Design and Analysis of algorithms
Dr. Rupa Ch
 
PPTX
Merge Sort
Nikhil Sonkamble
 
PDF
Chapter 14 Searching and Sorting
MuhammadBakri13
 
PPTX
Merge sort
Rojin Khadka
 
PPTX
Divide and conquer 1
Kumar
 
PPT
Data Structures - Searching & sorting
Kaushal Shah
 
PPSX
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
DOC
Algorithms Question bank
Shivalik college of engineering
 
PPT
Unit 2 linked list and queues
kalyanineve
 
PPT
3.8 quick sort
Krish_ver2
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
PPTX
Functions
Juan Apolinario Reyes
 
PPTX
Merge sort
Sindhoo Oad
 
PPT
Quicksort
Gayathri Gaayu
 
PPTX
Searching & Sorting Algorithms
Rahul Jamwal
 
PPT
(Data Structure) Chapter11 searching & sorting
Fadhil Ismail
 
PPT
L10 sorting-searching
mondalakash2012
 
PPTX
Merge sort analysis and its real time applications
yazad dumasia
 
PPTX
Insertion Sort, Quick Sort And Their complexity
Motaleb Hossen Manik
 
PPTX
10 merge sort
irdginfo
 
Design and Analysis of algorithms
Dr. Rupa Ch
 
Merge Sort
Nikhil Sonkamble
 
Chapter 14 Searching and Sorting
MuhammadBakri13
 
Merge sort
Rojin Khadka
 
Divide and conquer 1
Kumar
 
Data Structures - Searching & sorting
Kaushal Shah
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
Algorithms Question bank
Shivalik college of engineering
 
Unit 2 linked list and queues
kalyanineve
 
3.8 quick sort
Krish_ver2
 
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Merge sort
Sindhoo Oad
 
Quicksort
Gayathri Gaayu
 
Searching & Sorting Algorithms
Rahul Jamwal
 
(Data Structure) Chapter11 searching & sorting
Fadhil Ismail
 
L10 sorting-searching
mondalakash2012
 
Merge sort analysis and its real time applications
yazad dumasia
 
Insertion Sort, Quick Sort And Their complexity
Motaleb Hossen Manik
 
10 merge sort
irdginfo
 
Ad

Similar to Algorithm designing using divide and conquer algorithms (20)

PDF
Bs,qs,divide and conquer 1
subhashchandra197
 
PDF
Unit ii divide and conquer -1
subhashchandra197
 
PPTX
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
LakshmiSamivel
 
PPTX
Module 2_ Divide and Conquer Approach.pptx
nikshaikh786
 
PPT
Data Structure Sorting
Muhazzab Chouhadry
 
PPTX
Algorithm in computer science
Riazul Islam
 
PPT
Divide and conquer
Muhammad Sarfraz
 
PPTX
data_structure_Chapter two_computer.pptx
Mohammed472103
 
PDF
Heap, quick and merge sort
Dr. Mohammad Amir Khusru Akhtar (Ph.D)
 
PPTX
data structures and algorithms Unit 3
infanciaj
 
PPTX
Quick sort
Afaq Mansoor Khan
 
PPTX
09 QUICK SORT Design and Analysis of algorithms
syamalamaganti
 
PPTX
Divide-and-conquer
Mrunal Patil
 
PPTX
Weak 11-12 Sorting update.pptxbhjiiuuuuu
baloch4551701
 
PPTX
Divide and Conquer
Melaku Bayih Demessie
 
PPTX
Module 2 Quick Sort algorithm in analysis of algorithm.pptx
SiddhantRaut20
 
PPTX
Sortings .pptx
MuhammadSheraz836877
 
PPTX
2.Problem Solving Techniques and Data Structures.pptx
Ganesh Bhosale
 
PPTX
Divide and conquer
ramya marichamy
 
Bs,qs,divide and conquer 1
subhashchandra197
 
Unit ii divide and conquer -1
subhashchandra197
 
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
LakshmiSamivel
 
Module 2_ Divide and Conquer Approach.pptx
nikshaikh786
 
Data Structure Sorting
Muhazzab Chouhadry
 
Algorithm in computer science
Riazul Islam
 
Divide and conquer
Muhammad Sarfraz
 
data_structure_Chapter two_computer.pptx
Mohammed472103
 
Heap, quick and merge sort
Dr. Mohammad Amir Khusru Akhtar (Ph.D)
 
data structures and algorithms Unit 3
infanciaj
 
Quick sort
Afaq Mansoor Khan
 
09 QUICK SORT Design and Analysis of algorithms
syamalamaganti
 
Divide-and-conquer
Mrunal Patil
 
Weak 11-12 Sorting update.pptxbhjiiuuuuu
baloch4551701
 
Divide and Conquer
Melaku Bayih Demessie
 
Module 2 Quick Sort algorithm in analysis of algorithm.pptx
SiddhantRaut20
 
Sortings .pptx
MuhammadSheraz836877
 
2.Problem Solving Techniques and Data Structures.pptx
Ganesh Bhosale
 
Divide and conquer
ramya marichamy
 
Ad

Recently uploaded (20)

PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PPT
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Inventory management chapter in automation and robotics.
atisht0104
 
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 

Algorithm designing using divide and conquer algorithms

  • 2. Divide and Conquer Algorithms  Top-down technique for designing algorithms.  Divides the problem into smaller sub problems and then composes the partial solutions into the solutions of the original problem
  • 3. Basic problem-solving approach The Working: 1- Divide 2- Conquer 3- Combine
  • 4. Divide and Conquer Algorithms based on Divide and Conquer:  Merge Sort  Quick Sort  Binary Search  Tower of Hanoi
  • 5. Merge sort IDEA: Break down a list into several sub-lists until each sub list consists of a single element and merge those sub lists in a manner that results into a sorted list.
  • 8. Quick sort  Doesn’t use additional storage  Selects a pivot value to assist with splitting the array  The actual position where the pivot value belongs in the final sorted array, commonly called as split point , will be used to divide the array for subsequent calls to the quick sort .
  • 9. Quick Sort Different versions:  Always pick first element as pivot.  Always pick last element as pivot.  Pick a random element as pivot.  Pick median as pivot.
  • 10. Quick sort  Step 1 - Choose the first index value has pivot.  Step 2 − Take two variables to point left and right of the array.  Step 3 − left points to the low index.  Step 4 − right points to the high index.  Step 5 − while value at left is less than pivot move right  Step 6 − while value at right is greater than pivot move left  Step 7 − if both step 5 and step 6 does not match swap left and right  Step 8 − if left ≥ right, the point where they met is new pivot
  • 13. Binary Search  Works on sorted array.  Uses the middle array to compare. 2 3 6 8 10 12 15 MIDDLE 1. Check if the Middle number is equal to our number True Terminate False Continue 2. Check if our number is less than the middle no True 2 3 6 MIDDLE Continue from Step 1 with this array
  • 14. False Continue 3. Check if our number is greater than the middle no True 10 12 15 MIDDLE False “Element not there in the array ” Continue from Step 1 with this array
  • 16. Tower of Hanoi  A mathematical puzzle where we have three rods and n disks.  Objective: To move the entire stack to another rod  Rules: 1) Only one disk can be moved at a time. 2) a disk can only be moved if it is the uppermost disk on a stack. 3) No disk may be placed on top of a smaller disk.
  • 18. Advantages  Optimal for a general case solution, like merge sort.  Parallel processing.  Memory Access
  • 19. Disadvantages  Problem decomposition  Recursive nature  Lead to Huge recursive stacks

Editor's Notes

  • #19: 1.In a perfect world, where the problem is easy to divide, and the sub-problem at some level is easy to solve, divide and conquer can be optimal for a general case solution, like merge sort. 2. Parallel availability, divide and conquer by it’s very nature lends itself well to parallel processing. 3. Memory Access: Each problem is divided into various sub-problems. Thus, the size of each sub-problem becomes extremely small and can be stored and processed in the cache memory. It requires 0 or extremely small need of using main memory.
  • #20: 1.Problem decomposition may be very complex and thus not really suitable to divide and conquer. 2.Recursive nature of the solution may end up duplicating sub-problems, dynamic/memoized solutions may be better in some of these cases, like Fibonacci. 3. Recursion into small/tiny base cases may lead to huge recursive stacks, and efficiency can be lost by not applying solutions earlier for larger base cases.