Re: Determining the height of a non-binary tree

[email protected]
Newsgroups gmane.comp.ai.weka
Message-ID <162454082116.117859.18173125034841560991@sys-mailman-prd.its.waikato.ac.nz>
Dear Weka developers,

I have tried using the algorithm from:

https://stackoverflow.com/questions/13476508/non-binary-tree-height

with the following code:

int getHeight(Instances data){
      int height=0;
      if (data==null){
        return 0;
      }
      for (int i=0; i<m_sons.length; i++) {
        height = Math.max(height, getHeight(m_sons[i].m_train));
      }
      return height + 1;
  }

However, the i index does not go beyond 0 and I get a StackOverflowException!
It seems like there are no sentinels in the tree that are equal to null and therefore
I get an infinite recursion! Could you please help?

Thank you in advance,

Spyros Halkidis
_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.