Implementation of a binary tree, Data Structure & Algorithms

Assignment Help:

Like general tree, binary trees are implemented through linked lists. A typical node in a Binary tree has a structure as follows

struct NODE

{

struct NODE *leftchild;

int nodevalue;               /* this can be of any data type */

struct NODE *rightchild;

};

805_IMPLEMENTATION OF A BINARY TREE.png

Figure: Node structure of a binary tree

The 'left child 'and 'right child' are pointers to another tree-node. The "leaf node" (not shown) here will have NULL values for these pointers.

The binary tree creation follows a extremely simple principle. For the new element to be inserted, compare it along with the current element in the tree. If its value is less than the present element in the tree, then move to the left side of that element or else to its right. If there is no sub tree at the left, then make your new element as the left child of that present element or else compare it to the existing left child and follow the similar rule. Exactly, the same need to done for the case while your new element is greater than the current element into the tree however this time with the right child. Though this logic is followed for the formation of a Binary tree, this logic is frequently suitable to search for a key value in the binary tree.

Following is algorithm for the implementation of Binary tree:

Step-1: If new element < current element, then go to step-2 or else go to step -3

Step-2: If the current element does not contain a left sub-tree, then converts new element into the left child of the current element; else make the existing left child as your current element and go to step-1

Step-3: If the current element does not contain a right sub-tree, then converts new element into the right child of the present element; else make the existing right child as your existing element and go to step-1


Related Discussions:- Implementation of a binary tree

What is algorithms optimality, What is algorithm's Optimality? Optimali...

What is algorithm's Optimality? Optimality  is  about  the  complexity  of  the  problem  that  algorithm  solves.  What  is  the  minimum amount  of  effort  any  algorithm  w

Explain about the structured types - built-in types, Explain about the Stru...

Explain about the Structured types - Built-In Types Values of the carrier set are not atomic, consisting rather than several atomic values arranged in some way. Common illu

Merge sort, Merge sort is a sorting algorithm which uses the basic idea of ...

Merge sort is a sorting algorithm which uses the basic idea of divide and conquers. This algorithm initially divides the array into two halves, sorts them separately and then merge

Give example of assertion and abstract data type, Give example of assertion...

Give example of assertion and abstract data type For illustration, consider Natural ADT whose carrier set is the set of non-negative integers and whose operations are the usual

Algorithm for determining strongly connected components, Algorithm for dete...

Algorithm for determining strongly connected components of a Graph: Strongly Connected Components (G) where d[u] = discovery time of the vertex u throughout DFS , f[u] = f

Multikey file organization, what are the applications of multikey file orga...

what are the applications of multikey file organization?

Pre-order and post order traversal of a binary tree, The pre-order and post...

The pre-order and post order traversal of a Binary Tree generates the same output. The tree can have maximum One node

Life science, Define neotaxonomy. Discuss how electron microscopy can help ...

Define neotaxonomy. Discuss how electron microscopy can help in solving a zoological problem faced by taxonomist.

Complexity, Complexity : How do the resource needs of a program or algorith...

Complexity : How do the resource needs of a program or algorithm scale (the growth of resource requirements as a function of input). In other words, what happens with the performan

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd