Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE) PDF Download

Array Implementation


Talking about representation, trees can be represented in two ways:

  1. Dynamic Node Representation (Linked Representation).
  2. Array Representation (Sequential Representation).

We are going to talk about the sequential representation of the trees.
To represent tree using an array, the numbering of nodes can start either from 0–(n-1) or 1– n.
Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)For first case(0—n-1),
if (say)father=p;
then left_son=(2*p)+1;
and right_son=(2*p)+2;
For second case(1—n),
if (say)father=p;
then left_son=(2*p);
and right_son=(2*p)+1;
where father, left_son and right_son are the values of indices of the array.

  • C++
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
  • Java
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
  • C#
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
  • Python3
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)
    Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)

Output:

  • Can't set child at 3, no parent found
  • Can't set child at 4, no parent found
  • A-C---F---

Note: Please refer this if you want to construct tree from the given parent array.

The document Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Programming and Data Structures.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
158 docs|31 tests
Related Searches

Previous Year Questions with Solutions

,

Sample Paper

,

Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)

,

Extra Questions

,

Exam

,

mock tests for examination

,

Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)

,

Array Representation of Binary Trees | Programming and Data Structures - Computer Science Engineering (CSE)

,

Viva Questions

,

Objective type Questions

,

past year papers

,

MCQs

,

study material

,

practice quizzes

,

pdf

,

Important questions

,

ppt

,

shortcuts and tricks

,

Summary

,

Semester Notes

,

Free

,

video lectures

;