Merge Sort Tracing in AP CSA: How to Trace Without Writing Code (2026)
Merge Sort Tracing in AP CSA: How to Trace Without Writing Code
Merge sort appears on the 2026 AP CSA exam as a trace-only topic. You will NOT be asked to write the algorithm, but you need to show how the array splits apart and merges back together. This page teaches the exact tracing technique the exam expects.
📄 On This Page
🎲 The Big Picture
Merge sort works in two phases:
- Divide: Keep splitting the array in half until each piece has one element
- Merge: Combine pairs of sorted pieces back together, maintaining order
When the exam asks you to trace merge sort, draw the tree. Show the splits going DOWN and the merges going UP. This visual approach prevents almost all mistakes.
✂ Step 1: The Divide Phase
Start with {38, 27, 43, 3, 9, 82, 10}. Split at mid = (0 + 6) / 2 = 3:
[38, 27, 43, 3, 9, 82, 10]
/ \
[38, 27, 43, 3] [9, 82, 10]
/ \ / \
[38, 27] [43, 3] [9, 82] [10]
/ \ / \ / \
[38] [27] [43] [3] [9] [82] [10]
Each single element is already “sorted” — that is the base case.
🔄 Step 2: The Merge Phase
Now merge pairs back together. To merge two sorted lists, compare their front elements and take the smaller one:
Merge [38] and [27]:
Compare 38 vs 27. Take 27 first, then 38. Result: [27, 38]
Merge [43] and [3]:
Compare 43 vs 3. Take 3 first, then 43. Result: [3, 43]
Merge [9] and [82]:
Compare 9 vs 82. Take 9 first, then 82. Result: [9, 82]
Merge [27, 38] and [3, 43]:
| Step | Compare | Take | Result So Far |
|---|---|---|---|
| 1 | 27 vs 3 | 3 | [3] |
| 2 | 27 vs 43 | 27 | [3, 27] |
| 3 | 38 vs 43 | 38 | [3, 27, 38] |
| 4 | 43 left | 43 | [3, 27, 38, 43] |
Merge [9, 82] and [10]:
9 vs 10: take 9. 82 vs 10: take 10. Take 82. Result: [9, 10, 82]
Final Merge [3, 27, 38, 43] and [9, 10, 82]:
| Step | Compare | Take | Result So Far |
|---|---|---|---|
| 1 | 3 vs 9 | 3 | [3] |
| 2 | 27 vs 9 | 9 | [3, 9] |
| 3 | 27 vs 10 | 10 | [3, 9, 10] |
| 4 | 27 vs 82 | 27 | [3, 9, 10, 27] |
| 5 | 38 vs 82 | 38 | [3, 9, 10, 27, 38] |
| 6 | 43 vs 82 | 43 | [3, 9, 10, 27, 38, 43] |
| 7 | 82 left | 82 | [3, 9, 10, 27, 38, 43, 82] |
📈 Full Trace Tree
DIVIDE (top down):
[38, 27, 43, 3, 9, 82, 10]
/ \
[38, 27, 43, 3] [9, 82, 10]
/ \ / \
[38,27] [43,3] [9,82] [10]
/ \ / \ / \
[38] [27] [43] [3] [9] [82]
MERGE (bottom up):
[27,38] [3,43] [9,82] [10]
\ / \ /
[3,27,38,43] [9,10,82]
\ /
[3, 9, 10, 27, 38, 43, 82]
❌ Common Pitfalls
The split is at mid = (left + right) / 2 using integer division. For an array of length 6 (indices 0-5): mid = (0+5)/2 = 2. Left = indices 0-2 (3 elements), Right = indices 3-5 (3 elements).
During the merge, always compare the FRONT elements of both sub-arrays. Take the smaller one. Students sometimes compare all elements at once instead of front-to-front.
When one sub-array runs out of elements during a merge, append ALL remaining elements from the other sub-array. Do not stop merging early.
Merge sort uses recursion and extra space. If the exam code has no recursive calls, it is not merge sort. If it sorts in-place with swaps or shifts, it is selection or insertion sort.
✏ Practice Questions
{5, 2, 8, 1}, what are the two sub-arrays after the first split?[3, 7, 9] and [1, 5, 8]?I. It requires additional memory proportional to the array size.
II. Its worst-case performance is O(n log n).
III. It sorts elements in place without extra storage.
[2, 6] and [3, 4], how many comparisons are made?{6, 1, 4, 3}. After ALL splits and the FIRST round of merges (merging single elements), what are the two sorted sub-arrays waiting to be merged?❓ Frequently Asked Questions
Do I need to write merge sort on the AP CSA exam?
No. The 2026 AP CSA exam only requires you to trace merge sort, not write it. You need to understand how the divide and merge steps work and be able to show the array state at various points during execution.
How does merge sort divide the array?
Merge sort splits the array in half repeatedly until each sub-array has one element. Then it merges pairs of sub-arrays back together in sorted order. The split point is always the midpoint: mid = (left + right) / 2.
What is the time complexity of merge sort?
Merge sort has O(n log n) time complexity in all cases (best, average, and worst). This makes it significantly faster than selection sort and insertion sort (both O(n squared)) for large arrays.
How is merge sort different from selection and insertion sort?
Merge sort uses a divide-and-conquer approach with recursion, splitting the array and merging sorted halves. Selection and insertion sort work by iterating through the array directly. Merge sort is faster but uses additional memory for the merge step.
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]