Data structure optimized for lowest-complexity recursion from deepest to shallowest nodes?

Tag: algorithm Author: baidu320 Date: 2009-07-10

I'm looking a data structure or algo (to be implemented in C) that will provide low time-complexity recursion from the deepest nodes to the shallowest nodes in a complex, nested structure.

The application is protocol encoding, where each element must know its size (the combined size of its data, and any member elements).

I've been banging my head against this one -- I really appreciate everyone's help.

Other Answer1

You can use a stack and push the pointer to the nodes as you encounter them
Finally you will have the deepest node at the top and you can go to the shallowest node by simply popping out the pointers from the stack.


That's what I was thinking about -- wasn't sure if there was a better way of doing it! Thanks for the prompt response :)