The caption of the supplied reel gives the duck with a hat a special role: it is the pivot. Smaller values go to one side, larger values to the other, and the process repeats. That is a memorable starting point for quicksort.
The important operation is partitioning. Instead of fixing one neighbouring pair at a time, quicksort groups values around a reference value and sorts the smaller problems that remain.
Watch the source reel
Source reel: Leandro Hirt | Academify (@leandrohirt.oficial), dated 2026-10-04 in Instagram’s accessible post description. Creator and caption were checked on 8 October 2026. This article is an independently researched explanation of the topic, not a transcript or a claim to ownership of the video.
The embedded reel remains hosted by Instagram. Playback may depend on sign-in, browser settings and the creator’s permissions. Use the original-post link if it is unavailable.
A pivot is a value, not necessarily the median
NIST describes quicksort as choosing a pivot, partitioning values and recursively sorting the parts. Implementations differ in pivot selection, handling equal values and whether rearrangement happens inside the original array.
Choosing the item at the middle index is not the same as finding the median value. On an unsorted list, that item could be unusually large or small. The distinction helps explain why some partitions are balanced and others are not.
Partition a small list
Our original example is [7, 2, 9, 4, 1, 4, 6]. The middle-index pivot is 4. Make three groups: lower [2, 1], equal [4, 4], and higher [7, 9, 6].
Sort the lower group to get [1, 2] and the higher group to get [6, 7, 9]. Joining those with the equal group gives [1, 2, 4, 4, 6, 7, 9]. Both copies of 4 remain. A partition alone did not fully sort each group; recursive calls performed that work.
A readable three-way Python version
def quick_sort(values):
if len(values) < 2:
return values[:]
pivot = values[len(values) // 2]
lower = [x for x in values if x < pivot]
equal = [x for x in values if x == pivot]
higher = [x for x in values if x > pivot]
return quick_sort(lower) + equal + quick_sort(higher)
print(quick_sort([7, 2, 9, 4, 1, 4, 6]))
# [1, 2, 4, 4, 6, 7, 9]This teaching version builds new lists and returns a new result. It assumes ordinary comparable values such as integers. The equal group prevents repeated pivot values from being lost or repeatedly sent into another partition.
It is not an in-place quicksort. List comprehensions and concatenation allocate storage. An implementation that rearranges one array has different memory behaviour and requires more careful index handling. Do not attach its space-complexity claim to this example.
Why recursive calls do not erase their parents
A reader question visible under the reel asks whether making another call replaces the earlier lists. Each call has its own local bindings. The parent waits while a child computes its result; the returned lists are then combined in the parent’s expression.
The base case handles lists shorter than two items. Because the pivot’s equal group contains at least that pivot for normal integer inputs, the lower and higher groups are smaller than the input. That is the progress needed for termination. Very deep recursion can still hit Python’s recursion limit.
The reader’s question is a learning prompt, not evidence of a defect in the reel. Our explanation applies to the code printed here.

Quick does not mean fastest on every input
Standard quicksort has typical O(n log n) time but can degrade to O(n²) with repeatedly poor partitions. Randomised pivot selection can reduce dependence on a particular input ordering; it is not a promise of the same runtime on every run.
Our educational version also pays for allocation and concatenation. Its memory use grows with the lists retained during recursion, and badly unbalanced partitions can be especially wasteful. Benchmark the actual implementation rather than only comparing algorithm names.
What to use after the lesson
For ordinary Python tasks, start with the documented built-in sorting functions. They support key functions and stable sorting; you do not need to implement quicksort to arrange a list of records.
The code above was checked against sorted() on empty, repeated, already ordered, reversed and random integer lists. Those checks support the example’s behaviour, not a claim that it is production-optimised.
Watch the pivot, then watch the smaller subproblems. Once those two ideas make sense, recursion becomes a concrete sequence of smaller tasks rather than a mysterious function calling itself.
