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

closed account (STR9GNh0)
hi, anywhere i can get help on the above? thanks.
Last edited on
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;
}
closed account (STR9GNh0)
arranging the range of any numbers accordingly based on inorder transversal of the heap
Last edited on
Are you? That's nice.
closed account (STR9GNh0)
is there anyway to do without a pointer insteaD?
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.