in language C
Code that examine if the tree is full
Tree is full if each node have 2 child
i dont know how to write the code ?
somebody can help me ?

Recommended Answers

All 4 Replies

>i dont know how to write the code ?
Do you know how to do a preorder traversal? Once you have that, it's just a test whether both children are either null or not null. It's a short solution, so I can't give you example code without solving the problem for you.

in language C
Code that examine if the tree is full
Tree is full if each node have 2 child
i dont know how to write the code ?
somebody can help me ?

It seems to me a tree can never be full. The last node(s) will always have two free child positions, won't it?

>The last node(s) will always have two free child positions, won't it?
A full tree in this case is one where every non-leaf node has two non-null children. For example:

a
     /   \
    b     c
   / \   / \
  d   e f   g

is a full tree, but

a
     /   \
    b     c
     \   / \
      e f   g

is not because b is neither a leaf nor has two non-null children.

>The last node(s) will always have two free child positions, won't it?
A full tree in this case is one where every non-leaf node has two non-null children.

{pictire snipped] is not because b is neither a leaf nor has two non-null children.

Oh... OK. I didn't realize that was a definition. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.