Neocortex 🧠

Search

Search IconIcon to open search

Tree Representation with Arrays

Last updated Dec 14, 2021 Edit Source

It is very easy to represent Trees using a linked data structures, similar to Linked List. However, if you want more performance, it is sometimes better to use an Array. It is easy to calculate the indexes of the parent(Important Tree Terminology) and (left/right) children using simple arithmetic. If you place each node in an array as such:

graph TD; 0-->1 & 2; 1-->3;

We use the following formulas:


Interactive Graph