C++ array to calculate height, level and depth of the root of the heap

Apr 24, 2011 at 12:51pm
closed account (STR9GNh0)
hi, anywhere i can get help on the above? thanks.
Last edited on Apr 27, 2011 at 4:12pm
Apr 24, 2011 at 1:21pm
What is the array for?
The height of any tree is the height of it's highest child + 1.
If your heap is binary,
1
2
3
4
int height( node* root ){
   if( ! root ) return 0;
   else return max( height(root->left), height(root->right) ) +1;
}
Apr 24, 2011 at 1:58pm
closed account (STR9GNh0)
arranging the range of any numbers accordingly based on inorder transversal of the heap
Last edited on Apr 24, 2011 at 1:59pm
Apr 24, 2011 at 2:19pm
Are you? That's nice.
Apr 27, 2011 at 4:12pm
closed account (STR9GNh0)
is there anyway to do without a pointer insteaD?
Apr 27, 2011 at 4:52pm
Oh. So you've flattened your heap into an array?
If the height of a complete binary tree is h, the number of nodes in it n = 2h-1 from which you can easily find h.
Topic archived. No new replies allowed.