You are on page 1of 13

CSE

DESIGN &ANALYSIS OF ALGORITHEMS


21CS2214RB
Topic:

MERGE SORT

Session -7

CREATED BY K. VICTOR BABU


AIM OF THE SESSION

To introduce students to the basic concepts merge sort and its algorithm

INSTRUCTIONAL OBJECTIVES

This Session is designed to:

Demonstrate about merge sort algorithm

LEARNING OUTCOMES

At the end of this session, you should be able to

Describe about merge sort algorithm and its time complexity

CREATED BY K. VICTOR BABU


SESSION INTRODUCTION

Merge Sort
Merge sort is yet another sorting algorithm that falls under the category of Divide and Conquer technique.
It is one of the best sorting techniques that successfully build a recursive algorithm.

CREATED BY K. VICTOR BABU


SESSION DESCRIPTION (Cont..)

Merge Sort

1. Base Case, solve the problem directly if it is small enough(only one


element).

2. Divide the problem into two or more similar and smaller


subproblems.

3. Recursively solve the subproblems.

4. Combine solutions to the subproblems.

CREATED BY K. VICTOR BABU


Merge Sort: Idea

Divide into
A FirstPart SecondPart
two halves

FirstPart SecondPart

Merge

A is sorted!

CREATED BY K. VICTOR BABU


Merge Sort: Algorithm
• ALGORITHM-MERGE SORT  
2. 1. If p<r  
• 2. Then q → ( p+ r)/2  
4. 3. MERGE-SORT (A, p, q)  
• 4. MERGE-SORT ( A, q+1,r)  
6. 5. MERGE ( A, p, q, r)  

CREATED BY K. VICTOR BABU


ACTIVITIES/ CASE STUDIES/ IMPORTANT FACTS RELATED TO THE
SESSION

Writing an algorithm for merge sort


Finding the time complexity for merge sort

CREATED BY K. VICTOR BABU


EXAMPLES

To know the functioning of merge sort, lets consider an array arr[] = {38,
27, 43, 3, 9, 82, 10}

CREATED BY K. VICTOR BABU


SUMMARY

• Quick-Sort
– Most of the work done in partitioning
– Best case takes O(n log(n)) time
– Average case takes O(n log(n)) time
– Worst case takes O(n2) time
• Merge-sort
All cases take O(n log(n)) time

CREATED BY K. VICTOR BABU


SELF-ASSESSMENT QUESTIONS

1. Merge sort uses which of the following technique to implement sorting?

a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming

2. What is the average case time complexity of merge sort?

a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)

CREATED BY K. VICTOR BABU


TERMINAL QUESTIONS

1. Describe 3 case complexities of merge sort

2. Analyze mere sort algorithm find out recurrence relation

CREATED BY K. VICTOR BABU


REFERENCES FOR FURTHER LEARNING OF THE SESSION

Reference Books:
1.  Robert Sedgewick and Kevin wayne ,”Algorithms”, 4th edition,Addison Wesley Prof.,
(2011).
2. 2. Anny Levitin, “Introduction to Design and Analysis of Algorithms”, 2rd Edition, Person
Education Press. (2007).
3. 3. Michael T.Goodrich and Roberto Tamassia, Algorithm Design: Foundations, Analysis
and Internet Examples, Second Edition, Wiley-India, (200)6.
4. 4. Steven S. Skiena, “The Algorithm Design Manual”, Second Edition, Springer, (2008)
Sites and Web links:
5. https://www.javatpoint.com/daa-merge-sor
2. https://www.geeksforgeeks.org/merge-sort/

CREATED BY K. VICTOR BABU


THANK YOU

Team – DAA

CREATED BY K. VICTOR BABU

You might also like