n-ary tree approach to generate chemical structures

Hello all,

Here is the situation: I would like to generate an exhaustive list of structures for non-cyclic molecules that contain n carbons only.

Example for n = 5 (SMILES representation here, but it could be any valid format):

  1. CCCCC
  2. CC(C)CC
  3. CC(C)(C)C

If I express it in a language I better understand, this is traversing an unrooted quaternary tree with n nodes.

Could anyone point me in using the right node(s) to perform this?