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


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.
