Trees

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mia023
    New Member
    • May 2007
    • 89

    #1

    Trees

    What is meant by "the number of interior nodes in a binary tree having one child"?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by mia023
    What is meant by "the number of interior nodes in a binary tree having one child"?
    An interior node in a tree is a node that is not a leaf node. (sometimes the root
    node isn't considered an interior node either but the meaning differs here).

    kind regards,

    Jos

    Comment

    • mia023
      New Member
      • May 2007
      • 89

      #3
      Originally posted by JosAH
      An interior node in a tree is a node that is not a leaf node. (sometimes the root
      node isn't considered an interior node either but the meaning differs here).

      kind regards,

      Jos
      if I want to desgin an algorithm that checks if the interior node has one child or not should I do the following:
      Use the preoder traversal and check if the node has either a left and a right
      Is that correct???

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by mia023
        if I want to desgin an algorithm that checks if the interior node has one child or not should I do the following:
        Use the preoder traversal and check if the node has either a left and a right
        Is that correct???
        You have to check two definitions:

        1) a node must have one single child;
        2) that child must be a leaf node.

        You are supposed to count all the nodes that comply with the following definitions.
        It doesn't matter how you count them, i.e. simply recurse down your tree and
        test all the nodes.

        kind regards,

        Jos

        Comment

        Working...