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

CS5800: Advanced Data Structures and Algorithms: The Divide and Conquer Paradigm

The document describes the merge sort algorithm. It works by dividing the problem into subproblems, solving those subproblems recursively using merge sort, and then combining the sorted subproblems back together. The algorithm has three main steps - divide, conquer, and combine. It has a running time of O(n log n) which is proven using a recursion tree analysis of the algorithm.

Uploaded by

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

CS5800: Advanced Data Structures and Algorithms: The Divide and Conquer Paradigm

The document describes the merge sort algorithm. It works by dividing the problem into subproblems, solving those subproblems recursively using merge sort, and then combining the sorted subproblems back together. The algorithm has three main steps - divide, conquer, and combine. It has a running time of O(n log n) which is proven using a recursion tree analysis of the algorithm.

Uploaded by

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

CS5800: Advanced Data

Structures and Algorithms


The Divide and Conquer Paradigm

Merge Sort Algorithm

John Augustine

CS5800 (Odd 2013): The Merge Sort Algorithm

The Divide and Conquer Paradigm

Divide the problem into subproblems.


Conquer or solve the subproblems.
Combine the solutions of subproblems to form the
solution for the original problem.
Typically analyse running time using recurrence
equations.

CS5800 (Odd 2013): The Merge Sort Algorithm

The Sorting Problem

Input: An arbitrarily ordered list A of n items and a


total order on the elements of A.
1. For our purpose, A is a list of n distinct integers
and the usual ordering.
2. We will typically use a list implemented using arrays
to hold our lists and sequences.
Output: A sequence ordered according to .
The input and output lists are often the same to
avoid redundancy.

CS5800 (Odd 2013): The Merge Sort Algorithm

The Merge Sort Algorithms

Merge-Sort(A,`, r) /* guarantee: ` < r */


1. q b(` + r)/2c
2. Merge-Sort(A, `, q)
3. Merge-Sort(A, q + 1, r)
4. Merge(A, `, q, r) /* see below */

The Merge(A, `, q, r) step (described next slide)


takes an array A and indices ` q < r
assuming subarrays A[` . . . q] and A[q + 1 . . . r] are
sorted, and
merges them so that the subarray A[` . . . r] is sorted.
CS5800 (Odd 2013): The Merge Sort Algorithm

The Merge Step

Merge(A, `, q, r)
1. L A[` . . . q]; Append to L.
2. R A[q + 1 . . . r]; Append to R.
3. i j 1
4. For k ` to r do
(a) if L[i] R[j] then
A[k] = L[i]
i++
(b) else
A[k] = R[j]
j++

CS5800 (Odd 2013): The Merge Sort Algorithm

Analysis

The proof of correctness is elementary.


So we focus on running time T (n) given an input of n
items.


T (n)

c
2T (n/2) + cn

if n = 1, and
if n > 1,

where c > 0 is some constant.


By constructing a recursion tree, we can see that
T (n) O(n log n).

CS5800 (Odd 2013): The Merge Sort Algorithm

You might also like