Fixed GA3 again and again
This commit is contained in:
parent
d37f05664d
commit
59b66ac061
2 changed files with 8 additions and 1 deletions
BIN
GA3/ga3.pdf
BIN
GA3/ga3.pdf
Binary file not shown.
|
@ -639,7 +639,7 @@ FUNCTION JOIN-INTERVALS(X)
|
|||
|
||||
c $\gets$ 1
|
||||
n $\gets$ 0
|
||||
start $\gets$ X[i][1]
|
||||
start $\gets$ X[1][1]
|
||||
for i from 2 to X.length:
|
||||
c $\gets$ c + X[i][2]
|
||||
if c == 0:
|
||||
|
@ -654,4 +654,11 @@ FUNCTION JOIN-INTERVALS(X)
|
|||
The complexity of this algorithm is $O(n\log(n))$ since the sorting is in $\Theta(n\log(n))$ and the
|
||||
union operation afterwards is $\Theta(n)$.
|
||||
|
||||
\section{Bonus}
|
||||
|
||||
The number of possible trees with $n$ nodes can be defined recursively. The number of trees with 0 or 1 node is clearly 1, since there is no freedom in arranging any remaining elements as children. For $n$ nodes, this number can be defined as the the sum, for each $x, y \in N_0$ s.t. $x + y = n - 1$, of the number of trees with $x$ nodes times the number of trees with $y$ nodes. We consider only $n - 1$ nodes since one node must be the root of the tree.
|
||||
Using math notation, the number $T_n$ of trees with $n$ nodes can be expressed as:
|
||||
|
||||
$$T_n = 1 \hspace{1cm} n = 0 \lor n = 1$$
|
||||
$$T_n = \sum_{i = 0}^{n-1} C_i C_{n-1-i} \hspace{1cm} n \geq 2$$
|
||||
\end{document}
|
Reference in a new issue