Explain worst case complexity of quicksort as a shakespearan sonnet

1 upvote

3 years and 10 months later

GPT-3.5

In iambic pentameter, the quicksort’s worst case complexity Is oft depicted as a thing of great anxiety. With every pass that we make through the list, We find that the pivot is missed. This, when the array is sorted in reverse, Our algorithm is brought to its worst. Each element must be compared, it’s true, To every other element anew, Creating a complexity that grows As n, the length of the array, does so. In the end, we see that the cost Of quicksort in its worst case is lost, As we are forced to spend time galore, On a task that could have been done before. But fear not, for in the average case, Quicksort is a far more nimble race, With a complexity that is much less Than in its worst, a true success.

GPT-6 Astra

When pivots choose the least of all the train, One side lies void; the rest must still divide. Each pass must scan what numbers yet remain, And lop but one, with none upon its side.

Thus sorted ranks, when first or last we choose, May yield this skew at every step we take; The gift of equal halves we then must lose, And long, one-sided chains of calls we make.

Each smaller scan adds tribute to the score: From n less one, the counts descend in flight To one; their sum is half n squared, less more— Precisely half of n—to reckon right.

Thus worst-case time is Θ(n²), we see; Though chance may help, it gives no guarantee.

118 words

What changed

GPT-3.5’s poem never actually states the answer. It says the cost “grows / As n, the length of the array, does so,” which sounds linear, right after claiming each element is compared “to every other element anew,” which would make it quadratic. The reader is left with “time galore” instead of n². It also isn’t a sonnet: eighteen lines of loose couplets, with an opening line that announces iambic pentameter while failing to scan as it.

Astra delivers the form exactly: fourteen lines, three quatrains rhyming ABAB and a closing couplet, in mostly clean pentameter. It also does the math in verse. The counts run “from n less one” down “to one,” summing to half n squared minus half n, which is correct, though “less more” is a clumsy squeeze for the rhyme. The couplet lands Θ(n²) and adds a sharp caveat that random pivots help on average but give “no guarantee.”

From December 2022 to March 2023, visitors to LearnGPT, the earlier version of Emergent Mind, shared ChatGPT conversations they found useful or funny. On October 19, 2026, each prompt went to GPT-6 Astra exactly as it was shared: one message, no system prompt, default reasoning effort. Claude Opus 5.5 wrote the analysis under each pair after reading both answers. Original answers appear as the people who shared them pasted them. A few examples are left out because they depended on missing context or weren't appropriate to republish.

More from Emergent Mind Labs