One can, for example, represent 2d arrays such as:[[1,2],[3,4],[4,5]]as flat arrays:[1,2,3,4,5,6]as long as he transforms the indices before accessing:index(x,y) = x + y*2 // because internal width=2This is often faster. My question is: is it possible to use a similar approach of representing an structure as a flat array, for, instead of n-dimensional tables, free-form trees such as:[[1,2,3],4,[5,[6,7]],8]
Is there an structure that allows for a flat representation of trees with constant access to any element?
algorithms;data structures