forked from dgleich/matlab-bgl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_from_pred.m
More file actions
28 lines (25 loc) · 794 Bytes
/
tree_from_pred.m
File metadata and controls
28 lines (25 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function T = tree_from_pred(pred)
% TREE_FROM_PRED Convert a predecessor array into a tree
%
% T = tree_from_pred(pred) returns the predecessor array as an
% unweighted adjacency matrix
% pred(i) = 0 if vertex i is a source vertex u,
% pred(i) = 0 if vertex i has no predecessor associated with it, or
% pred(i) = j where j is the parent of vertex i in the tree.
%
% Example:
% load('graphs/dominator_tree_example.mat');
% p = lengauer_tarjan_dominator_tree(A,1);
% T = tree_from_pred(p);
%
% See also BFS, DFS, LENGAUER_TARJAN_DOMINATOR_TREE
% David Gleich
% Copyright, Stanford University, 2007-2008
%% History
% 2007-07-12: Initial version
% 2008-09-23: Reformatted common section.
%%
n = length(pred);
mask = pred~=0;
I = 1:n;
T = sparse(I(mask),pred(mask),1,n,n);