function DepthList = ParentList2DepthList(ParentList)
% DepthList = ParentList2DepthList(ParentList)
%Input: ParentList: a two column matrix giving the parent of each vertex
%Output: DepthList: a two column matrix giving the depth of each vertex
[n s] = size(ParentList); %n = number of vertices
DepthList = zeros(n,2);
DepthList(:,1) = ParentList(:,1);
ParentList(1,2) = 0; %root has zero depth
counter = n - 1; %initialize number of vertices left to compute depths
Gen = 0; %initialize Generation Counter
Parents = ParentList(1,1); %initialize first generation parent (the root)
while counter > 0
    Gen = Gen + 1; %advance generation counter
    %find all indices children of current generation parents and assign
    %their depth as Gen
    Children = []; % initialize empty vector for current children
    for i = 1:length(Parents)
        ChildInds = find(ParentList(:,2) == Parents(i));
        DepthList(ChildInds,2) = Gen;
        counter = counter - length(ChildInds);
        Children = [Children ParentList(ChildInds,1)'];
    end
    %All Current Children determine next generation of Parents
    Parents = Children;
end
    
        
    