You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Merge sort is an efficient, general-purpose sorting algorithm that uses a divide and conquer strategy. It works by repeatedly splitting a list in half until each sub-list contains a single element, and then merging those sub-lists back together in the correct order.
Merge sort follows three key steps:
A list of one element is considered already sorted (this is the base case for the recursion).
FUNCTION mergeSort(list)
IF LENGTH(list) <= 1 THEN
RETURN list
ENDIF
mid = LENGTH(list) DIV 2
left = mergeSort(list[0 TO mid - 1])
right = mergeSort(list[mid TO end])
RETURN merge(left, right)
ENDFUNCTION
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.