Is the root node an internal node?

后端 未结 4 1784
滥情空心
滥情空心 2021-02-20 05:57

So I\'ve looked around the web and a couple of questions here in stackoverflow here are the definition:

  • Generally, an internal node is any node that is not a leaf
相关标签:
4条回答
  • 2021-02-20 06:19

    Yes root node is an internal node.
    [More explanation]

    A root node is never called as a leaf node even if it is the only node present in the tree. For ex. if a tree has only one node then we say that it is a tree with only root node, we never say that the tree has a single leaf node.
    Since internal node means a non-leaf node and because root node is never considered as leaf node I would say that in case of single node tree root node is an internal node.

    0 讨论(0)
  • 2021-02-20 06:25

    Statement from a book : Discrete Mathematics and Its Applications - 7th edition By Rosen says,

    Vertices that have children are called internal vertices. The root is an internal vertex unless it is the only vertex in the graph, in which case it is a leaf.

    Supportive Theorem:

    For any positive integer n, if T is a full binary tree with n internal vertices, then T has n + 1 leaves and a total of 2n + 1 vertices.

    case 1:

          O  <- 1 internal node as well as root
         / \
        O   O <- 2 Leaf Nodes
    

    case 2: Trivial Tree

          O <- 0 internal vertices (no internal vertices) , this is leaf
    
    0 讨论(0)
  • 2021-02-20 06:29

    "A node with no children is a leaf or external node. A non-leaf node is an internal node."

    Source: "Introduction To Algorithms-3rd edition" page number 1176, last line.

    So, root is also an internal node except when it is the only node of the tree.

    0 讨论(0)
  • 2021-02-20 06:38

    IMHO when you are talking about a tree with more than one node we can say the root node is an internal node. When there is only one node (the root node) the question of internal node doesn't arise. Hence we can vacuously say it is an internal node.

    0 讨论(0)
提交回复
热议问题