cs101-notes
  • CS 101 Notes
  • Big O Notation
  • Big O Cheat Sheet
  • Sorting
    • Summary
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
    • Merge Sort
    • Quick Sort
  • Abstract Data Types
    • Linked List
    • Stack
    • Queue
    • Hash Maps
    • Minimum Ordered Heap
Powered by GitBook
On this page

Was this helpful?

  1. Sorting

Merge Sort

Divide and Conquer:

  • Split the data in half

  • Sort each half recursively

  • Merge the results

template <typename eType>
void mergeSort(vector<eType> list): 
    if len(list) < 2: 
        return list
    auto middle = len(list) / 2
    auto left = mergesort(list[:middle])
    auto right = mergesort(list[middle:])
    return merge(left, right)
PreviousInsertion SortNextQuick Sort

Last updated 5 years ago

Was this helpful?