0% found this document useful (0 votes)
33 views6 pages

Divide and Conquer in Merge Sort Analysis

Uploaded by

Muhammad Azeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

Divide and Conquer in Merge Sort Analysis

Uploaded by

Muhammad Azeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Introduction to Algorithms

Assignment no. 1
MS – Mathematics and Scientific Computing
MSS - 622
Assignment Objective:
This assignment aims to:
1. Analyze the Divide and Conquer algorithmic technique.
2. Evaluate its efficiency in solving computational problems.
3. Demonstrate critical thinking by applying the technique to a chosen
problem.
4. Compare the chosen algorithm's efficiency with other solutions.
5. Explore limitations and real-world scenarios where the Divide and Conquer
strategy may not be ideal.

Task: Analyze Divide and Conquer Strategy


Introduction
The Divide and Conquer strategy is a powerful algorithmic technique used to
solve complex problems by breaking them down into simpler subproblems. This
approach works especially well for algorithms that sort and search. Using Merge
Sort as an example, we will examine the Divide and Conquer method in this
analysis. We will go over each stage of the plan, offer a step-by-step algorithm,
assess the temporal complexity of the strategy, and talk about situations in which
this technique could not be effective.

1. Explanation of the Divide and Conquer Technique


The divide-and-conquer paradigm divides a problem into smaller, related
problems that are then resolved in a recursive manner. The overall problem is
then resolved by combining the solutions to the minor issues. Each sub problem
must have a base case and be smaller than the original problem because divide-
and-conquer solves subproblems recursively. A divide-and-conquer algorithm is
best understood as consisting of three components:
Divide: Break the difficulty down into a number of smaller challenges that are
subproblems of the primary problem.
Conquer: To get past subproblems, one must solve them recursively. Solve the
smaller issues as base cases if they are sufficiently small.
Combine: Put the answers to the subproblems together to solve the main issue.
The divide, conquer, combine approach makes it easy to memorize the stages of
the divide-and-conquer algorithm. Here's how to look at one of the two
subproblems that each divide step, assuming there are two (some divide-and-
conquer algorithms produce more than two), produces:

If we expand out two more recursive steps, it looks like this


Problem Selection: Merge Sort
Explanation of Divide and Conquer in Merge Sort
An array or list of elements can be sorted using the Divide and Conquer strategy
with the help of the effective, reliable Merge Sort sorting algorithm. This is how
Merge Sort uses the technique:

 Divide: Create two nearly equal sublists from the unsorted list.
 Conquer: Sort every sublist recursively. A sublist is automatically sorted if it
only has one element.
 Combine: By comparing and arranging the components in the proper order,
combine the two sorted sublists into a single sorted list.

Detailed Breakdown of Phases


Divide: Two sublists of around n/2 entries each are created from a list of n
elements.

Conquer: Merge Sort is used to recursively sort each sublist until there is only one
entry in each sublist.

Combine: The sublists that have been sorted are combined once more. In this
stage, a sorted list is put together by comparing the smallest components in the
two sublists.

2.Step-by-Step Algorithm for Merge Sort


Pseudo Code
MergeSort(A[], left, right):
if left < right:
mid = (left + right) / 2
MergeSort(A, left, mid)
MergeSort(A, mid+1, right)
Merge(A, left, mid, right)
Merge(A[], left, mid, right):
Create two temporary arrays, L[] and R[]
L[] = A[left ... mid]
R[] = A[mid+1 ... right]
i = 0, j = 0, k = left
while i < size of L and j < size of R:
if L[i] <= R[j]:
A[k] = L[i]
i++
else:
A[k] = R[j]
j++
k++

3. Time Complexity Analysis


The time complexity of Merge Sort can be analyzed using the recurrence relation:
T(n)=2T(n/2)+O(n)T(n)=2T(n/2)+O(n)
Here:
 T(n)T(n) represents the time taken to sort an array of size nn.
 The term 2T(n/2)2T(n/2) accounts for the two recursive calls made on
halves of the array.
 The term O(n)O(n) accounts for the time taken to merge the two sorted
halves.
Using the Master Theorem, we find that: T(n)=O(nlogn)T(n)=O(nlogn)
The image below shows the time complexity for Merge Sort.
Comparing This Algorithm to Others:
Quick Sort: Quick Sort has an average case time complexity of O(n log n), yet it
employs the Divide and Conquer strategy just as Merge Sort. While Merge Sort
ensures O(n log n) even in the worst scenario, its worst-case time complexity may
deteriorate to O(n^2) in unbalanced partitions.
Bubble Sort: With a temporal complexity of O(n^2), Bubble Sort is an inefficient
method that performs much slower than Merge Sort, particularly when dealing
with huge datasets.

4. Scenarios Where Divide and Conquer Might Fail or Be Inefficient


While Divide and Conquer is a powerful strategy, there are scenarios where it
may not be efficient:
 Overhead of Recursion: The recursive nature of Divide and Conquer can
lead to significant overhead due to function calls. For problems with very
small input sizes, iterative solutions may perform better.
 Memory Usage: Divide and Conquer algorithms often require additional
memory for temporary arrays or data structures used during processing (as
seen in Merge Sort). This can be problematic in memory-constrained
environments.
 Unbalanced Division: If the problem does not divide evenly (e.g., when one
half is significantly larger than the other), it can lead to inefficiencies. For
instance, Quick Sort's performance can degrade to O(n2)O(n2) if poor pivot
choices are made consistently.

Broader Applications and Limitations


Applications: The Divide and Conquer technique is not limited to sorting. It is also
widely used in algorithms such as Binary Search, Fast Fourier Transform (FFT), and
matrix multiplication (Strassen's algorithm).
Limitations: As mentioned, Divide and Conquer can be inefficient when
subproblems are not independent, or if recursion depth increases overhead,
leading to slower performance for small input sizes.

Conclusion
The Divide and Conquer strategy is an essential algorithmic technique that
effectively solves complex problems by breaking them down into manageable
parts. Through examples like Merge Sort, we see how this approach can lead to
efficient solutions with a time complexity of O(nlogn)O(nlogn). However, it is
crucial to consider scenarios where this method may not be optimal due to
recursion overhead or memory constraints. Understanding these nuances allows
developers to choose the most suitable algorithmic strategies for their specific
computational problems.

References
1- Divide and Conquer technique
https://www.khanacademy.org/computing/computer-science/algorithms/merge-
sort/a/divide-and-conquer-algorithms
2- Merge Sort Explanation https://www.javatpoint.com/merge-sort
3- Time Complexity of merge sort
https://www.w3schools.com/dsa/dsa_algo_mergesort.php#:~:text=The
%20Merge%20Sort%20algorithm%20is,so%20that%20it%20is%20sorted.

You might also like