Question Details

Consider Quick sort algorithm used to sort an array of n distinct randomly ordered element. In every call the pivot is chosen as the first element of the current subarray. Let T(n) denote the expected time to sort the array. Assume that the time to partition is linear in the size of current subarray. Which of the following option represents T(n) in this scenario.

Options

A

T ( n ) = T ( n 4 ) + T ( 3 n 4 ) + O ( n )

B

T ( n ) = 1 n ∑ K = 0 n - 1 [ T ( K ) + T ( n - K - 1 ) ] + O ( n )

C

T ( n ) = 2 T ( n 2 ) + O ( n )

D

T ( n ) = T ( 1 ) + T ( n - 1 ) + O ( n )

Show Answer
Correct Answer
B
T ( n ) = 1 n ∑ K = 0 n - 1 [ T ( K ) + T ( n - K - 1 ) ] + O ( n )

Solution :

The correct option is:
T ( n ) = 1 n ∑ K = 0 n - 1 [ T ( K ) + T ( n - K - 1 ) ] + O ( n )

Step-by-step Explanation:

1. Understanding Quick Sort Partitioning:
In the Quick sort algorithm, we choose a pivot element to partition the subarray of size n. Here, the pivot is chosen as the first element of the current subarray. Since the array contains n distinct elements that are randomly ordered, the chosen pivot is equally likely to end up in any of the sorted positions from index 0 to index n - 1. Specifically, the pivot will partition the array into two subarrays: one of size K (representing elements smaller than the pivot) and one of size n - K - 1 (representing elements larger than the pivot), where K can range from 0 to n - 1 with equal probability.

2. Probability of Pivot Position:
Since the input elements are randomly ordered, each possible size of the left subarray, K (where 0 ≤ K ≤ n - 1), occurs with equal probability:
P ( left subarray size is K ) = 1 n

3. Formulating the Recurrence Relation for Expected Time:
For a fixed partition index K, the time taken to sort the subarray is the sum of:
- The time to sort the left subarray of size K, which is T(K)
- The time to sort the right subarray of size n - K - 1, which is T(n - K - 1)
- The linear time required to perform the partitioning, denoted as O(n)

To find the expected time T(n), we take the weighted average over all possible values of K from 0 to n - 1:
T ( n ) = ∑ K = 0 n - 1 1 n [ T ( K ) + T ( n - K - 1 ) ] + O ( n )

Factoring out the constant probability factor 1 n gives the final expected recurrence relation:
T ( n ) = 1 n ∑ K = 0 n - 1 [ T ( K ) + T ( n - K - 1 ) ] + O ( n )

Transparent Access on Mindyard

Built for Learners & Educators Alike

Completely free for students. Educators & coaching institutes get 2 months free Pro trial to create tests.

FREE FOR STUDENTS

Practice & Learn Free for Students

Access unlimited practice questions, detailed step-by-step solutions, and exam study materials — completely free for students.

  • Unlimited mock tests & question bank practice
  • Full access to curated study library & formula notes
  • 100% free for students • No credit card required
2 MONTHS FREE TRIAL

Educators & Coaching Institutes

Create and conduct professional online assessments with AI question generation, tab proctoring, and comprehensive batch management.

  • AI question uploader & rapid test generator
  • Anti-cheating tab proctoring & performance reports
  • Full Pro access free for 60 days • No upfront commitment
Discover more resources

You may also like

Mock Tests

View All
  • CUET UG
  • intermediate
  • 1 hour

A comprehensive CUET UG Mathematics Question Paper with Solutions – 2 June 2023 (Shift 3) designed to help students practice and understand the actual CUET exam pattern. This paper covers important topics from Algebra, Calculus, Coordinate Geometry, Probability, Statistics, Matrices, Determinants, and Vectors, featuring a balanced mix of conceptual, numerical, and application-based questions. Detailed solutions are provided to strengthen problem-solving skills, improve conceptual clarity, and enhance calculation accuracy. Based on the CUET syllabus and previous year exam trends, this paper is ideal for practice, revision, self-assessment, time management, previous year analysis, and final preparation for upcoming CUET UG Mathematics examinations.

  • CUET UG
  • intermediate
  • 1 hour

A comprehensive CUET Accountancy Question Paper – 20 June 2023 (Shift 2) designed to help students practice and analyze previous year exam patterns for effective CUET preparation. This paper covers important topics including Accounting for Partnership Firms, Company Accounts, Financial Statements Analysis, Cash Flow Statements, Accounting Ratios, and Fundamental Accounting Principles. It features a balanced mix of conceptual, numerical, and application-based questions to strengthen accounting concepts, improve calculation accuracy, and enhance problem-solving skills. Based on the CUET exam structure and syllabus, this paper is ideal for practice, revision, self-assessment, time management, previous year analysis, and final preparation for upcoming CUET Accountancy examinations.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...
Ask your own doubt or choose a quick prompt: