Talking about representation, trees can be represented in two way:
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, numbering of nodes can start either from 0–(n-1) or 1– n.
A(0) / \ B(1) C(2) / \ \ D(3) E(4) F(6) OR, A(1) / \ B(2) C(3) / \ \ D(4) E(5) F(7)
For first case(0—n-1),
For second case(1—n),
where father, left_son and right_son are the values of indices of the array.
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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- Minimum swap required to convert binary tree to binary search tree
- Find the median array for Binary tree
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Construct Binary Tree from given Parent Array representation
- Shortest path between two nodes in array like representation of binary tree
- Maximum height of the binary search tree created from the given array
- Check if an array represents Inorder of Binary Search tree or not
- Find Height of Binary Tree represented by Parent array
- Convert a Binary Tree to Threaded binary tree | Set 2 (Efficient)
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)
- Construct Binary Tree from given Parent Array representation | Iterative Approach
- Check if a given array can represent Preorder Traversal of Binary Search Tree
- Construct a complete binary tree from given array in level order fashion
- Create a binary tree from post order traversal and leaf node array
- Check if the given array can represent Level Order Traversal of Binary Search Tree
- BK-Tree | Introduction & Implementation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.