answersLogoWhite

0


Best Answer

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

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you represent binary tree using array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


Can you implements tree using array?

yes you can....


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.


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


Are binary tree and binary tree same?

Yes.


Copy of binary tree?

Is another binary tree.