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
PPTX
Divide and conquer - Quick sort
PPT
Mergesort
PDF
Divide and conquer
PDF
Quick Sort , Merge Sort , Heap Sort
PPTX
Data Structure and Algorithms Merge Sort
PPT
Sorting
PPT
Lect11 Sorting
Divide and conquer
Divide and conquer - Quick sort
Mergesort
Divide and conquer
Quick Sort , Merge Sort , Heap Sort
Data Structure and Algorithms Merge Sort
Sorting
Lect11 Sorting

What's hot (20)

RTF
Design and Analysis of algorithms
PPTX
Merge Sort
PDF
Chapter 14 Searching and Sorting
PPTX
Merge sort
PPTX
Divide and conquer 1
PPT
Data Structures - Searching & sorting
PPSX
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
DOC
Algorithms Question bank
PPT
Unit 2 linked list and queues
PPT
3.8 quick sort
PDF
Binary Search - Design & Analysis of Algorithms
PPTX
PPTX
Merge sort
PPT
Quicksort
PPTX
Searching & Sorting Algorithms
PPT
(Data Structure) Chapter11 searching & sorting
PPT
L10 sorting-searching
PPTX
Merge sort analysis and its real time applications
PPTX
Insertion Sort, Quick Sort And Their complexity
PPTX
10 merge sort
Design and Analysis of algorithms
Merge Sort
Chapter 14 Searching and Sorting
Merge sort
Divide and conquer 1
Data Structures - Searching & sorting
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Algorithms Question bank
Unit 2 linked list and queues
3.8 quick sort
Binary Search - Design & Analysis of Algorithms
Merge sort
Quicksort
Searching & Sorting Algorithms
(Data Structure) Chapter11 searching & sorting
L10 sorting-searching
Merge sort analysis and its real time applications
Insertion Sort, Quick Sort And Their complexity
10 merge sort
Ad

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

PPTX
Quick Sort in data structure.pptx
PPTX
Module 2_ Divide and Conquer Approach.pptx
PPTX
SORT AND SEARCH ARRAY WITH WITH C++.pptx
PDF
Heap, quick and merge sort
PPTX
Sorting
DOCX
Quick sort
PPT
Advanced s and s algorithm.ppt
PPTX
Searching searching in in arrays arrays.pptx
PDF
Algo PPT.pdf
PPTX
data structures and algorithms Unit 3
PPTX
Sorting Algorithms to arrange data in particular format
PPTX
VCE Unit 04vv.pptx
PDF
Chapter 8 advanced sorting and hashing for print
PPTX
Data analysis and algorithms - UNIT 2.pptx
PPTX
Divide and Conquer / Greedy Techniques
PPTX
what is sorting algorithm and implementation.pptx
PPTX
data_structure_Chapter two_computer.pptx
PDF
Design and analysis of algorithm final course
PDF
Design and analysis of algorithm final course
PPTX
Arrays and linked lists
Quick Sort in data structure.pptx
Module 2_ Divide and Conquer Approach.pptx
SORT AND SEARCH ARRAY WITH WITH C++.pptx
Heap, quick and merge sort
Sorting
Quick sort
Advanced s and s algorithm.ppt
Searching searching in in arrays arrays.pptx
Algo PPT.pdf
data structures and algorithms Unit 3
Sorting Algorithms to arrange data in particular format
VCE Unit 04vv.pptx
Chapter 8 advanced sorting and hashing for print
Data analysis and algorithms - UNIT 2.pptx
Divide and Conquer / Greedy Techniques
what is sorting algorithm and implementation.pptx
data_structure_Chapter two_computer.pptx
Design and analysis of algorithm final course
Design and analysis of algorithm final course
Arrays and linked lists
Ad

Recently uploaded (20)

PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Well-logging-methods_new................
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPT
Project quality management in manufacturing
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Welding lecture in detail for understanding
PDF
PPT on Performance Review to get promotions
PPTX
web development for engineering and engineering
PDF
Digital Logic Computer Design lecture notes
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi
Well-logging-methods_new................
bas. eng. economics group 4 presentation 1.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Internet of Things (IOT) - A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Project quality management in manufacturing
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Welding lecture in detail for understanding
PPT on Performance Review to get promotions
web development for engineering and engineering
Digital Logic Computer Design lecture notes
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CH1 Production IntroductoryConcepts.pptx
573137875-Attendance-Management-System-original
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx

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.