answersLogoWhite

0

The root of the tree is stored in array element [0];

for any node of the tree that is stored in array element [i],

its left child is stored in array element [2*i],

its right child at [2*i+2]

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

Which is faster binary tree or binary search tree?

A tree doesn't do anything so it has no speed...


Describe how an array may be used to effectively represent a complete binary tree?

First you have to sort the array. Once that is done, you can use binary search to locate any value. To achieve this, start at the middle element (this represents the root of the tree). If the value you seek is here, you are done. Otherwise if it is less than this element, the value must be in the left portion of the array, otherwise it must be in the right portion of the array. Repeat the process using the appropriate sub-array, starting with the middle element of that sub-array. Eventually you will either locate the value or the sub-array will be empty, in which case the value does not exist. This is effectively the same as starting from the root of a balanced binary tree and traversing left or right through the nodes to locate your value. Each traversal eliminates half the remaining values and the node you arrive at is the root of the sub-tree where your value must reside (if it exists).


Algorithm to determine if a binary tree is complete binary?

There are many ways of checking for a complete binary tree. Here is one method:1. Do a level order traversal of the tree and store the data in an array2. If you encounter a nullnode, store a special flag value.3. Keep track of the last non-null node data stored in the array - lastvalue4. Now after the level order traversal, traverse this array up to the index lastvalue and check whether the flag value is encountered. If yes, then it is not a complete binary tree, otherwise it is a complete binary tree.


Complexity of an algorithm in data structure?

* search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1) * search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1)


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.

Related Questions

Which is faster binary tree or binary search tree?

A tree doesn't do anything so it has no speed...


Describe how an array may be used to effectively represent a complete binary tree?

First you have to sort the array. Once that is done, you can use binary search to locate any value. To achieve this, start at the middle element (this represents the root of the tree). If the value you seek is here, you are done. Otherwise if it is less than this element, the value must be in the left portion of the array, otherwise it must be in the right portion of the array. Repeat the process using the appropriate sub-array, starting with the middle element of that sub-array. Eventually you will either locate the value or the sub-array will be empty, in which case the value does not exist. This is effectively the same as starting from the root of a balanced binary tree and traversing left or right through the nodes to locate your value. Each traversal eliminates half the remaining values and the node you arrive at is the root of the sub-tree where your value must reside (if it exists).


How do you represent binary search and linear search in graphics using c plus plus?

Linear search usually implies the data sequence is in an unsorted order or does not provide random access iterators (such as a list). Essentially you start from the beginning and traverse through each element until you find the element you are looking for, or reach the "one-past-the-end" iterator (which means the value does not exist). With binary search you use a sorted sequence, such as a sorted array. You start in the middle of the sequence. If the value is not there, you know which half of the array the value must be in, so you start in the middle of that half. By eliminating half the array (or sub-array) each time you will either find the value or you end up with an empty sub-array (which means the value does not exist). You can also use binary search on a binary tree which achieves the same thing, but the tree must be perfectly balanced (such as a red/black tree) to be of benefit.


Algorithm to determine if a binary tree is complete binary?

There are many ways of checking for a complete binary tree. Here is one method:1. Do a level order traversal of the tree and store the data in an array2. If you encounter a nullnode, store a special flag value.3. Keep track of the last non-null node data stored in the array - lastvalue4. Now after the level order traversal, traverse this array up to the index lastvalue and check whether the flag value is encountered. If yes, then it is not a complete binary tree, otherwise it is a complete binary tree.


Can you implements tree using array?

yes you can....


Code for binary trees written in C using graphics?

cg code for binary tree


Complexity of an algorithm in data structure?

* search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1) * search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1)


If a CBT is stored using array , then what is the parent node of element stored at index 11?

In a complete binary tree (CBT) stored using an array, the parent of an element at index i can be found at index (i-1)/2, assuming the array is 0-indexed. So for an element stored at index 11, the parent node would be stored at index (11-1)/2 = 5.


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.


How many types of binary tree?

A binary tree is type of tree with finite number of elements and is divided into three main parts. the first part is called root of the tree and itself binary tree which exists towards left and right of the tree. There are a no. of binary trees and these are as follows : 1) rooted binary tree 2) full binary tree 3) perfect binary tree 4) complete binary tree 5) balanced binary tree 6) rooted complete binary tree


What is binary search in data structure using c?

a tree which has atmost two nodes is called binary tree binary search tree is a binary tree which satisfies the following 1.every node in tree must be distinct 2.values in right subtree > value at root 3.values in left subtree < value at root 4.left,right subtrees must be binary search trees


Copy of binary tree?

Is another binary tree.


Are binary tree and binary tree same?

Yes.


Is a full binary tree the same as a complete binary tree, or are there differences between the two structures?

A full binary tree is a type of binary tree where each node has either 0 or 2 children. A complete binary tree is a binary tree where all levels are fully filled except possibly for the last level, which is filled from left to right. So, a full binary tree can be a complete binary tree, but not all complete binary trees are full binary trees.


When converting binary tree into extended binary tree all the original nodes in binary tree are?

will remain same


Does binary tree and binary search tree same?

no they are not same


What are the application of binary tree in computer science?

What are the applications of Binary Tree.


What is meant by left skewed binary tree?

a binary tree with only left sub trees is called as left skewed binary tree


What is an almost complete binary tree?

An almost complete binary tree is a tree in which each node that has a right child also has a left child. Having a left child does not require a node to have a right child. Stated alternately, an almost complete binary tree is a tree where for a right child, there is always a left child, but for a left child there may not be a right child.The number of nodes in a binary tree can be found using this formula: n = 2^h Where n is the amount of nodes in the tree, and h is the height of the tree.


Why you represent the general trees as binary trees?

General trees are not binary trees. It is the other way around, however, see the last paragraph for a different answer - explanation first... A binary tree is one with two possible child nodes, a left node and a right node, either of which might be not present. This particular representation implies a certain order between the node and its children, and if you walk the tree from bottom left to bottom right, you will traverse the nodes in order. A general tree is one with any number of possible child nodes, including no child nodes, so a binary tree is an example of a general tree, while a general tree is a generalization of a binary tree. However, in the general tree, the meaning of the child nodes might not have any specific ordering, like those in a binary tree, unless the general tree has other information contained in the node about order, because the concept of left and right has no implied meaning when there are more than two children. But, as promised, if the general tree has order, it is always possible to represent the general tree as a binary tree - there will just be more nodes, but they will only contain zero, one, or two children, and they will have an implied order.