August 19, 2024

P69 - Dotstring representation of binary trees

We consider again binary trees with nodes that are identified by single lower-case letters, as in the example of problem P67.

Such a tree can be represented by the preorder sequence of its nodes in which dots (.) are inserted where an empty subtree (nil) is encountered during the tree traversal.

For example, the tree shown in problem P67 is represented as "ABD..E..C.FG...". First, try to establish a syntax (BNF or syntax diagrams) and then write functions tree and dotstring which do the conversion.

Be first to comment
Leave a reply