Explain worst case complexity of quicksort as a shakespearan sonnet
GPT-3.5
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.
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.”