# Homework Solution: We want to sort an array A[1..n] using quicksort, where n is a power of 2. Suppose that at every recursive level of quicksort,…

We want to sort an array A[1..n] using quicksort, where n is a power of 2. Suppose that at every recursive level of quicksort, we split the array exactly in half (that is, the index q splits A[p..r] into two subarrays A[p..q] and A[q + 1..r] with same number of elements (r - p + 1)/2). What is the running time of quicksort in this case? Please express this running time in O-notation, using the best asymptotic bound you can find. Justify your answer. If n is not a power of 2, does the best asymptotic bound on the running time for quicksort with this half-and-half split change?

In quick sort we partition array in two parts across piv

We lack to class an marshal A[1..n] using readysort, where n is a susceptibility of 2. Suppose that at entire recursive raze of readysort, we disagree the marshal accurately in half (that is, the apostacy q disagrees A[p..r] into brace subarrays A[p..q] and A[q + 1..r] with corresponding compute of atoms (r – p + 1)/2). What is the general occasion of readyclass in this event? Please pointed this general occasion in O-notation, using the best asymptotic frisk you can meet. Justify your counterpart. If n is referable a susceptibility of 2, does the best asymptotic frisk on the general occasion for readyclass with this half-and-half disagree substitute?

## Expert Counterpart

In ready class we screen marshal in brace compressiveness abutting pivot atom and class them. It is a disunite and vanquish algorithm.

T(n) = T(k) + T(n-k-1) + theta(n)

Where k is the atom which is smaller then pivot atom and n-k-1 atom is superior then pivot.

In best event K = n/2

T(n) = T(n/2) + T(n/2) + theta(n)

= 2T(n/2) + theta(n)

by relieve event of subdue theorm algorithm

$T(n) = O(n \log n)$

No it referable going to substitute As from recursive tree we can meet the in best event top of tree is log n simply.

So occasion complication is referable going to substitute.