Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6536765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:32:00+00:00 2026-05-25T10:32:00+00:00

I am reading a chapter on trees in book on Data structures and Algorithms

  • 0

I am reading a chapter on trees in book on Data structures and Algorithms by Mark Allen Weiss. Here is text snippet.

Let D(n) be the internal path length for some tree T of n nodes. D(1)
= 0. An n-node tree consists of an i-node left subtree and an (n – i
– 1)-node right subtree, plus a root at depth zero for 0<= i < n. D(i)
is the internal path length of the left subtree with respect to its
root. In the main tree, all these nodes are one level deeper. The same
holds for the right subtree. Thus, we get the recurrence

D(n) = D(i) + D(n – i -1) + n -1

If all subtree sizes are equally likely, which is true for binary
search trees (since the subtree size depends only on the relative rank
of the first element inserted into the tree), but not binary trees,
then the average value of both D(i) and D(n – i -1) is (1/n) sum from
j =0 to n-1 of D(j). This yields

D(n) = (2/n)(sum from j = 0 to n-1 of D(j)) + (n-1).

The above recurrence obtains an average values of D(n) = O(nlogn).

Following are my questions on above text snippet.

  1. What does author mean “since subtree size depends only on the relative rank of the first element inserted into the tree” ?
  2. How author achieved average value O(nlogn) from D(n)? Can any one please show me steps involved in achieving the mentioned result?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:32:00+00:00Added an answer on May 25, 2026 at 10:32 am

    About your first point :

    In a binary tree the size of the left subtree correspond to the number of element smaller than the root and the size of the right subtree to the element larger than the root.

    Therefore the subtree size deponds only on the relative rank of the first element inserted.

    About your second point I don’t have the solution but I would start this way:

    You can first transfor the sum :

    you know that sum(j=0 to n, of j ) = n*(n-1)/2

    then n-1 = 2/n*sum(j=0 to n-1, of 1 ) +2/n*n = 2/n*sum(j=0 to n-1, of j ) + 2

    Since D(n) = (2/n)(sum from j = 0 to n-1 of D(j)) + (n-1), you get the new formula

    D(n) = (2/n)(sum from j = 0 to n-1 of (D(j) + j)) + 2 (1)
    

    now you can express Dn in term of Dn-1

    you would find (if i’m right):

    D(n)= (n+1)/n*D(n-1) + 2  (2)
    

    Then try to express Dn as n*Sum(1/k) which is equivalent to nln(n)…

    from the above formula (2) you get (you can try to write it):

    D(n) = n+1 * SUM( 2 /k for k=1 to n) +2 ... which is a O(n ln(n))
    

    tell me if you have more questions on this proof

    Hope it helps


    EDIT: details on (2)

    D(n) = (2/n)(sum from j = 0 to n-1 of (D(j) + j)) + 2
    
    => D(n) = (2/n)(sum from j = 0 to n-2 of (D(j) + j)) + 2 + (2/n)*(D(n-1)+n-1)
    
    => D(n) = ((n-1)/n)* [ 2/(n-1) *(sum from j = 0 to n-2 of (D(j) + j)) + 2]  + 2 + (2/n)*D(n-1)
    
    note: the +2 between the brackets comes  from (2/n)*(D(n-1)+n-1) =  (2/n)*D(n-1) + 2 *(n-1)/n
    
    between the brackets [] you have D(n-1) then :
    
    =>  D(n) = ((n-1)/n)* D(n-1)  + 2 + (2/n)*D(n-1)
    
    => D(n) = (n+1)/n*D(n-1) + 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading the book Think Python by Allen Downey. For chapter 4, one
I'm reading the Cormen algorithms book (binary search tree chapter) and it says that
while reading the chapter on basic operations on sets from the book of data
I'm currently reading chapter 5.8 of Dive Into Python and Mark Pilgrim says: There
I was reading the example chapter from the book by Ayende and on the
I am reading the book -- Hadoop: The Definitive Guide In chapter 2 (Page
I'm reading the Book Java Concurrency in Practice . In chapter 15, they are
So I started reading this book: http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022 On chapter 2 it explains about the
Guys from book C++ GUI programming with qt I'm reading a chapter on how
Am reading an O'Reilly book called Learning WCF and in chapter one, it mentions:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.