Graph theory is the study of properties or invariants of graphs. Among the properties of interest are such things as connectivity, cycle structure, and chromatic number. Here, we demonstrate how to compute several different graph invariants.
An undirected graph is connected if there exists a path between any pair of vertices. Deleting an edge from a connected graph can disconnect it. Such an edge is called a bridge.
ConnectedQ[ DeleteEdge[ Star[10], {1,10} ] ]
GraphUnion can be used to create disconnected graphs.
ConnectedComponents[ GraphUnion[CompleteGraph[3],
CompleteGraph[4]] ]
An orientation of an undirected graph is an assignment of exactly one direction to each of the edges of . This orientation of a wheel directs each edge in the outer cycle in the same direction, and completes it by giving the center an indegree of and outdegree of 1.
ShowGraph[ OrientGraph[Wheel[10]],
Directed];
An articulation vertex of a graph is a vertex whose deletion disconnects . Any graph with no articulation vertices is said to be biconnected. A graph with a vertex of degree 1 cannot be biconnected, since deleting the other vertex that defines its only edge disconnects the graph.
BiconnectedComponents[
RealizeDegreeSequence[{4,4,3,3,3,2,1}] ]
The only articulation vertex of a star is its center, even though its deletion leaves connected components. Deleting a leaf leaves a connected tree.
ArticulationVertices[ Star[10] ]
Every edge in a tree is a bridge.
Bridges[ RandomTree[10] ]
A graph is said to be connected if there does not exist a set of vertices whose removal disconnects the graph. The wheel is the basic triconnected graph.
VertexConnectivity[Wheel[5]]
A graph is edgeconnected if there does not exist a set of edges whose removal disconnects the graph. The edge connectivity of a graph is at most the minimum degree , since deleting those edges disconnects the graph. Complete bipartite graphs realize this bound.
EdgeConnectivity[CompleteGraph[3,4]]
These two complete bipartite graphs are isomorphic, since the order of the two stages is simply reversed. Here, all isomorphisms are returned.
Isomorphism[CompleteGraph[3,2], CompleteGraph[2,3], All]
A graph is selfcomplementary if it is isomorphic to its complement. The smallest nontrivial selfcomplementary graphs are the path on four vertices and the cycle on five.
SelfComplementaryQ[ Cycle[5] ] &&
SelfComplementaryQ[ Path[4] ]
A directed graph with half the edges is almost certain to contain a cycle. Directed acyclic graphs are often called DAGs.
AcyclicQ[
RandomGraph[7,0.5,Directed], Directed]
The girth of a graph is the length of its shortest cycle. The girth of a complete graph is 3, since it contains a triangle, the smallest possible cycle.
Girth[ CompleteGraph[5] ]
An Eulerian cycle is a complete tour of all the edges of a graph. An Eulerian cycle of a bipartite graph bounces back and forth between the stages.
EulerianCycle[ CompleteGraph[4,4] ]
A Hamiltonian cycle of a graph is a cycle that visits every vertex in exactly once, as opposed to an Eulerian cycle, which visits each edge exactly once. for are the only Hamiltonian complete bipartite graphs.
HamiltonianCycle[CompleteGraph[3,3], All]
The divisibility relation between integers is reflexive since each integer divides itself and antisymmetric, since cannot divide if . Finally, it is transitive, as implies for some integer , so implies .
ShowLabeledGraph[
g = MakeGraph[Range[8],(Mod[#1,#2]==0)&] ];
Since the divisibility relation is reflexive, transitive, and antisymmetric, it is a partial order.
PartialOrderQ[g]
A graph is transitive if any three vertices such that edges imply . The transitive reduction of a graph is the smallest graph such that . The transitive reduction eliminates all implied edges in the divisibility relation, such as , , , and .
ShowLabeledGraph[TransitiveReduction[g]]
The Hasse diagram clearly shows the lattice structure of the Boolean algebra, the partial order defined by inclusion on the set of subsets.
ShowLabeledGraph[
HasseDiagram[MakeGraph[Subsets[4],
((Intersection[#2,#1]===#1)&&(#1 != #2))&]],
Subsets[4] ];
A topological sort is a permutation of the vertices of a graph such that an edge implies appears before in . A complete directed acyclic graph defines a total order, so there is only one possible output from TopologicalSort.
TopologicalSort[
MakeGraph[Range[10],(#1 > #2)&] ]
Any labeled graph can be colored in a certain number of ways with exactly colors . This number is determined by the chromatic polynomial of the graph.
ChromaticPolynomial[
GraphUnion[CompleteGraph[2,2], Cycle[3]], z ]
Combinatorica functions for properties of graphs.