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.

⏰ The AP CSA Exam is May 15, 2026 — Get the 4-Week Cram Kit →

🎲 The Big Picture

Merge sort works in two phases:

  1. Divide: Keep splitting the array in half until each piece has one element
  2. Merge: Combine pairs of sorted pieces back together, maintaining order
🎓 AP Exam Tip

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]
⚠ Watch Out! When the array has an odd length, the left half gets the extra element. For length 7 split at mid=3: left gets indices 0-3 (4 elements), right gets indices 4-6 (3 elements).

❌ Common Pitfalls

Pitfall 1: Wrong Split Point

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).

Pitfall 2: Merging Out of Order

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.

Pitfall 3: Forgetting the Leftover

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.

Pitfall 4: Confusing Merge Sort with Other Algorithms

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

Score: 0 / 8
1. When merge sort is applied to {5, 2, 8, 1}, what are the two sub-arrays after the first split?
2. What is the result of merging the sorted sub-arrays [3, 7, 9] and [1, 5, 8]?
3. How many total merge operations occur when merge sort processes an array of 8 elements?
4. Which of the following is true about merge sort?
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.
5. During the merge of [2, 6] and [3, 4], how many comparisons are made?
6. Merge sort is applied to {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?
7. Why is merge sort O(n log n) while selection sort is O(n squared)?
8. An array of length 16 is sorted using merge sort. How many levels of recursive splitting occur before all sub-arrays have length 1?

❓ 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.

About the Author: Tanner Crow has 11+ years of AP Computer Science teaching experience, 1,845+ verified tutoring hours, and a 5.0 rating. His students score 5s at over double the national rate. Book a tutoring session →

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]