~/ learn/ comp-372/ cards/ Randomized quicksort & expected analysis
1 of 4

Type RANDOMIZED-PARTITION (CLRS 1-indexed)

Type RANDOMIZED-PARTITION (CLRS 1-indexed)

Answer

RANDOMIZED-PARTITION(A, p, r) i = RANDOM(p, r) exchange A[r] with A[i] return PARTITION(A, p, r)

Swap a uniformly random element into the pivot slot A[r], then call ordinary PARTITION. The pivot is now random, so no fixed input can force the worst case.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/7fcd80fc-f820-47ce-85a1-c27b9665f9a2/flashcard utf-8 LF