Merge sort js

10
Welcome To My Presentation 1

Transcript of Merge sort js

Page 1: Merge sort js

Welcome To My

Presentation1

Page 2: Merge sort js

Submitted BySharmin Sultana Jeesa

ID#141-15-3219Dept: CSE

Course Code: CSE2212

Page 3: Merge sort js

Contents

MERGE SORT

3

Page 4: Merge sort js

Merging*The key to Merge Sort is merging two sorted lists into one, such that if you have two lists L1= {3, 8, 9} & L2= {1, 5, 7} then the sorted array will be, merge(L1, L2) = {1, 3, 5, 7, 8, 9}.*Time complexity of merge sort is O(n log₂n).*Double storage needed to hold the array to be sorted.

4

Page 5: Merge sort js

Invention

5

*Invented by John von Neumann (1903-1957).

*Follows divide and conquer approach.

Page 6: Merge sort js

Divide & Conquer*Divide: Divide the unsorted list into two sub lists of about half the size.*Conquer: Sort each of the two sub lists recursively until we have list sizes of length 1, in which case the list itself is returned.*Combine: Merge the two-sorted sub lists back into one sorted list.

6

Page 7: Merge sort js

5 8 4 2 6 3 0 1 7

7

5 8 4 2 6 3 0 1 7

5 8 4 2 6 3 0 1 7

85

5 8 4 2 6 3 0 1 7

Page 8: Merge sort js

0 1 2 3 4 5 6 7 8

8

2 4 5 6 8 0 1 3 7

5 8 4 2 6 3 0 1 7

85

4 5 8 2 6 0 3 1 7

MERGE

Page 9: Merge sort js

Uses Of Merge Sort Merge sort’s merge operation is useful in online sorting, where the list to be sorted is received a piece at a time, instead of all at the beginning.

In this We sort each new piece that is received using any sorting algorithm, and then merge it into our sorted list so far using the merge operation.

9

Page 10: Merge sort js

10

THANK YOU