Friday, June 2, 2023
HomeSoftware DevelopmentGood Binary Tree - GeeksforGeeks

# Good Binary Tree – GeeksforGeeks

What’s a Good Binary Tree?

An ideal Binary Tree is a binary tree during which every of the inner nodes has precisely two youngster nodes and all of the leaf nodes are located on the similar stage of the tree.

In different phrases, it may be stated that every stage of the tree is totally stuffed by the nodes.

Examples of Good Binary Tree:Â

Instance of a Good Binary Tree

A tree with solely the foundation node can be an ideal binary tree. Â  Â Â

Instance-2

The next tree will not be an ideal binary tree as a result of the final stage of the tree will not be fully stuffed.

Not a Good Binary Tree

Properties of a Good Binary Tree:

• Diploma: The diploma of a node of a tree is outlined because the variety of kids of that node. All the inner nodes have a level of two. The leaf nodes of an ideal binary tree have a level of 0.
• Variety of leaf nodes: If the peak of the proper binary tree is h, then the variety of leaf nodes might be 2h as a result of the final stage is totally stuffed.
• Depth of a node: Common depth of a node in an ideal binary tree is Î˜(ln(n)).
• Relation between leaf nodes and non-leaf nodes: No. of leaf nodes = No. of non-leaf nodes +1.
• Complete variety of nodes: A tree of peak h has complete nodes = 2h+1 â€“ 1. Every node of the tree is stuffed. So complete variety of nodes might be calculated as 20 + 21 + . . . + 2h = 2h+1 â€“ 1.
• Peak of the tree: The peak of an ideal binary tree with N variety of nodes = log(N + 1) â€“ 1 = Î˜(ln(n)). This may be calculated utilizing the relation proven whereas calculating the whole variety of nodes in an ideal binary tree.

Verify whether or not a tree is a Good Binary Tree or not:

• Discover the depth of any node (within the under tree we discover the depth of the leftmost node). Let this depth be d.
• Now recursively traverse the tree and verify for the next two circumstances.
• Each inside node ought to have each kids non-empty.
• All leaves are at depth d

For extra details about this confer with the article article: Verify whether or not a given binary tree is ideal or not

RELATED ARTICLES