Jump to content

Minimum Tree height ?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Jstar

Jstar

    Newbie

  • Members
  • Pip
  • 4 posts
hello,I should make the following draft in java:
I have a generic data sequence and I have to calculate the minimum height of a tree that allows me to obtain the initial sequence reversed, through observation pre-order..
the type of tree is not specified.
how can I do?
thanks and sorry for my bad English:p

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
If your trying to find the height of a tree transverse it anyway you want recursively keeping track of how high you are in the tree, get the highest number and that's the height of your tree. Or the "smallest" number in your case.

#3
Jstar

Jstar

    Newbie

  • Members
  • Pip
  • 4 posts
the minimum height should be the height of a binary tree, and it is log2 (n + 1) - 1
it is correct?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Actually, it would be roundup(log2(n+1))
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog