1
$\begingroup$

I try to express datastructures in a form of mathematical functions. For example an array or a dictionary is just a function to me.

Is there a good way to model a tree in terms of functions?

$\endgroup$
1

1 Answer 1

2
$\begingroup$

A tree structure can be completely described by three functions:

  • a function that given a node $x$ returns the number of children of that node,
  • a function that given a node $x$ and index $i$ returns the $i$th child of that node, and
  • a function that given a node $x$ returns an associated value $v$ stored at that node.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.