1function p = cs_nd (A)
2%CS_ND generalized nested dissection ordering.
3%   p = cs_nd(A) computes the nested dissection ordering of a matrix.  Small
4%   submatrices (order 500 or less) are ordered via cs_amd.  A must be sparse
5%   and symmetric (use p = cs_nd(A|A') if it is not symmetric).
6%
7%   Example:
8%       A = delsq (numgrid ('L', 300)) ;    % matrix used in 'bench'
9%       p = cs_nd (A) ;
10%       cspy (A (p,p)) ;
11%
12%   See also CS_AMD, CS_SEP, CS_ESEP, CS_NSEP, AMD.
13
14% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com
15
16n = size (A,1) ;
17if (n == 1)
18    p = 1 ;
19elseif (n < 500)
20    p = cs_amd (A) ;                % use cs_amd on small graphs
21else
22    [s a b] = cs_nsep (A) ;         % find a node separator
23    a = a (cs_nd (A (a,a))) ;       % order A(a,a) recursively
24    b = b (cs_nd (A (b,b))) ;       % order A(b,b) recursively
25    p = [a b s] ;                   % concatenate to obtain the final ordering
26end
27