Array-based representation of a binary tree, Data Structure & Algorithms

Assignment Help:

Assume a complete binary tree T with n nodes where each node has an item (value). Label the nodes of the complete binary tree T from top to bottom & from left to right 0, 1, ..., n-1. Relate with T the array A where the ith   entry of A is the item in the node labeled i of T, i = 0, 1, ..., n-1. Table illustrates the array representation of a Binary tree of Figure

1724_Array-based representation of a Binary Tree.png

Given the index i of a node, we can efficiently & easily compute the index of its parent and left & right children:

Index of Parent: (i - 1)/2, Index of Left Child: 2i + 1, Index of Right Child: 2i + 2.

Node #

Item

Left child

Right child

0

A

1

2

1

B

3

4

2

C

-1

-1

3

D

5

6

4

E

7

8

5

G

-1

-1

6

H

-1

-1

7

I

-1

-1

8

J

-1

-1

9

?

?

?

Table: Array Representation of a Binary Tree

First column illustrates index of node, second column contain the item stored into the node & third & fourth columns mention the positions of left & right children

(-1 shows that there is no child to that specific node.)


Related Discussions:- Array-based representation of a binary tree

Representation of data structure in memory, Representation of data structur...

Representation of data structure in memory is known as: Abstract data type

Write down the procedure to reverse a singly linked list. , Ans: A pr...

Ans: A procedure to reverse the singly linked list: reverse(struct node **st) { struct node *p, *q, *r; p = *st; q = NULL; while(p != NULL) { r =q;

B-tree, Unlike a binary-tree, each node of a B-tree may have a number of ke...

Unlike a binary-tree, each node of a B-tree may have a number of keys and children. The keys are stored or saved in non-decreasing order. Each key has an related child that is the

Explain in detail about the ruby arrays, Explain in detail about the Ruby a...

Explain in detail about the Ruby arrays Ruby arrays have many interesting and powerful methods. Besides indexing operations which go well beyond those discussed above, arrays h

Queue, algorithm for insertion in a queue using pointers

algorithm for insertion in a queue using pointers

Program segment for quick sort, Illustrates the program segment for Quick s...

Illustrates the program segment for Quick sort. It uses recursion. Program 1: Quick Sort Quicksort(A,m,n) int A[ ],m,n { int i, j, k; if m { i=m; j=n+1; k

Explain insertion sort, Q. Explain the insertion sort with a proper algorit...

Q. Explain the insertion sort with a proper algorithm. What is the complication of insertion sort in the worst case?

Acyclic graphs, Acyclic Graphs In a directed graph a path is said to fo...

Acyclic Graphs In a directed graph a path is said to form a cycle is there exists a path (A,B,C,.....P) such that A = P. A graph is called acyclic graph if there is no cycle in

Depth First Search Through Un-weighted Connected Graph , Q. Write down the ...

Q. Write down the algorithm which does depth first search through an un-weighted connected graph. In an un-weighted graph, would breadth first search or depth first search or neith

Sorting, how to do a merge sorting

how to do a merge sorting

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