Recurrence equations for Quicksort
Not what you're looking for?
The following recurrence equation gives the expected number of comparisons for Quicksort, given that the "pivot element" is selected uniformly at random from the list:
T(n) = (n - 1) + (1/n)* SUM[i=0,n-1](T(i) + T(n-1-i)), T(0) = 0.
(a) Let S(n) = SUM[i=0,n-1](T(i) + T(n-1-i)). Give Dual recurrence equations expressing T(n) in terms of S(n), and S(n) in terms of S(n-1) and T(n-1).
(b) Evaluate S(n) and T(n) for n = 1, 2, ..., 7.
(c) What are the time and space requirements for computing T(n)?
Purchase this Solution
Solution Summary
Solution applies the concept of memoing to compute T(n), and accordingly works out the time and space requirements for computing T(n) in part (c).
Solution Preview
(a) Since the summation expression in the right hand side of T(n) equation is the complete right hand side of S(n) equation, it is straightforward to express T(n) in terms of S(n).
T(n) = (n-1) + (1/n) S(n), T(0) = 0
Expressing S(n) in terms of S(n-1) and T(n-1) is slightly tricky.
S(n-1) = SUM[i=0 to ((n-1) - 1)] (T(i) + T((n-1) -1 -i))
= SUM[i=0 to (n-2)] T(i) + SUM[i=0 to (n-2)] T((n-1) -(1+i))
= (T(n-1) + SUM[i=0 to (n-2)] T(i)) - T(n-1) + SUM[i=0 to (n-2)] T((n-1) -(1+i))
= SUM[i=0 to (n-1)] T(i) - T(n-1) + SUM[i=0 to (n-2)] T((n-1) -(1+i))
= SUM[i=0 to (n-1)] T(i) - T(n-1) + SUM[(j-1)=0 to (n-2)] T((n-1) -(1+(j-1))) -- Substituting i=j-1
= ...
Purchase this Solution
Free BrainMass Quizzes
Basic Computer Terms
We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.
Word 2010: Table of Contents
Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.
Inserting and deleting in a linked list
This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.
Java loops
This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.
Javscript Basics
Quiz on basics of javascript programming language.