Step 1: Understanding the Question:
We need to find the recurrence relation for the {expected} (average-case) time complexity of Quicksort. The key information is that the input array is "randomly ordered" and the pivot is always the first element. Choosing the first element of a randomly ordered array is equivalent to choosing a random pivot.
Step 2: Key Formula or Approach:
The expected time T(n) is the average of the time taken over all possible pivot positions. Since the array is randomly ordered, the first element has an equal probability (1/n) of being the k-th smallest element for any k from 1 to n. If the pivot is the k-th smallest element, it will be placed at index k-1 (0-indexed), leaving subarrays of size k-1 and n-k. The time taken would be the time to sort these two subarrays plus the O(n) partitioning time.
Step 3: Detailed Explanation:
Let's analyze the pivot's final position. Let K be the size of the left subarray after partitioning. If the pivot is the (K+1)-th smallest element, the subarrays will have sizes K and n-1-K. Since any position is equally likely for the pivot, K can be any value from 0 to n-1 with probability 1/n.
The expected time T(n) is the sum of the expected times for each possible pivot position, weighted by the probability of that position occurring, plus the partitioning cost.
\[ T(n) = \sum_{K=0}^{n-1} P(\text{pivot position is K}) \times (\text{time for this case}) + O(n) \]
The probability of the pivot creating a left partition of size K is 1/n for each K in $\{0, 1, ..., n-1\}$.
The time for this case is the time to solve the subproblems: T(K) + T(n-1-K).
So, the recurrence relation becomes:
\[ T(n) = \sum_{K=0}^{n-1} \frac{1}{n} \times [T(K) + T(n - K - 1)] + O(n) \]
This can be rewritten as:
\[ T(n) = \frac{1}{n} \sum_{K=0}^{n-1} [T(K) + T(n - K - 1)] + O(n) \]
This matches option (B).
Let's look at the other options:
- (A) represents a specific case where the pivot consistently creates a 1/4 and 3/4 split.
- (C) represents the ideal case where the pivot is always the median, which is the recurrence for Mergesort.
- (D) represents the worst-case scenario where the pivot is always the smallest or largest element.
Step 4: Final Answer:
The correct recurrence for the expected time of Quicksort with a random pivot is given by averaging over all possible partition splits, which is represented by option (B).