a Binary Tree T can be represented by Array in 2 different way;
Sequential representation:
if T is a complete Binary tree, then its-
- Sequential representation (via singular linear array)
- Linked representation
Sequential representation:
if T is a complete Binary tree, then its-
- root R will be stored in array element T[0]
- if K number of node occupies, will be stored in array element T[K]
- left child will be stored in array element T[ 2*K ]
- right child will be stored in array element T [ 2*K+1 ]
diagrammatic explanation:
Linked representation:
if K is the correspond location pointer :
if K is the correspond location pointer :
- need 3 parallel array INFO, LEFT and RIGHT
- data at node N will be stored in array element INFO[K]
- location of left child of node N will be stored in array element LEFT[ K ]
- location of right child of node N will be stored in array element RIGHT [ K ]
- root R of T will be stored in ROOT
No comments:
Post a Comment