Quick Sort
Pick a Pivot, Partition, then Recurse
Quick Sort is a divide-and-conquer algorithm. The key learning moment is the partition step: the pivot is placed in its final position, and the array is split into left (smaller) and right (greater) regions.
This page is a micro UX/HCI case study: it’s designed to reduce confusion by making the pivot, partition boundary, and “what changed” visually obvious while the animation runs.
Overview
Quick Sort is fast in practice and conceptually powerful because it shows how one operation (partition) can create structure: once the pivot is placed, it never moves again.
This page teaches Quick Sort using a scaffolded flow: Choose Pivot → Partition → Recurse. The UX goal is to make the algorithm feel trackable by showing: (1) where the pivot is, (2) which region is being processed, and (3) what the next action is.
The learning problem
Users & context
- Primary: beginners learning sorting and recursion.
- Secondary: instructors/TAs who need a clean artifact for demos and critique.
- Environment: lecture projection, self-study, or short lab activities.
Goals & success criteria
- Explain what partition guarantees: pivot ends in final position.
- Track left vs right regions created by the pivot.
- Describe what recursion does (solve smaller subproblems).
- Students can identify pivot and partition boundary during the demo.
- Students can predict next step: “recurse left” or “recurse right.”
- Students answer a short checkpoint after the animation.
Demo / Media
Quick Sort Animation
Watch for three cues: pivot selection, partition swaps, and the moment the pivot locks into place. That “lock” is the core mental model: pivot is done, then we solve left/right.
Pseudocode
QUICK-SORT(A, low, high):
if low < high:
p = PARTITION(A, low, high)
QUICK-SORT(A, low, p - 1)
QUICK-SORT(A, p + 1, high)
PARTITION(A, low, high): // Lomuto partition scheme
pivot = A[high]
i = low - 1
for j = low to high - 1:
if A[j] <= pivot:
i = i + 1
swap A[i], A[j]
swap A[i + 1], A[high]
return i + 1
Complexity
How the animation maps to the code
Partition example (pivot “locks in”)
Array: [4, 3, 1, 5, 2]
Choose the pivot as the last element: pivot = 2.
- Compare each value to 2.
- Move values < 2 to the left (only 1).
- Place the pivot immediately after them.
UX mental model: once the pivot is placed, it is done forever — it will never move again. Now we only sort the left and right sides.
Teaching flow (scaffolded)
UX/UI • Pedagogy • HCI
Quick Sort is often “hard” because learners lose their place. The UX work here is about orientation, cues, and pacing.
- Pivot emphasis: pivot is a constant reference point (anchored + labeled).
- Progressive disclosure: one idea at a time (pivot → partition swaps → pivot locks → recurse).
- Region clarity: subtle boundary or spacing shows left/right regions.
- Change focus: highlight only the elements involved in the current swap (avoid highlight noise).
- Consistent pattern: same page structure across algorithms reduces reading friction.
- Chunking: teach partition first (as a standalone skill), then introduce recursion.
- Prediction prompts: “Will this element go left or right of pivot?”
- Checkpoint questions: ask learners to name the pivot index after partition.
- Mental models: “pivot finds home” + “solve smaller parts” makes recursion predictable.
- Recognition over recall: pivot + boundary cues reduce working-memory load.
- Feedback: after each partition, show a clear “pivot locked” moment.
- Cognitive load control: avoid showing multiple recursion frames at once.
Evaluation plan (lightweight but real)
- Point to the pivot and predict where it will land.
- After partition: mark left vs right region correctly.
- Identify which subarray the algorithm processes next.
Iteration note: If learners confuse partition, add stronger cues (pivot label, region boundary), slow the swaps slightly, and insert a short “pivot locked” caption before recursing.