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)
119 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

119 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

study material

,

past year papers

,

Viva Questions

,

MCQs

,

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

,

shortcuts and tricks

,

Previous Year Questions with Solutions

,

Objective type Questions

,

Exam

,

pdf

,

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

,

Important questions

,

mock tests for examination

,

practice quizzes

,

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

,

ppt

,

video lectures

,

Summary

,

Sample Paper

,

Extra Questions

,

Semester Notes

,

Free

;