create your own

Creating a Binary Tree from a General Tree

64
rate or flag this page

By aesthunter

A general Binary Tree
A general Binary Tree

Let us list the properties of binary trees:

1) Recall from the previous section the definition of internal and external nodes.- A binary tree with
   N internal nodes has maximum of (N + 1) external nodes : Root is considered as an internal node.
2) The external path length of any binary tree with N internal nodes is 2N greater than the internal
   path length.
3) The height of a full binary tree with N internal nodes is about log2N
As we shall see, binary trees appear extensively in computer applications, and performance is best when the
binary trees are full (or nearly full). You should note carefully that, while every binary tree is a tree, not
every tree is a binary tree.
A full binary tree or a complete binary tree is a binary tree in which all internal nodes have degree and all
leaves are at the same level. The figure 6a illustrates a full binary tree.
The degree of a node is the number of non empty sub trees it has. A leaf node has a degree zero.

Converting Process

Since the references now access either the first child or successive siblings, the process must use this type of information rather than magnitude as was the case for the binary search tree. Note that the resulting tree is a binary tree but not a binary search tree.


The process of converting the general tree to a binary tree is as follows:


* use the root of the general tree as the root of the binary tree

* determine the first child of the root. This is the leftmost node in the

general tree at the next level

* insert this node. The child reference of the parent node refers to this

node

* continue finding the first child of each parent node and insert it below

the parent node with the child reference of the parent to this node.

* when no more first children exist in the path just used, move back to the

parent of the last node entered and repeat the above process. In other

words, determine the first sibling of the last node entered.

* complete the tree for all nodes. In order to locate where the node fits

you must search for the first child at that level and then follow the

sibling references to a nil where the next sibling can be inserted. The

children of any sibling node can be inserted by locating the parent and then

inserting the first child. Then the above process is repeated.

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working