Professional Documents
Culture Documents
Divide and Conquer Group Presentation
Divide and Conquer Group Presentation
and Analysis
D i v i d e a n d C o n q u e r
G R O U P P R E S E N TAT I O N
Introduction
A Presentation on the Divide and Conquer Approach in
Algorithm Design and Analysis
• The solutions of the sub-problems are then merged to obtain the solution of
the original problem.
BF JACKSON 2
Introduction Cont…
The divide and conquer approach can be understood in three
steps:
BF JACKSON 3
Introduction Cont…
Arrays as Input
• Arrays are commonly used as input for algorithms that employ the divide and
conquer technique.
• The array is divided into subproblems until they cannot be divided further.
• The subproblems are then solved independently, and the solutions are merged
to form the solution of the original array.
BF JACKSON 4
Introduction Cont…
Linked Lists as Input
• Linked lists can also be used as input for divide and conquer algorithms.
• Like arrays, linked lists are linear data structures that store data sequentially.
• The list is divided until it cannot be divided further, the nodes are sorted, and
then they are combined recursively to achieve the final solution.
BF JACKSON 5
Overview
Design and analysis of algorithms involves studying various techniques and approaches to solve
computational problems efficiently. In this context, let's discuss the following topics:
BF JACKSON 6
Topics Explanations
Multiplying Large Integers: S u p p o s e wEex aw mapnl te : t o m u l t i p l y
two large integers, such as
1 2 3 4 5 6 7 8 9 a n d 9 8 7 6 5 4 3 2 1 . We
Multiplying large integers involves
breaking down the problem into can break down the problem into
smaller subproblems and smaller subproblems:
recursively solving them. S p l i t t h e n u m b e r s i n t o two
The divide and conquer approach parts: 12345 and 6789, and
uses the concept of recursive 98765 and 4321.
multiplication, where large
integers are divided into smaller R e c u r s i v e l y multiply these
parts and recursively multiplied. subparts: 12345 * 98765 and
6789 * 4321.
The resulting sub-products are
combined to obtain the final C o m b i n e the sub-products:
product. (12345 * 98765) * 10^5 +
(12345 * 4321 + 6789 * 98765)
* 10^4 + (6789 * 4321).
BF JACKSON 7
Topics Explanations
C o n s iCont…
der an array of sorted
i n t e g e r s : [ 1 ,E 4x ,a m
7 ,p l9e,: 1 2 , 1 5 , 1 8 , 2 1 ,
Binary Search 2 5 ] . To f i n d t h e t a r g e t v a l u e 1 2 , w e
can apply binary search: Split the
Binary search is an efficient numbers into two parts: 12345 and
algorithm for finding a specific
t a r g e t v a l u e w i t h i n a s o r t e d a r r a y.
6789, and 98765 and 4321.
It involves repeatedly dividing the C o m p a r e t h e t a r g e t v a l u e w i t h t h e
search space in half by comparing middle element (9).Since the target
the target value with the middle i s g r e a t e r, w e d i s c a r d t h e l e f t h a l f
e l e m e n t o f t h e a r r a y. o f t h e a r r a y.
By discarding the half where the T h e n e w s e a r c h s p a c e b e c o m e s
target value cannot be present, the [12, 15, 18, 21, 25]. Repeat the
search space is significantly process by comparing with the
reduced. middle element (18).
Binary search has a time
T h e t a r g e t i s s m a l l e r , s o w e
complexity of O(log n), making it
faster than linear search for large d i s c a r d t h e r i g h t h a l f o f t h e a r r a y.
datasets. T h e n e w s e a r c h s p a c e b e c o m e s
BF JACKSON [ 1 2 , 1 5 , 1 8 ] . C o n t i n u e t h e p r o c e s s8
until the target is found or the
Topics Explanations Cont…
Sorting by Merging and Quicksort:
Merging and Quicksort are two popular algorithms for sorting elements in an
a r r a y.
•M e r g i n g s o r t i s b a s e d o n t h e d i v i d e a n d c o n q u e r s t r a t e g y. I t r e c u r s i v e l y
divides the array into smaller subarrays until each subarray contains a single
element. Then, it merges these subarrays in a sorted order to obtain a fully
s o r t e d a r r a y.
•Q u i c k s o r t i s a l s o a d i v i d e a n d c o n q u e r a l g o r i t h m . I t s e l e c t s a p i v o t e l e m e n t
and partitions the array around the pivot. Elements smaller than the pivot are
moved to the left, and elements greater than the pivot are moved to the right.
The process is repeated recursively on the subarrays until the entire array is
sorted. Example:
S u p p o s e w e h a v e a n u n s o r t e d a r r a y : [ 5 , 2 , 9 , 1 , 7 , 3 ] . We c a n u s e
the merging sort algorithm to sort it:
D i v i d e t h e a r r a y i n t o s m a l l e r s u b a r r a y s : [ 5 , 2 , 9 ] a n d [ 1 , 7 , 3 ] .
BF JACKSON
R e c u r s i v e l y s o r t t h e s u b a r r a y s : [ 2 , 5 , 9 ] a n d [ 1 , 3 , 7 ] . 9
M e r g e t h e s o r t e d s u b a r r a y s : [ 1 , 2 , 3 , 5 , 7 , 9 ] .
Topics Explanations Cont…
Finding Median: Example:
BF JACKSON 10
Topics Explanations Cont…
Matrix Multiplication: Example:
Exponentiation refers to
r a i s i n g a n u m b e r t o a p o w e r.
S u p p o s e w e w a n t t o c a l c u l a t e 2 ^ 8 .
The divide and conquer We c a n u s e t h e d i v i d e a n d c o n q u e r
approach can be applied to approach:
exponentiation through S p l i t t h e e x p o n e n t into smaller
recursive multiplication. parts: 2^4 * 2^4.
By breaking down the R e c u r s i v e l y c a l c u l a t e t h e sub-
exponent into smaller parts parts: 2^4 = 2 * 2 * 2 * 2.
and recursively calculating C o m b i n e t h e r e s u l t s : 2 ^ 8 = 2 ^ 4 *
the result, the overall 2^4.
computation can be
optimized.
BF JACKSON 12
Overhead of recursion: The
BF JACKSON 15
Thank you
Ronald Mutangabende M213198
Blessing Chizana M225655
Passion Joni M225228
Fuyana Bonginkosi M224216
BF JACKSON 16