Question: Let T be a (possibly improper) binary tree with n nodes, and let D be the sum of the depths of all the external nodes

Let T be a (possibly improper) binary tree with n nodes, and let D be the sum of the depths of all the external nodes of T. Describe a configuration for T such that D is Ω(n2). Such a tree would be the worst case for the asymptotic running time of method heightBad (Code Fragment 8.4).

/** Returns the height of the tree. */ 1 private int heightBad() { int h = 0; // works, but quadratic worst-case time fo

/** Returns the height of the tree. */ 1 private int heightBad() { int h = 0; // works, but quadratic worst-case time for (Position p: positions()) 5 4 if (isExternal(p)) // only consider leaf positions h = Math.max(h, depth(p)); return h;

Step by Step Solution

3.47 Rating (167 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Let T 1 be a tree of n2 nodes in a sin... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Algorithms Questions!