Re: Enumerating all expression trees (not Catalan)



On Sep 15, 9:53 pm, Tegiri Nenashi <tegirinena...@xxxxxxxxx> wrote:
I'm writing a program that generates all expressions with binary and
unary operations. E.g.  -((x + y) * z). Before worrying about
variables and operations, I wonder how to generate plain tree
structures. The mapping that would enumerate each tree with unique
integer would be ideal for my purposes. (Curiously, such mapping in
simple cases of binary trees or other Catalan structures is appeared
to be not an easy matter to google!)

Here is one such mapping. Assign 2 to a node with two children, 1 to
the node with one child, 0 to the leaf. Write down expression in
polish notation, and interpret it as a ternary number, e.g.

221000

corresponds to the tree or expression like this

(((-x)+y)+z)

However, this mapping is not a bijection, for example the code

22100

doesn't correspond to any tree. This might be a big problem for my
program if asymptotically the mapping is almost empty, then the run
time would be wasted wading through the list of mostly useless codes.
Any guess for asymptotic, or suggestion for better encoding?

Here is asymptotics:
10000 - 225
100000 - 1696
1000000 - 13695
10000000 - 108540
Admittedly, this should be done in base3 rather than 10 to give better
feeling of analytics. However my purpose was to establish if the
method is practical or not, and this experiment proved it does...
.



Relevant Pages

  • Re: Review of Mueckenheims book.
    ... mapping does or does not exist. ... It is not excluded "a priori" that a model of ZFC might not map '0' to ... Geometry is USED for physics. ... than your tree. ...
    (sci.math)
  • Re: Two results of set geometry
    ... >>> There is a bijection between the set of all paths representing real ... The mapping you gave is from nodes to paths. ... traversal of the tree still differs by some finite amount from 2/3. ... at which the approximation to 2/3 is closer than epsilon. ...
    (sci.math)
  • Enumerating all expression trees (not Catalan)
    ... The mapping that would enumerate each tree with unique ... corresponds to the tree or expression like this ... time would be wasted wading through the list of mostly useless codes. ...
    (sci.math)
  • Re: [RFC] fsblock
    ... fsblocks vs extent range mapping] ... The fsblocks and the vm page cache interface cannot be used to ... facilitate this because a radix tree is the wrong type of tree to ... but we keep the dirty each buffer part. ...
    (Linux-Kernel)
  • Re: ANN: WHIFF += Mako & treeview & url rewrites
    ... a big traceback page which indicates that the application doesn't ... understand the normal link on each of the nodes of the tree. ... JavaScript, which is a worthy objective forgotten by many Web ... purposes, they can be turned off, of course. ...
    (comp.lang.python)

Loading