answersLogoWhite

0


Best Answer

Something like this:

int depth (const Tree *root)

{

int l, r;

if (root==NULL) return 0;

l= depth (root->left);

r= depth (root->right);

if (l>r) return return 1+l;

else return 1+r;

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

You recursively descend the tree, taking every possible path, counting the number of nodes, finding the maximum.

Well, that's how to measure it. To calculate it, consider this...

For an ideally balanced binary tree of depth D, the number of nodes N is 2D - 1. Solving for D...

N = 2D - 1

N + 1 = 2D

log2 (N + 1) = D

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Weigh it, calculate its volume, then calculate density.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you calculate tree density?
Write your answer...
Submit
Still have questions?
magnify glass
imp