Is it possible to have an infix expression in a Ternary Tree and above?
Hi All,
Is it possible to have an infix expression in a ternary tree?
I am asking this because in a binary tree the infix expression is defined as visiting the left of the root, then the root, after that the right of the root. But in a ternary tree since there are 3 child nodes for each root, when should the root node be visited in order to make it infix.
I dont know any practical use of such a tree but it is a question that was once asked in an interview. any information regarding this will be great.
Re: Is it possible to have an infix expression in a Ternary Tree and above?
Seems to me that a ternary tree could be used the same way as a binary tree is used - by, for example, ignoring the right-most child (keeping it NULL) of each node, and considering the left-most and middle children to be left child and right child in accordance.
Or am I not getting your question right ?
Regards,
Zachm
Re: Is it possible to have an infix expression in a Ternary Tree and above?
<quote>
Zachm Seems to me that a ternary tree could be used the same way as a binary tree is used - by, for example, ignoring the right-most child (keeping it NULL) of each node, and considering the left-most and middle children to be left child and right child in accordance.
Or am I not getting your question right ?
<quote>
That would be like using a binary tree itself... But i am talking about a ternary or any higher order tree where there are odd number of children as its nodes here...