motzkin-numbers

Algorithm improvement for enumerating binary trees

我与影子孤独终老i 提交于 2019-11-27 07:53:30
问题 Currently I can enumerate rooted planar unlabeled binary trees using the following brute-force Prolog code. e --> u | b | t. u --> ['[op(u),['], e, [']]']. b --> ['[op(b),['], e, [','], e, [']]']. t --> ['number(n)']. Note: See output listings below. and output them in increasing size using es(S) :- length(Ls, _), phrase(e, Ls), % or e(Ls,[]), atomic_list_concat(Ls,S). However this is inefficient brute-force algorithm. Is there a more efficient algorithm for enumerating rooted planar