You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the merge sort algorithm as required by OCR J277 Section 2.2. Merge sort is the second standard sorting algorithm you must know for the OCR GCSE Computer Science exam. Unlike bubble sort, merge sort uses a "divide and conquer" strategy and is significantly more efficient for large datasets.
Merge sort is a sorting algorithm that uses a divide and conquer approach. It works by:
The first phase splits the list repeatedly in half:
[6, 3, 8, 1, 5, 2, 7, 4][6, 3, 8, 1, 5, 2, 7, 4]
/ \
[6, 3, 8, 1] [5, 2, 7, 4]
/ \ / \
[6, 3] [8, 1] [5, 2] [7, 4]
/ \ / \ / \ / \
[6] [3] [8] [1] [5] [2] [7] [4]
The second phase merges the sorted sub-lists back together:
[6] [3] [8] [1] [5] [2] [7] [4]
\ / \ / \ / \ /
[3, 6] [1, 8] [2, 5] [4, 7]
\ / \ /
[1, 3, 6, 8] [2, 4, 5, 7]
\ /
[1, 2, 3, 4, 5, 6, 7, 8]
OCR Exam Tip: In exam questions, you are often asked to "show the stages of a merge sort". Make sure you show BOTH the divide phase (splitting into halves) AND the merge phase (combining in order). Showing only one phase will lose marks.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.