function y = GraphSequenceRecursive(DegSeq)
%y = GraphSequenceRecursive(DegSeq)
%Recursive Algorithm based on the Havel-Hakimi theorem on degree sequences
%Alg. 8.1 in book
%input: DegSeq = a vector of nonnegative integers (in decreasing order)
%y = 0, if sequence is not graphic, y = 1, if it is graphic.
if max(DegSeq) >= length(DegSeq)
    fprintf('Degrees are too large for the number of vertices.\r'), y = 0; return
end
d1 = DegSeq(1);
n = length(DegSeq);
count = 1;
while d1 > 0
    DegSeqNew = DegSeq(2:end); 
    DegSeq = DegSeqNew; 
    DegSeq(1:d1) = DegSeq(1:d1) - 1;
    DegSeq = sort(DegSeq,[2],'descend');
    d1 = DegSeq(1);
    count = count + 1;
    if DegSeq(end)<0
        y=0; return
    end
end
y=1;

    