Graph theory: traversal, shortest paths, spanning trees, flow, coloring, communities and centrality.
Functions
func Kruskal (g &: Graph, chosen &: Vector < int >): f64 The minimum spanning tree with Kruskal; returns the weight.
The example for this item is shown with the ones above: graph-Trees.salam
func MaximumSpanningTree (g &: Graph, chosen &: Vector < int >): f64 The maximum spanning tree.
The example for this item is shown with the ones above: graph-Trees.salam
func Prim (g &: Graph, root: int , parent &: Vector < int >): f64 The minimum spanning tree with Prim.
The example for this item is shown with the ones above: graph-Trees.salam
func Boruvka (g &: Graph, chosen &: Vector < int >): f64 The minimum spanning tree with Boruvka.
The example for this item is shown with the ones above: graph-Trees.salam
func MSTWeight (g &: Graph): f64 The weight of the minimum spanning tree.
The example for this item is shown with the ones above: graph-Trees.salam
func MinimumSpanningTree (g &: Graph): Graph The minimum spanning tree as a graph.
The example for this item is shown with the ones above: graph-Trees.salam
func SpanningAgreement (g &: Graph): bool True when the three algorithms give the same weight; for tests.
The example for this item is shown with the ones above: graph-Trees.salam
func BFSFrom (g &: Graph, src: int , dist &: Vector < int >, parent &: Vector < int >) Breadth-first search with distances and parents.
graph-Search.salam Copy
import graph
func ints (v: Vector < int >): str :
mut text := "["
repeat v. Len () in i:
if i > 0 :
text += " "
end
text += "" + v. Get (i)
end
ret text + "]"
end
func main :
mut g := graph. FromEdgeList ( "0 1\n1 2\n2 0\n2 3\n4 5" , 6 , false )
println ints (graph. BFS (g, 0 )),
ints (graph. BFSOrder (g, 0 )),
ints (graph. DFSOrder (g, 0 )),
ints (graph. DFSPostOrder (g, 0 ))
mut dist := Vector {} as Vector < int >
mut parent := Vector {} as Vector < int >
graph. BFSFrom (
g, 0 , dist, parent
)
println ints (dist), ints (graph. PathFromParents (parent, 0 , 3 )), ints (graph. DFSForest (g))
println graph. ReachableCount (g, 0 ),
graph. Reachable (g, 4 ). Get ( 5 ),
graph. HopDistance (g, 0 , 3 ),
graph. HopDistance (g, 0 , 4 ),
ints (graph. HopPath (g, 1 , 3 ))
mut comp := Vector {} as Vector < int >
println graph. Components (
g, comp
), ints (comp), graph. ComponentCount (g), ints (
graph. ComponentSizes (g)
), graph. IsConnected (g)
mut color := Vector {} as Vector < int >
println graph. IsBipartite (
graph. CycleGraph ( 4 ), color
), ints (color), graph. Bipartite (g)
println ints (graph. FindCycle (g)), graph. HasCycle (g)
println ints (graph. Bridges (g)), ints (graph. ArticulationPoints (g))
mut bicomp := Vector {} as Vector < int >
println graph. BiconnectedComponents (
g, bicomp
), ints (bicomp), graph. IsBiconnected (
graph. CycleGraph ( 5 )
), graph. IsTwoEdgeConnected (graph. CycleGraph ( 5 ))
mut twoedge := Vector {} as Vector < int >
println graph. TwoEdgeComponents (
g, twoedge
), ints (twoedge)
hops := graph. AllPairsHops (graph. PathGraph ( 3 ))
println hops. at ( 0 , 2 ), hops.rows
mut tasks := graph. FromEdgeList ( "0 1\n0 2\n1 3\n2 3\n3 4" , 5 , true )
mut order := Vector {} as Vector < int >
println graph. TopologicalSort (tasks, order), ints (order)
println graph. TopologicalSortLex (tasks, order), ints (order), graph. IsDAG (tasks)
mut cyclic := graph. FromEdgeList ( "0 1\n1 2\n2 0\n2 3\n3 4\n4 3" , 5 , true )
mut strong := Vector {} as Vector < int >
println graph. StronglyConnected (
cyclic, strong
), ints (strong), graph. SCCCount (cyclic), graph. IsStronglyConnected (cyclic)
mut kosa := Vector {} as Vector < int >
println graph. Kosaraju (cyclic, kosa)
dag := graph. Condensation (cyclic, strong)
println dag. order (), dag. Size ()
end Output [0 1 1 2 -1 -1] [0 1 2 3] [0 1 2 3] [3 2 1 0]
[0 1 1 2 -1 -1] [0 2 3] [0 1 2 3 4 5]
4 true 2 -1 [1 2 3]
2 [0 0 0 0 1 1] 2 [4 2] false
true [0 1 0 1] false
[0 1 2] true
[3 4] [2]
3 [1 1 1 0 2] true true
4 [0 0 0 1 2 3]
2 3
true [0 1 2 3 4]
true [0 1 2 3 4] true
2 [1 1 1 0 0] 2 false
2
2 1
func BFS (g &: Graph, src: int ): Vector < int > The hop distance of every node from the source; -1 means unreachable.
The example for this item is shown with the ones above: graph-Search.salam
func BFSOrder (g &: Graph, src: int ): Vector < int > The order in which breadth-first search visits the nodes.
The example for this item is shown with the ones above: graph-Search.salam
func DFSOrder (g &: Graph, src: int ): Vector < int > The example for this item is shown with the ones above: graph-Search.salam
func DFSPostOrder (g &: Graph, src: int ): Vector < int > The depth-first post-order.
The example for this item is shown with the ones above: graph-Search.salam
func DFSForest (g &: Graph): Vector < int > The depth-first order of the whole graph.
The example for this item is shown with the ones above: graph-Search.salam
func Reachable (g &: Graph, src: int ): Vector < bool > Whether each node is reachable.
The example for this item is shown with the ones above: graph-Search.salam
func ReachableCount (g &: Graph, src: int ): int The number of reachable nodes.
The example for this item is shown with the ones above: graph-Search.salam
func HopDistance (g &: Graph, s: int , t: int ): int The fewest number of hops.
The example for this item is shown with the ones above: graph-Search.salam
func PathFromParents (parent: Vector < int >, s: int , t: int ): Vector < int > A path from the parent list.
The example for this item is shown with the ones above: graph-Search.salam
func HopPath (g &: Graph, s: int , t: int ): Vector < int > The path with the fewest hops.
The example for this item is shown with the ones above: graph-Search.salam
func CountColorings (g &: Graph, k: int ): f64 The number of colorings with k colors.
The example for this item is shown with the ones above: graph-Flow.salam
func New (n: int , directed: bool ): Graph A graph with n nodes, directed or undirected.
The example for this item is shown with the ones above: graph-Build.salam
func NewUndirected (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func NewDirected (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func FromEdges (n: int , us: Vector < int >, vs: Vector < int >, directed: bool ): Graph A graph from two lists of edge start and end nodes.
The example for this item is shown with the ones above: graph-Build.salam
func IsClose (a: f64 , b: f64 ): bool True when two floats are equal within a tolerance.
The example for this item is shown with the ones above: graph-Build.salam
func HasEulerianCircuit (g &: Graph): bool True when there is an Eulerian circuit.
The example for this item is shown with the ones above: graph-Paths.salam
func HasEulerianPath (g &: Graph): bool True when there is an Eulerian path.
The example for this item is shown with the ones above: graph-Paths.salam
func EulerianCircuit (g &: Graph): Vector < int > A cycle that passes every edge once.
The example for this item is shown with the ones above: graph-Paths.salam
func EulerianPath (g &: Graph): Vector < int > A path that passes every edge once.
The example for this item is shown with the ones above: graph-Paths.salam
func HamiltonianPath (g &: Graph): Vector < int > A path that passes every node once; for small graphs.
The example for this item is shown with the ones above: graph-Paths.salam
func HamiltonianCycle (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Paths.salam
func HasHamiltonianCycle (g &: Graph): bool True when there is a Hamiltonian cycle.
The example for this item is shown with the ones above: graph-Paths.salam
func TourLength (g &: Graph, tour: Vector < int >): f64 The example for this item is shown with the ones above: graph-Paths.salam
func TSPNearestNeighbor (g &: Graph, start: int ): Vector < int > A traveling salesman tour by nearest neighbor.
The example for this item is shown with the ones above: graph-Paths.salam
func TSPTwoOpt (g &: Graph, tour &: Vector < int >): f64 Improves the tour with 2-opt swaps and returns the new length.
The example for this item is shown with the ones above: graph-Paths.salam
func TSPHeuristic (g &: Graph, start: int ): Vector < int > The two methods above combined.
The example for this item is shown with the ones above: graph-Paths.salam
func NewDisjointSet (n: int ): DisjointSet The example for this item is shown with the ones above: graph-Analysis.salam
func FillInt (v &: Vector < int >, n: int , x: int ) An int vector with n copies of one value.
The example for this item is shown with the ones above: graph-Analysis.salam
func FillFloat (v &: Vector < f64 >, n: int , x: f64 ) A float vector with n copies of one value.
The example for this item is shown with the ones above: graph-Paths.salam
func FillBool (v &: Vector < bool >, n: int , x: bool ) A bool vector with n copies of one value.
The example for this item is shown with the ones above: graph-Build.salam
func Iota (v &: Vector < int >, n: int ) The example for this item is shown with the ones above: graph-Analysis.salam
func MaxInt (v: Vector < int >): int The example for this item is shown with the ones above: graph-Analysis.salam
func SumInt (v: Vector < int >): int The example for this item is shown with the ones above: graph-Analysis.salam
func SumFloat (v: Vector < f64 >): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func ReverseInt (v &: Vector < int >) Reverses the vector in place.
The example for this item is shown with the ones above: graph-Analysis.salam
func GlobalMinCut (g &: Graph): f64 The global minimum cut, with Stoer-Wagner.
The example for this item is shown with the ones above: graph-Flow.salam
func EdgeConnectivity (g &: Graph): int The fewest edges whose removal disconnects the graph.
The example for this item is shown with the ones above: graph-Flow.salam
func VertexConnectivity (g &: Graph): int The fewest nodes whose removal disconnects the graph.
The example for this item is shown with the ones above: graph-Flow.salam
func BipartiteMatching (g &: Graph, mate &: Vector < int >): int The maximum bipartite matching, with Hopcroft-Karp.
The example for this item is shown with the ones above: graph-Flow.salam
func MaximalMatching (g &: Graph, mate &: Vector < int >): int A greedy maximal matching.
The example for this item is shown with the ones above: graph-Flow.salam
func MinimumVertexCover (g &: Graph, cover &: Vector < bool >): int The minimum vertex cover of a bipartite graph.
The example for this item is shown with the ones above: graph-Flow.salam
MaximumIndependentSetBipartite #
func MaximumIndependentSetBipartite (g &: Graph, pick &: Vector < bool >): int The maximum independent set of a bipartite graph.
The example for this item is shown with the ones above: graph-Flow.salam
func Dijkstra (g &: Graph, src: int , dist &: Vector < f64 >, parent &: Vector < int >): bool The shortest distances from the source. Returns false, with every distance GRAPH_INF, when any weight is negative.
The example for this item is shown with the ones above: graph-Paths.salam
func DijkstraDist (g &: Graph, src: int ): Vector < f64 > The example for this item is shown with the ones above: graph-Paths.salam
func ShortestPath (g &: Graph, s: int , t: int ): Vector < int > The shortest weighted path.
The example for this item is shown with the ones above: graph-Paths.salam
func ShortestPathLength (g &: Graph, s: int , t: int ): f64 Its length; GRAPH_INF when there is no route. Uses Bellman-Ford when a weight is negative.
The example for this item is shown with the ones above: graph-Paths.salam
func BellmanFord (g &: Graph, src: int , dist &: Vector < f64 >, parent &: Vector < int >): bool The shortest distances with negative weights; false when there is a negative cycle.
The example for this item is shown with the ones above: graph-Paths.salam
func FindNegativeCycle (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Paths.salam
func HasNegativeCycle (g &: Graph): bool True when there is a negative cycle.
The example for this item is shown with the ones above: graph-Paths.salam
func ZeroOneBFS (g &: Graph, src: int , dist &: Vector < f64 >, parent &: Vector < int >): bool The shortest distances when the weights are zero and one.
The example for this item is shown with the ones above: graph-Paths.salam
func DAGShortestPath (g &: Graph, src: int , dist &: Vector < f64 >, parent &: Vector < int >): bool The shortest path in an acyclic graph.
The example for this item is shown with the ones above: graph-Paths.salam
func DAGLongestPath (g &: Graph, src: int , dist &: Vector < f64 >, parent &: Vector < int >): bool The longest path in an acyclic graph.
The example for this item is shown with the ones above: graph-Paths.salam
func CriticalPath (g &: Graph): Vector < int > The critical path of a project.
The example for this item is shown with the ones above: graph-Paths.salam
func CountPaths (g &: Graph, s: int , t: int ): f64 The number of paths in an acyclic graph.
The example for this item is shown with the ones above: graph-Paths.salam
func PathCounts (g &: Graph, src: int ): Vector < f64 > The number of paths from the source to each node.
The example for this item is shown with the ones above: graph-Paths.salam
func TransitiveClosure (g &: Graph): IntMatrix The transitive closure: who can reach whom.
The example for this item is shown with the ones above: graph-Paths.salam
func TransitiveReduction (g &: Graph): Graph The smallest graph with the same reachability.
The example for this item is shown with the ones above: graph-Paths.salam
func TopologicalLayers (g &: Graph, layer &: Vector < int >): int The layer of each node; the tasks that can run at the same time.
The example for this item is shown with the ones above: graph-Paths.salam
func IsTotalOrder (g &: Graph): bool True when the topological order is unique.
The example for this item is shown with the ones above: graph-Paths.salam
func Clone (g &: Graph): Graph The example for this item is shown with the ones above: graph-Build.salam
func Transpose (g &: Graph): Graph Reverses the direction of every edge.
The example for this item is shown with the ones above: graph-Build.salam
func Reverse (g &: Graph): Graph The same as the transpose.
The example for this item is shown with the ones above: graph-Build.salam
func ToUndirected (g &: Graph): Graph The example for this item is shown with the ones above: graph-Build.salam
func ToDirected (g &: Graph): Graph A directed version with an edge in both directions.
The example for this item is shown with the ones above: graph-Build.salam
func SubgraphMap (g &: Graph, keep: Vector < bool >, map &: Vector < int >): Graph The subgraph of the kept nodes, with a map from old numbers to new ones.
The example for this item is shown with the ones above: graph-Build.salam
func Subgraph (g &: Graph, keep: Vector < bool >): Graph The subgraph of the kept nodes.
The example for this item is shown with the ones above: graph-Build.salam
func EdgeSubgraph (g &: Graph, keep: Vector < bool >): Graph The subgraph of the kept edges.
The example for this item is shown with the ones above: graph-Build.salam
func Complement (g &: Graph): Graph The example for this item is shown with the ones above: graph-Build.salam
func Union (a &: Graph, b &: Graph): Graph The union of the edges over the same nodes.
The example for this item is shown with the ones above: graph-Build.salam
func DisjointUnion (a &: Graph, b &: Graph): Graph Two graphs side by side, with no shared edge.
The example for this item is shown with the ones above: graph-Build.salam
func Intersection (a &: Graph, b &: Graph): Graph The example for this item is shown with the ones above: graph-Build.salam
func LineGraph (g &: Graph): Graph The line graph: each edge becomes a node.
The example for this item is shown with the ones above: graph-Build.salam
func Simplify (g &: Graph): Graph Without self-loops and parallel edges.
The example for this item is shown with the ones above: graph-Build.salam
func RemoveSelfLoops (g &: Graph): Graph The example for this item is shown with the ones above: graph-Build.salam
func SelfLoopCount (g &: Graph): int The number of self-loops.
The example for this item is shown with the ones above: graph-Build.salam
func HasSelfLoop (g &: Graph): bool True when there is a self-loop.
The example for this item is shown with the ones above: graph-Build.salam
func ParallelEdgeCount (g &: Graph): int The number of parallel edges.
The example for this item is shown with the ones above: graph-Build.salam
func IsSimple (g &: Graph): bool True when the graph is simple.
The example for this item is shown with the ones above: graph-Build.salam
func TotalWeight (g &: Graph): f64 The sum of the edge weights.
The example for this item is shown with the ones above: graph-Build.salam
func IsTree (g &: Graph): bool True when the graph is a tree.
The example for this item is shown with the ones above: graph-Trees.salam
func IsForest (g &: Graph): bool True when the graph is a forest.
The example for this item is shown with the ones above: graph-Trees.salam
func RootTree (g &: Graph, root: int , parent &: Vector < int >, order &: Vector < int >) Roots the tree, filling in the parents and the order.
The example for this item is shown with the ones above: graph-Trees.salam
func SubtreeSizes (g &: Graph, root: int ): Vector < int > The size of each node's subtree.
The example for this item is shown with the ones above: graph-Trees.salam
func TreeDiameter (g &: Graph, ends &: Vector < int >): int The diameter of the tree and its two ends.
The example for this item is shown with the ones above: graph-Trees.salam
func TreeCenter (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Trees.salam
func TreeCentroid (g &: Graph): Vector < int > The centroid of the tree.
The example for this item is shown with the ones above: graph-Trees.salam
func GreedyColoring (g &: Graph, order: Vector < int >): Vector < int > A greedy coloring in the given order.
The example for this item is shown with the ones above: graph-Flow.salam
func GreedyColoringNatural (g &: Graph): Vector < int > A greedy coloring in number order.
The example for this item is shown with the ones above: graph-Flow.salam
func WelshPowell (g &: Graph): Vector < int > The Welsh-Powell coloring.
The example for this item is shown with the ones above: graph-Flow.salam
func DSatur (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Flow.salam
func ColorCount (color: Vector < int >): int The example for this item is shown with the ones above: graph-Flow.salam
func IsProperColoring (g &: Graph, color: Vector < int >): bool True when no two neighbors share a color.
The example for this item is shown with the ones above: graph-Flow.salam
func ChromaticNumber (g &: Graph): int The fewest colors needed; for small graphs.
The example for this item is shown with the ones above: graph-Flow.salam
func EdgeColoringGreedy (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Flow.salam
func Density (g &: Graph): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func AverageDegree (g &: Graph): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func MaxDegree (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func MinDegree (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func DegreeSequence (g &: Graph): Vector < int > The degree sequence, in descending order.
The example for this item is shown with the ones above: graph-Analysis.salam
func DegreeHistogram (g &: Graph): Vector < int > The number of nodes with each degree.
The example for this item is shown with the ones above: graph-Analysis.salam
func IsRegular (g &: Graph): bool True when every degree is the same.
The example for this item is shown with the ones above: graph-Analysis.salam
func IsComplete (g &: Graph): bool True when the graph is complete.
The example for this item is shown with the ones above: graph-Analysis.salam
func Eccentricity (g &: Graph, u: int ): int The farthest distance from a node.
The example for this item is shown with the ones above: graph-Analysis.salam
func EccentricityAll (g &: Graph): Vector < int > The eccentricity of every node.
The example for this item is shown with the ones above: graph-Analysis.salam
func Diameter (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func Radius (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func Center (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Analysis.salam
func Periphery (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Analysis.salam
func AveragePathLength (g &: Graph): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func WienerIndex (g &: Graph): f64 The sum of the distances.
The example for this item is shown with the ones above: graph-Analysis.salam
func Girth (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func Isomorphic (a &: Graph, b &: Graph): bool True when two graphs are isomorphic.
The example for this item is shown with the ones above: graph-Analysis.salam
func IsomorphismMap (a &: Graph, b &: Graph, map &: Vector < int >): bool The example for this item is shown with the ones above: graph-Analysis.salam
func AutomorphismCount (g &: Graph): int The number of automorphisms.
The example for this item is shown with the ones above: graph-Analysis.salam
func IsGraphical (seq: Vector < int >): bool True when a degree sequence can be a simple graph.
The example for this item is shown with the ones above: graph-Analysis.salam
func HavelHakimi (seq: Vector < int >): Graph A simple graph with the given degree sequence.
The example for this item is shown with the ones above: graph-Analysis.salam
func SameDegreeSequence (a &: Graph, b &: Graph): bool True when the degree sequences are the same.
The example for this item is shown with the ones above: graph-Analysis.salam
func StronglyConnected (g &: Graph, comp &: Vector < int >): int The strongly connected components, with Tarjan's algorithm.
The example for this item is shown with the ones above: graph-Search.salam
func SCCCount (g &: Graph): int The number of strong components.
The example for this item is shown with the ones above: graph-Search.salam
func IsStronglyConnected (g &: Graph): bool True when the graph is strongly connected.
The example for this item is shown with the ones above: graph-Search.salam
func Kosaraju (g &: Graph, comp &: Vector < int >): int The strong components, with Kosaraju's algorithm.
The example for this item is shown with the ones above: graph-Search.salam
func Condensation (g &: Graph, comp &: Vector < int >): Graph The graph of the components, which never has a cycle.
The example for this item is shown with the ones above: graph-Search.salam
func Bridges (g &: Graph): Vector < int > The edges whose removal disconnects the graph.
The example for this item is shown with the ones above: graph-Search.salam
func ArticulationPoints (g &: Graph): Vector < int > The nodes whose removal disconnects the graph.
The example for this item is shown with the ones above: graph-Search.salam
func BiconnectedComponents (g &: Graph, ecomp &: Vector < int >): int The biconnected components of the edges.
The example for this item is shown with the ones above: graph-Search.salam
func IsBiconnected (g &: Graph): bool True when the graph is biconnected.
The example for this item is shown with the ones above: graph-Search.salam
func IsTwoEdgeConnected (g &: Graph): bool True when the graph is connected and has no bridge.
The example for this item is shown with the ones above: graph-Search.salam
func TwoEdgeComponents (g &: Graph, comp &: Vector < int >): int The two-edge-connected components.
The example for this item is shown with the ones above: graph-Search.salam
func NewMatrix (rows: int , cols: int ): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func NewIntMatrix (rows: int , cols: int , fill: int ): IntMatrix An integer matrix filled with one value.
The example for this item is shown with the ones above: graph-Paths.salam
func AdjacencyMatrix (g &: Graph): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func WeightMatrix (g &: Graph): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func DegreeMatrix (g &: Graph): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func LaplacianMatrix (g &: Graph): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func NormalizedLaplacian (g &: Graph): Matrix The normalized Laplacian.
The example for this item is shown with the ones above: graph-Analysis.salam
func IncidenceMatrix (g &: Graph): Matrix The node-edge incidence matrix.
The example for this item is shown with the ones above: graph-Analysis.salam
func MatrixMultiply (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func MatrixIdentity (n: int ): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func MatrixPower (x &: Matrix, k: int ): Matrix The example for this item is shown with the ones above: graph-Analysis.salam
func WalkCount (g &: Graph, k: int , u: int , v: int ): f64 The number of walks of length k.
The example for this item is shown with the ones above: graph-Paths.salam
func MaxClique (g &: Graph): Vector < int > The largest clique; for small graphs.
The example for this item is shown with the ones above: graph-Flow.salam
func CliqueNumber (g &: Graph): int The size of the largest clique.
The example for this item is shown with the ones above: graph-Flow.salam
func MaximumIndependentSet (g &: Graph): Vector < int > The largest independent set.
The example for this item is shown with the ones above: graph-Flow.salam
func IndependenceNumber (g &: Graph): int The example for this item is shown with the ones above: graph-Flow.salam
func VertexCoverNumber (g &: Graph): int The example for this item is shown with the ones above: graph-Flow.salam
func GreedyVertexCover (g &: Graph, cover &: Vector < bool >): int The example for this item is shown with the ones above: graph-Flow.salam
func BuildLCA (g &: Graph, root: int ): LCAIndex A lowest common ancestor index, by binary lifting.
The example for this item is shown with the ones above: graph-Trees.salam
func LCA (ix &: LCAIndex, u0: int , v0: int ): int The lowest common ancestor of two nodes.
The example for this item is shown with the ones above: graph-Trees.salam
func TreeDistance (ix &: LCAIndex, u: int , v: int ): int The distance between two nodes in the tree.
The example for this item is shown with the ones above: graph-Trees.salam
func PruferEncode (g &: Graph): Vector < int > The Prufer code of the tree.
The example for this item is shown with the ones above: graph-Trees.salam
func PruferDecode (code: Vector < int >): Graph A tree from a Prufer code.
The example for this item is shown with the ones above: graph-Trees.salam
func TreeIsomorphic (a &: Graph, b &: Graph): bool True when two trees are isomorphic.
The example for this item is shown with the ones above: graph-Trees.salam
func TreeCanonicalForm (g &: Graph): str The canonical form of the tree, in parentheses.
The example for this item is shown with the ones above: graph-Trees.salam
func LabeledTreeCount (n: int ): f64 The number of labeled trees, n to the power n minus two.
The example for this item is shown with the ones above: graph-Trees.salam
func TreeToString (g &: Graph, root: int ): str The tree as parenthesized text.
The example for this item is shown with the ones above: graph-Trees.salam
func EmptyGraph (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func CompleteGraph (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func CompleteBipartite (a: int , b: int ): Graph The complete bipartite graph.
The example for this item is shown with the ones above: graph-Build.salam
func PathGraph (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func CycleGraph (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func StarGraph (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func WheelGraph (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func GridGraph (rows: int , cols: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func HypercubeGraph (d: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func PetersenGraph (): Graph The example for this item is shown with the ones above: graph-Build.salam
func CirculantGraph (n: int , offsets: Vector < int >): Graph The circulant graph with the given offsets.
The example for this item is shown with the ones above: graph-Build.salam
func BalancedTree (branch: int , depth: int ): Graph A balanced tree with the given branching and depth.
The example for this item is shown with the ones above: graph-Build.salam
func ErdosRenyi (n: int , p: f64 ): Graph An Erdos-Renyi random graph with an edge probability.
The example for this item is shown with the ones above: graph-Build.salam
func RandomGraph (n: int , m: int ): Graph A random graph with m edges.
The example for this item is shown with the ones above: graph-Build.salam
func RandomTree (n: int ): Graph The example for this item is shown with the ones above: graph-Build.salam
func BarabasiAlbert (n: int , m: int ): Graph A Barabasi-Albert scale-free random graph.
The example for this item is shown with the ones above: graph-Build.salam
func WattsStrogatz (n: int , k: int , p: f64 ): Graph A Watts-Strogatz small-world graph.
The example for this item is shown with the ones above: graph-Build.salam
func FloydWarshall (g &: Graph): Matrix The distance of every pair.
The example for this item is shown with the ones above: graph-Paths.salam
func FloydWarshallPaths (g &: Graph, next &: IntMatrix): Matrix The same, with a next-step matrix.
The example for this item is shown with the ones above: graph-Paths.salam
func FloydPath (next &: IntMatrix, s: int , t: int ): Vector < int > A path from the next-step matrix.
The example for this item is shown with the ones above: graph-Paths.salam
func Johnson (g &: Graph): Matrix The distance of every pair in a sparse graph with negative weights.
The example for this item is shown with the ones above: graph-Paths.salam
func AStar (g &: Graph, src: int , target: int , heuristic: Vector < f64 >): Vector < int > A* search with an estimate of the distance to the target.
The example for this item is shown with the ones above: graph-Paths.salam
func KShortestLengths (g &: Graph, s: int , t: int , k: int ): Vector < f64 > The lengths of the k shortest paths.
The example for this item is shown with the ones above: graph-Paths.salam
func AllPairsHops (g &: Graph): IntMatrix The hop distance of every pair.
The example for this item is shown with the ones above: graph-Search.salam
func Components (g &: Graph, comp &: Vector < int >): int The component number of each node; returns the number of components.
The example for this item is shown with the ones above: graph-Search.salam
func ComponentCount (g &: Graph): int The number of components.
The example for this item is shown with the ones above: graph-Search.salam
func ComponentSizes (g &: Graph): Vector < int > The sizes of the components.
The example for this item is shown with the ones above: graph-Search.salam
func IsConnected (g &: Graph): bool True when the graph is connected.
The example for this item is shown with the ones above: graph-Search.salam
func IsBipartite (g &: Graph, color &: Vector < int >): bool True when the graph is bipartite; fills in the two-side coloring.
The example for this item is shown with the ones above: graph-Search.salam
func Bipartite (g &: Graph): bool True when the graph is bipartite.
The example for this item is shown with the ones above: graph-Search.salam
func TopologicalSort (g &: Graph, order &: Vector < int >): bool The topological order of a directed graph; false when there is a cycle.
The example for this item is shown with the ones above: graph-Search.salam
func TopologicalSortLex (g &: Graph, order &: Vector < int >): bool The topological order, taking the smallest number at each step.
The example for this item is shown with the ones above: graph-Search.salam
func IsDAG (g &: Graph): bool True when the directed graph has no cycle.
The example for this item is shown with the ones above: graph-Search.salam
func FindCycle (g &: Graph): Vector < int > The example for this item is shown with the ones above: graph-Search.salam
func HasCycle (g &: Graph): bool True when there is a cycle.
The example for this item is shown with the ones above: graph-Search.salam
func NewFlowNet (n: int ): FlowNet A flow network with n nodes.
The example for this item is shown with the ones above: graph-Flow.salam
func FlowFromGraph (g &: Graph): FlowNet A flow network from a graph, with the weights as capacities.
The example for this item is shown with the ones above: graph-Flow.salam
func MaxFlow (f &: FlowNet, s: int , t: int ): f64 The maximum flow, with Dinic.
The example for this item is shown with the ones above: graph-Flow.salam
func MaxFlowEdmondsKarp (f &: FlowNet, s: int , t: int ): f64 The maximum flow, with Edmonds-Karp.
The example for this item is shown with the ones above: graph-Flow.salam
func MinCut (f &: FlowNet, s: int , t: int , side &: Vector < bool >): f64 The minimum cut and the source side.
The example for this item is shown with the ones above: graph-Flow.salam
func MaxFlowValue (g &: Graph, s: int , t: int ): f64 The maximum flow in a graph.
The example for this item is shown with the ones above: graph-Flow.salam
func MinCutEdges (g &: Graph, s: int , t: int , cut &: Vector < int >): f64 The edges of the minimum cut.
The example for this item is shown with the ones above: graph-Flow.salam
func MinCostFlow (f &: FlowNet, s: int , t: int , want: f64 , sent &: f64 ): f64 The flow with the lowest cost; also fills in the amount sent.
The example for this item is shown with the ones above: graph-Flow.salam
func DegreeCentrality (g &: Graph): Vector < f64 > The example for this item is shown with the ones above: graph-Analysis.salam
func InDegreeCentrality (g &: Graph): Vector < f64 > The in-degree centrality.
The example for this item is shown with the ones above: graph-Analysis.salam
func OutDegreeCentrality (g &: Graph): Vector < f64 > The out-degree centrality.
The example for this item is shown with the ones above: graph-Analysis.salam
func ClosenessCentrality (g &: Graph): Vector < f64 > The closeness centrality.
The example for this item is shown with the ones above: graph-Analysis.salam
func HarmonicCentrality (g &: Graph): Vector < f64 > The example for this item is shown with the ones above: graph-Analysis.salam
func BetweennessCentrality (g &: Graph): Vector < f64 > The betweenness centrality, with Brandes.
The example for this item is shown with the ones above: graph-Analysis.salam
func EdgeBetweenness (g &: Graph): Vector < f64 > The betweenness of the edges.
The example for this item is shown with the ones above: graph-Analysis.salam
func EigenvectorCentrality (g &: Graph, iters: int , tol: f64 ): Vector < f64 > The eigenvector centrality.
The example for this item is shown with the ones above: graph-Analysis.salam
func KatzCentrality (g &: Graph, alpha: f64 , beta: f64 , iters: int , tol: f64 ): Vector < f64 > The example for this item is shown with the ones above: graph-Analysis.salam
func PageRank (g &: Graph, damping: f64 , iters: int , tol: f64 ): Vector < f64 > Page ranking, as Google does it.
The example for this item is shown with the ones above: graph-Analysis.salam
func HITS (g &: Graph, iters: int , tol: f64 , hubs &: Vector < f64 >, auth &: Vector < f64 >) The hub and authority scores.
The example for this item is shown with the ones above: graph-Analysis.salam
func TopNode (score: Vector < f64 >): int The node with the highest score.
The example for this item is shown with the ones above: graph-Analysis.salam
func ScaleToSum (v &: Vector < f64 >) Normalizes the scores so they sum to one.
The example for this item is shown with the ones above: graph-Analysis.salam
func KCore (g &: Graph, k: int , alive &: Vector < bool >): int The example for this item is shown with the ones above: graph-Flow.salam
func CoreNumbers (g &: Graph): Vector < int > The core number of each node.
The example for this item is shown with the ones above: graph-Flow.salam
func Degeneracy (g &: Graph): int The example for this item is shown with the ones above: graph-Flow.salam
func Modularity (g &: Graph, comm: Vector < int >): f64 The modularity of a partition.
The example for this item is shown with the ones above: graph-Flow.salam
func LabelPropagation (g &: Graph, comm &: Vector < int >): int Communities by label propagation.
The example for this item is shown with the ones above: graph-Flow.salam
func Louvain (g &: Graph, comm &: Vector < int >): int Communities with Louvain.
The example for this item is shown with the ones above: graph-Flow.salam
func GirvanNewman (g &: Graph, want: int , comm &: Vector < int >): int Communities by removing the edges with the highest betweenness.
The example for this item is shown with the ones above: graph-Flow.salam
func Determinant (x &: Matrix): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func SpanningTreeCount (g &: Graph): f64 The number of spanning trees, by Kirchhoff's theorem.
The example for this item is shown with the ones above: graph-Trees.salam
func SymmetricEigenvalues (x &: Matrix): Vector < f64 > The eigenvalues of a symmetric matrix.
The example for this item is shown with the ones above: graph-Analysis.salam
func AdjacencySpectrum (g &: Graph): Vector < f64 > The example for this item is shown with the ones above: graph-Analysis.salam
func LaplacianSpectrum (g &: Graph): Vector < f64 > The example for this item is shown with the ones above: graph-Analysis.salam
func SpectralRadius (g &: Graph): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func AlgebraicConnectivity (g &: Graph): f64 The algebraic connectivity, the second eigenvalue of the Laplacian.
The example for this item is shown with the ones above: graph-Analysis.salam
func ToEdgeList (g &: Graph): str The example for this item is shown with the ones above: graph-Build.salam
func FromEdgeList (text: str , n: int , directed: bool ): Graph A graph from text, one "from to weight" per line, where the weight is optional.
The example for this item is shown with the ones above: graph-Build.salam
func ToAdjacencyList (g &: Graph): str The adjacency list as text.
The example for this item is shown with the ones above: graph-Build.salam
func ToMatrixText (g &: Graph): str The adjacency matrix as text.
The example for this item is shown with the ones above: graph-Build.salam
func ToDot (g &: Graph): str Graphviz DOT text, for drawing.
The example for this item is shown with the ones above: graph-Build.salam
func ToMermaid (g &: Graph): str Mermaid text, for drawing in Markdown.
The example for this item is shown with the ones above: graph-Build.salam
func ToJSON (g &: Graph): str JSON of the nodes and edges, suited to D3.
The example for this item is shown with the ones above: graph-Build.salam
func Describe (g &: Graph): str A one-line summary of the properties.
The example for this item is shown with the ones above: graph-Build.salam
func LocalClustering (g &: Graph, u: int ): f64 The clustering coefficient of a node.
The example for this item is shown with the ones above: graph-Analysis.salam
func AverageClustering (g &: Graph): f64 The example for this item is shown with the ones above: graph-Analysis.salam
func Transitivity (g &: Graph): f64 The transitivity, the ratio of triangles.
The example for this item is shown with the ones above: graph-Analysis.salam
func TriangleCount (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func Assortativity (g &: Graph): f64 The degree assortativity.
The example for this item is shown with the ones above: graph-Analysis.salam
func CircuitRank (g &: Graph): int The example for this item is shown with the ones above: graph-Analysis.salam
func WeightedDiameter (g &: Graph): f64 The example for this item is shown with the ones above: graph-Analysis.salam