Hot answers tagged


A tree is defined to be a set of nodes, with a parent-child relationship that satisfies certain properties. Thus, it doesn't make sense to ask whether a node can "appear" twice. In your code snippet, you have constructed a DAG, not a tree.


Is this valid? Why or why not? Mathematically it's not a tree. However, it would be allowed in some programming languages as a valid representation of a tree. Short answer The reason it is not mathematically a tree is that the node a has two children, b and b, which are the same. This is not allowed in a tree. If you have multiple children they must all ...


Assume $n>1$. The solution to $k^k=n$ is $k=e^{W(\log n)}$, where $W(\cdot)$ is the Lambert W function. Another way to express the solution is $$k = \dfrac{\log n}{\log\dfrac{\log n}{\log\dfrac{\log n}{\log\dfrac{\log n}{\cdots}}}}.$$ In other words, $k$ is the limit of $k_0=\log n$, $k_1=\dfrac{\log n}{\log k_1}$, $\cdots$, $k_{t+1}=\dfrac{\log n}{\...


If a binary tree has height $h$ then it has at most 1 node at depth 0, at most 2 nodes at depth 1, ..., at most $2^{h-1}$ nodes at depth $h-1$ (the maximal depth), and so at most $1+2+\cdots+2^{h-1} = 2^h-1$ nodes in total. You can also prove this by induction. When $h=1$, the tree consists only of a root, so at most $1=2^h-1$ vertices. Given a tree of ...

Only top voted, non community-wiki answers of a minimum length are eligible