# Recursive tree in Tikz

I'm trying to build a large inverted tree structure in Tikz, like the one below (except much larger, and ideally recursive):

In this tree structure, each 'line' is made up of three nodes, and each of those nodes will have a parent which is the bottom node in another line.

Is it possible to write this recursively in such a way that I can easily change the amount of nodes per line (at the moment this is 3) and the maximum amount of lines (at the moment this is 5)?

I manually generated the above diagram using the code below:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[every node/.style={draw,shape=circle,fill=black}]

\node[fill=red] (A) at (0,0) {};
\node[fill=red] (B) at (0,1) {};
\node[fill=red] (C) at (0,2) {};

\draw (A) -- (B) (B) -- (C);

\node (D) at (2,1) {};
\node (E) at (2,2) {};
\node (F) at (2,3) {};

\draw (A) -- (D) (D) -- (E) (E) -- (F);

\node (G) at (-1,2) {};
\node (H) at (-1,3) {};
\node (I) at (-1,4) {};

\draw (B) -- (G) (G) -- (H) (H) -- (I);

\node (J) at (1,3) {};
\node (K) at (1,4) {};
\node (L) at (1,5) {};

\draw (C) -- (J) (J) -- (K) (K) -- (L);

\node (M) at (-2,3) {};
\node (N) at (-2,4) {};
\node (O) at (-2,5) {};

\draw (G) -- (M) (M) -- (N) (N) -- (O);

\end{tikzpicture}
\end{document}

• Welcome! But each of those nodes will have a parent which is the bottom node in another line? Surely not! – cfr Apr 1 '16 at 10:38
• The thing is: the number of lines does not determine the structure of the tree. How does TikZ (or anything else) know which 5 groups of 3 to draw? This would be true even if the trees obeyed the rule you gave which the tree you show does not. – cfr Apr 1 '16 at 10:43
• You can check this question to see how you can draw recursively a tree. – Kpym Apr 1 '16 at 19:48
• @Kpym Did you link to the wrong question? There are plenty of relevant questions around, but that doesn't seem to be one of them! Of course, I may have misunderstood the question. (And it is certainly true that fractals are recursive. And I'm not really sure how these are supposed to work. So maybe you're right.) – cfr Apr 2 '16 at 2:15
• @cfr in the question of my link these are trees (of a free group). They are not fractals. Their boundary looks like a fractal. I think that all the methods their could be adapted to draw the kind of tree asked in this question. But I agree their is a work to do ;) – Kpym Apr 2 '16 at 5:40