function Tb = msmt_tree_breakdown(Tb,T,A,B,column)
% MSMT_TREE_BREAKDOWN determines the number of points of A or B in each 
%	node in the decision tree T, for the given matrices A and B.
%
%	Tb = msmt_tree_breakdown(Tb,T,A,B,column)
%
%	Tb: output matrix with structure as follows:
%		if column i of matrix T has no children that are leaf nodes
%			then column i of matrix Tb is as follows:
%			Tb(1,i) = number of points of A at this decision node
%			Tb(2,i) = number of points of B at this decision node
%			Tb(3:6,i) = -1
%			The label Tb is for T-breakdown
%		if column j of matrix T has left child that is leaf node
%			then column j of Tb is as follows:
%			Tb(1,j) = number of points of A at this decision node
%			Tb(2,j) = number of points of B at this decision node
%			Tb(3,j) = number pts of A in left child
%			Tb(4,j) = number pts of B in left child
%			Tb(5:6,j) = -1
%		if column j of matrix T has right child that is leaf node
%			Tb(1:2,j) = same as above
%			Tb(3:4,j) = -1
%			Tb(5,j) = number pts of A in right child
%			Tb(6,j) = number pts of B in right child
%		if column j of matrix T has both left, right children leaves
%			all rows 1,...,6 are filled as described above
%			(i.e. no -1's)
%	T: matrix representing decision tree T generated by MSM-T algorithm
%	A: matrix representing points in set A
%	B: matrix representing points in set B
%	column: counter to tell where we are in T
%
% NOTE: this is recursive

% n is the dimension of points in sets A,B and is global
global n;


% for this column: put in the necessary info:
Tb(1,column) = size(A,1);
Tb(2,column) = size(B,1);
% get w,theta for this node
w = T(1:n,column);
theta = T(n+1,column);

% divvy up the sets A,B
[Asmall,Abig,Bsmall,Bbig] = msmt_divvy(A,B,w,theta);

% if left child is a a leaf, do the right stuff to Tb, else go there
if (T(n+2,column) == -1)
	Tb(3,column) = size(Asmall,2);
	Tb(4,column) = size(Bsmall,2);

else
	Tb(3,column) = -1;
	Tb(4,column) = -1;
	Tb = msmt_tree_breakdown(Tb,T,A(Asmall,:),B(Bsmall,:),T(n+2,column));
end

% if right child is a leaf, do the right stuff to Tb, else go there
if (T(n+3,column) == -1)
	Tb(5,column) = size(Abig,2);
	Tb(6,column) = size(Bbig,2);
else
	Tb(5,column) = -1;
	Tb(6,column) = -1;
	Tb = msmt_tree_breakdown(Tb,T,A(Abig,:),B(Bbig,:),T(n+3,column));
end
return







