0% found this document useful (0 votes)
4 views

CSPC24 Chapter 5 - Divide and Conquer Algorithm Design Technique

The document explains the divide-and-conquer algorithm design technique, which involves dividing a problem into smaller sub-problems, solving them independently, and combining their solutions. It highlights the importance of this technique and provides applications such as merge sort, binary search, and quicksort. The document also includes algorithmic descriptions for binary search and quicksort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CSPC24 Chapter 5 - Divide and Conquer Algorithm Design Technique

The document explains the divide-and-conquer algorithm design technique, which involves dividing a problem into smaller sub-problems, solving them independently, and combining their solutions. It highlights the importance of this technique and provides applications such as merge sort, binary search, and quicksort. The document also includes algorithmic descriptions for binary search and quicksort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

CSPC 24

Algorithm and
Complexity
DIVIDE AND CONQUER
ALGORITHM DESIGN TECHNIQUE
Objectives
• Explain the definition of divide-and-conquer algorithm
design technique.

• Synthesize the importance of divide-and-conquer


algorithm.

• Apply the divide-and-conquer algorithm design


technique.
DIVIDE-AND-CONQUER ALGORITHM
DESIGN TECHNIQUE

• a problem is divided into smaller problems, then the


smaller problems are solved independently, and finally
the solutions of smaller problems are combined into a
solution for the large problem.
Importance of Divide and Conquer
Algorithm
Generally, divide-and-conquer algorithms have three parts.
• Divide the problem into a number of sub-problems that
are smaller instances of the same problem.

• Conquer the sub-problems by solving them recursively.


If they are small enough, solve the sub-problems as base
cases.

• Combine the solutions to the sub-problems into the


solution for the original problem.
Application of Divide and Conquer
Approach
Following are some problems, which are solved using
divide and conquer approach.

• Finding the maximum and minimum of a sequence of


numbers
• Strassen’s matrix multiplication
• Merge sort
• Binary search
Merge sort
• is also a sorting algorithm.

• The algorithm divides the array in two halves,


recursively sorts them and finally merges the two sorted
halves.
Merge sort(Problem Statement)
The problem of sorting a list of numbers lends itself
immediately to a divide-and-conquer strategy: split the
list into two halves, recursively sort each half, and then
merge the two sorted sub-lists.
Binary Search
• is a searching algorithm. In each step, the algorithm
compares the input element x with the value of the
middle element in array. If the values match, return the
index of the middle.

• Otherwise, if x is less than the middle element, then the


algorithm recurs for left side of middle element, else
recurs for the right side of the middle element.
Binary Search(Problem Statement)
• Binary search can be performed on a sorted array. In
this approach, the index of an element x is determined
if the element belongs to the list of elements. If the
array is unsorted, linear search is used to determine the
position.
Binary Search(Algorithm)
Binary-Search(numbers[], x, l, r)
if l = r then
return l
else
m := ⌊(l + r) / 2⌋
if x ≤ numbers[m] then
return Binary-Search(numbers[], x, l, m)
else
return Binary-Search(numbers[], x, m+1, r)
Quicksort
• is a sorting algorithm.
• The algorithm picks a pivot element, rearranges the array elements in
such a way that all elements smaller than the picked pivot element
move to left side of pivot, and all greater elements move to right side.
• Finally, the algorithm recursively sorts the subarrays on left and right
of pivot element.
• Quick sort is a highly efficient sorting algorithm and is based on
partitioning of array of data into smaller arrays.
• A large array is partitioned into two arrays one of which holds values
smaller than the specified value, say pivot, based on which the
partition is made and another array holds values greater than the pivot
value.
Quicksort
Thank you!
REFERENCES:
Cormen T., Leiserson C., Rivest R., & Stein C. (2009). Introduction to Algorithms Third
Edition. The MIT Press, Cambridge, Massachusets
Fleck, Margaret M., (2013). Building Blocks for Theoretical Computer Science. Version
1.3 (January 2013)
Lehman, Eric F., Leighton, Thomson & Meyer, Albert R. (2018). Mathematics for
Computer Science. June 2018
ONLINE REFERENCES:
https://www.geeksforgeeks.org/
http://www.freebookcentre.net/CompuScience/free-computer-algorithm-books.html

You might also like