Can one GAA score help you sort a whole list of scores, even when some are tied?
You’ve got a list of points scored by teams in a GAA blitz, and some teams scored the same number of points. Could you use the first score to split the list into groups that are easier to sort?
In bubble sort, you compare neighbours and swap them if they’re out of order. In insertion sort, you compare a new item with items in the sorted part to find where it fits. Quicksort also uses comparisons. This time, one chosen value guides a whole pass.
Use the first score, five, as your reference. Scan from left to right, including that first five. Two goes in the lower group, the next five joins the first, seven goes higher, and one joins the lower group after two. Five is the pivot, and this pass is called partitioning.
Use the first value, four, as the pivot. Read four, six, four, three from left to right, including the pivot itself. What goes into the equal group? Pick the matching group.
First check the list size. If it has zero or one item, return it unchanged. Otherwise, partition it and apply quicksort to each outer group. Calling the same algorithm on smaller lists is recursion. Leave the equal group as it is and join the sorted lower group, the equal group, then the sorted higher group.
Start with six, nine, four, six, two, eight. Pivot six gives four and two, two sixes, then nine and eight. Pivot four leaves two on the left and nothing on the right. Both lists return unchanged, giving two, four. Pivot nine gives eight, nine the same way. Join them around both sixes.
Now use the same convention on five, eight, three, five, two, seven. Start with five as the pivot, then apply quicksort to both outer groups before joining. Which list does quicksort return? Pick one.
It’s tempting to join the groups as soon as you’ve split them. Here, three and two are both below five, yet three still comes before two. The split put each key on the correct side of the pivot. The recursive calls fix the order within each outer group.
With nine distinct keys, a middle pivot leaves four per side. Balanced splits give about log n levels, each scanning at most n keys, so time grows as n log n. The smallest key leaves zero and eight. Repeating that scans lists of size n down to two, giving n squared growth.
If a question asks you to trace the execution of quicksort, follow the pivot rule given and record each pivot. Show the three groups for each partition. Then show what each recursive call returns, including the unchanged lists from the base cases. Finish by showing how the groups join.