Processing math: 28%
Google
 
Web unafbapune.blogspot.com

Friday, December 20, 2013

 

Quicksort Recurrence

Assume array of size N with entries distinct and randomly ordered. Let CN be the expected number of compares used by quicksort. Starting with the recurrence relation:
  CN=N+1+Nk=11N(Ck1+CNk)C0=0=N+1+2NNk=1Ck1by symmetryNCN=N(N+1)+2Nk=1Ck1(N1)CN1=(N1)N+2N1k=1Ck1for N1 instead of NNCN(N1)CN1=2N+2CN1subtract the last two equationsNCN=(N+1)CN1+2Nnote it's now linear time, not quadratic!CNN+1=CN1N+2N+1divide both sides by N(N+1)CNN+1=CN1N+2N+1=CN2N1+2N+2N+1telescopeCNN+1=C12+23++2N+2N+1note C1=2CN=(N+1)(1+23++2N)+2CNN(1+23++2N)f(x)g(x) meanslim
Source: Analysis of Algorithm


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?