CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Question 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.

  2. #2
    Join Date
    Oct 2006
    Posts
    616

    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

  3. #3
    Join Date
    Mar 2011
    Posts
    2

    Smile 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...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured