[Tex/LaTex] pstree: How to force a tree node to one side

pst-treepstrickstrees

I'm drawing some binary search trees using pstricks and pstree, but I don't see anything in the docs to push a node to one side. In a binary search tree, every child must be either right or left, but if there's only one child then pstree will hang it straight down.

   *
  / \
 *   *
/ \  |

should be

   *
  / \
 *   *
/ \   \

Best Answer

Putting a nil node is not tricky but rather good maths. Adding manually some space would be ugly.

In pstree you manipulate (ordered) n-ary trees so there is no notion of left or right child node. You can only give a list of child nodes (ordered).

Think of how you will implement binary trees (t := () | (t, t)) with ordered n-ary trees (t := list of trees). The two following binary trees are different.

  *          *
 /     !=     \
*              *

While they are equal as n-ary trees. You need to explicitly encode the skip of the left child node to simulate that in n-ary trees.

The pstree creators proposed you a distinguished \Tn node (nil node) for that purpose.

\pstree{\TR{a}}{
  \Tn
  \TR{b}
}

Just like when a missing information is an information.