%% Topological Sort of Nodes
% Create and plot a graph that represents a progression of university-level Mathematics courses. An edge between two courses signifies a course requirement.

A = [0 1 1 0 0 0 0
     0 0 0 1 0 0 0
     0 1 0 1 0 0 1
     0 0 0 0 1 1 0
     0 0 0 0 0 0 0
     0 0 0 0 1 0 0
     0 0 0 0 1 0 0];
names = {'Calculus I','Linear Algebra','Calculus II', ...
    'Multivariate Calculus','Topology', ...
    'Differential Equations','Real Analysis'};
G = digraph(A,names);
plot(G)

%
% Find the topological sorting of the courses to determine the proper order in which they should be completed.

N = toposort(G)

%

G.Nodes.Name(N,:)

% Copyright 2015 The MathWorks, Inc.