Finding the child node in the recombining binomial tree I am trying to program a binomial tree in Matlab. The tree looks something like this:

The numbers in the picture refer to the index of the array to create a binomial tree.
Problem:
Value of 2 = 0.5*Value of 4 + 0.5*Value of 5
Value of 3 = 0.5*Value of 5 + 0.5*Value of 6
I need to link the value of 2 to value of 4 and value of 5, similarly for value of 3 accordingly. 
How do i get the link mathematically so that I can program it, instead of stating it manually?
I hope the problem is clear. Need some guidance on this.
How I am programming it?
Basically I am trying to model an interest rate tree. I am having a array for interest and another for the discounted value. I have a previous qn:Interest Rate Tree in Matlab. Now I am changing to vectors.I programmed it using cell arrays, now changing to vectors.
Interest = [0.03;0;0];
DiscountedValue =zeros(3,1);

Interest = [Interest; zeros(n,1)];
DiscountedValue = [DiscountedValue; zeros(n,1)];

total= size(Interest,1);
DiscountedValue(end:-1:(end-n+1)) = 100;
m=0
for i=total-n:-1:total-2n+2
        Interest(i)= (alpha*exp(2^(m)*volatility))/100;
        m = m+1;
end
for j= total-n:-1:1
    //Stuck here//DiscountedValue(j) = (0.5*DiscountedValue(j+0.5*DiscountedValue{j+1}(2,i+1))/(1+Interest(j));
end

 A: The bottom numbers on your columns are the triangular numbers $\frac 12n(n+1)$ where $n$ is the column number.  If you have a number, say $5$, the number up and to the right is $5+n$, where $n$ is the column number of $5$ and the number down and to the right is $5+n+1$.  We will be done if we can find the column number from the entry.  
Given a triangular number $m$, its column number is the $n$ such that $m=\frac 12n(n+1)$ or $n^2+n-2m=0$  We can use the quadratic formula to solve this:  $n=\frac 12(-1+\sqrt{1+8m})$  So given an entry $m$ in your triangle, its column number is $\lceil \frac 12(-1+\sqrt{1+8m}) \rceil$  
For a test, let $m=13$.  It column number is $\lceil \frac 12(-1+\sqrt {1+8\cdot 13})=\lceil \frac 12(\sqrt{105}-1 )\rceil=\lceil \frac 12(10.25-1) \rceil =5$ and the numbers next to it are $18,19$
A: I'm not sure if I understood your question quite well, but you may want to consider this "trick" in order to get the coefficients of the Pascal's triangle.
Consider the matrix whose elements are given by:
$$a_{ij} = \left\{\begin{array}{ll} 0 & i \neq j-1\\ i-1 & i = j-1  \end{array}\right.$$
Compute now the exponential matrix, $M = e^A$, and note that the non-zero elements of the $i$th row of $M$ (wich is a lower triangle matrix) is the $i$th row of the Pascal's triangle.
Example
If $$A = \left(
\begin{array}{cccc}
 0 & 0 & 0 & 0 \\
 1 & 0 & 0 & 0 \\
 0 & 2 & 0 & 0 \\
 0 & 0 & 3 & 0
\end{array}
\right),$$ 
then 
$$M = e^{A} = \left(
\begin{array}{cccc}
 1 & 0 & 0 & 0 \\
 1 & 1 & 0 & 0 \\
 1 & 2 & 1 & 0 \\
 1 & 3 & 3 & 1
\end{array}
\right). $$
The matrix exponential in Matlab is computed with expm.
Cheers!

Source here. Search for the t-shirt answer given by @Gottfried Helms.
