TLDR Dev · ARTICLES & TUTORIALS

REPRESENTING HIERARCHIES

gpfault.net3 min read

Summary from the TLDR Dev newsletter

There are two common methods for representing hierarchical data structures, like HTML elements or file systems. The "obvious way" uses an array of pointers to child nodes, which allows for convenient indexed access but introduces dynamic memory allocations and potential cache misses. The "allocation-free way" uses first-child and next-sibling pointers, removing the need for dynamic memory management for child relationships and improving cache efficiency.