C++ Example – Merge Sort Algorithm






Merge sort

  • Merge sort algorithm is one of two important divide-and-conquer sorting algorithms (the other one is quick sort).Merge
  • MergeIt is a recursive algorithm.Merge
    • MergeDivides the list into halves,Merge
    • MergeSort each halve separately, andMerge
    • MergeThen merge the sorted halves into one sorted array.Merge

In this lesson we will learn how to write a source code in C++ programming language for doing simple Merge sort using array in ascending order.

Merge Sort  C++ Example :

Analysis of Merge 

Merging two sorted arrays of size kMerge

  • Best-case: Merge
    • MergeAll the elements in the first array are smaller (or larger) than all the elements in the second array.Merge
    • MergeThe number of moves: 2k + 2k Merge
    • MergeThe number of key comparisons: kMerge
  • Worst-case: Merge
    • MergeThe number of moves: 2k + 2k Merge
    • MergeThe number of key comparisons: 2k-1Merge

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Stuff I use to make videos

Windows notebook – http://amzn.to/2zcXPyF

Apple MacBook Pro – http://amzn.to/2BTJBZ7

Desktop - http://amzn.to/2zct252

Microphone – http://amzn.to/2zcYbW1

notebook mouse – http://amzn.to/2BVs4Q3

Screen Recording Software – Camtasia