Maggie HTTN
Visual Algorithms • Sorting

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

Common breakdown
Beginners don’t understand partition: they can’t track the pivot, the “i/j pointers,” or why swapping is happening. Recursion makes it feel like the algorithm “jumps around.”
Key questions learners ask
“Why did those two swap?”, “Where is the pivot going?”, “What part is done?”, “Which subarray is next?”

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

Learning goals
  • 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).
Success signals
  • 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

Read this while watching: the key is PARTITION. If learners understand partition, recursion becomes simple.
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

Time
Best / Avg: O(n log n), Worst: O(n²)
Space
O(log n) average (recursion stack)
Stability
Not stable (swaps can reorder equals)

How the animation maps to the code

Pivot as an anchor
The pivot should be visually distinct (color/outline/label), because it is the “story center” of partition: everything else is compared to it.
Swap = evidence of partition logic
Swaps aren’t random: they move values to the correct side of the pivot. Each swap should be paced so learners can explain “why that swap.”
Boundary / regions
A strong visualization shows a boundary: left ≤ pivot and right ≥ pivot. Even a subtle spacing cue helps learners track progress.
Recursion as “focus shift”
Recursion should feel like moving the spotlight to a smaller subarray (not “teleporting”). The UI should clearly indicate: “now sorting left” vs “now sorting right.”

Partition example (pivot “locks in”)

Array: [4, 3, 1, 5, 2]

Choose the pivot as the last element: pivot = 2.

  1. Compare each value to 2.
  2. Move values < 2 to the left (only 1).
  3. Place the pivot immediately after them.
After partition:
[1, 2, 4, 5, 3]

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)

1) Choose a pivot
Start by naming the pivot rule (e.g., last element). Tell learners: “the pivot’s goal is to find its final home.”
2) Partition the array
Show how elements move left/right relative to the pivot. This is the main concept to master.
3) Recurse on subarrays
Once pivot locks, recursion becomes “do the same thing on the left, then on the right.”

UX/UI • Pedagogy • HCI

Quick Sort is often “hard” because learners lose their place. The UX work here is about orientation, cues, and pacing.

UX/UI design choices
  • 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.

Pedagogy (teaching strategy)
  • 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.

HCI principles applied
  • 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)

Method
10–15 minute micro test with 3–5 learners: ask them to narrate what’s happening and where recursion goes next.
Tasks
  • 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.
Metrics
Time-to-correct explanation, number of confusion points, and a 1–5 confidence score after the demo. (Enough evidence for a micro case study on this site.)

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.