TITLE: Counting the number of subgraphs in a given labeled tree
QUESTION [5 upvotes]: Are there any results on the number of subgraphs in a labeled tree (or a general labeled graph)?  I would also be happy to know any results on the number of subgraphs in an unlabeled tree.  Cayley's formula says how many different trees I can form given n vertices, but it doesn't seem to relate to the problem of counting subgraphs in a given tree.  Any help is appreciated.

REPLY [5 votes]: Paul's idea can be improved into a linear algorithm to count the subtrees of a tree. Arbitrarily root the tree at some vertex $r$ and let $T_x$ denote the subtree rooted at vertex $x$. Define $A(x)$ to be the number of subtrees of $T_x$ that include $x$, and define $B(x)$ to be the number of subtrees of $T_x$ that don't include $x$.  Do not include the null subtree in $B(x)$ (add 1 to the final answer if you want).
If $x$ is a leaf then $A(x)=1$ and $B(x)=0$.
If $y_1,\ldots,y_k$ are the children of a non-leaf $x$, then
\begin{align*}
  A(x) &= \prod_{i=1}^k (1+A(y_i)) \\\\
  B(x) &= \sum_{i=1}^k (A(y_i) + B(y_i)),
\end{align*}
and the answer is $A(r)+B(r)$.
The two recurrences need to be applied once for each vertex.  The time required for vertex $x$ is $O(1+\text{degree of }x)$, which adds up to $O(n)$ when summed over all $x$. So the total time is $O(n)$. Here we are cheating slightly by counting arithmetic operations as $O(1)$ even though numbers with a linear number of bits might be involved.
This is most unlikely to be original.