<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>numConnectedComponents -- returns the number of connected components in a (hyper)graph</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_num__Connected__Graph__Components.html">next</a> | <a href="_neighbors.html">previous</a> | <a href="_num__Connected__Graph__Components.html">forward</a> | <a href="_neighbors.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <hr/> <div><h1>numConnectedComponents -- returns the number of connected components in a (hyper)graph</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>d = numConnectedComponents H</tt></div> </dd></dl> </div> </li> <li><div class="single">Inputs:<ul><li><span><tt>H</tt>, <span>a <a href="___Hyper__Graph.html">hypergraph</a></span></span></li> </ul> </div> </li> <li><div class="single">Outputs:<ul><li><span><tt>d</tt>, <span>an <a href="../../Macaulay2Doc/html/___Z__Z.html">integer</a></span>, the number of connected components of <tt>H</tt></span></li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div><p>This function returns the number of connected components of a hypergraph. A connected component of a hypergraph is any maximal set of vertices which are pairwise connected by a non-trivial path. Isolated vertices, which are those not appearing in any edge, do not count as connected components. This is in contrast to <a href="_num__Connected__Graph__Components.html" title="returns the number of connected components in a graph">numConnectedGraphComponents</a> in which isolated vertices are counted as connected components. See the <a href="___Connected_sp__Components_sp__Tutorial.html" title="clarifying the difference between graph and hypergraph components">Connected Components Tutorial</a> for more information.</p> <p>The algorithm used by <tt>numConnectedComponents</tt> turns <tt>H</tt> into a simplicial complex, and then computes the rank of the 0<sup>th</sup> reduced homology group. This number plus 1 gives the number of connected components of <tt>H</tt>.</p> <p>We depart from this method in two cases: We define the hypergraph with only the empty edge (corresponding to the irrelevant simplicial complex) and the hypergraph with empty edge set (corresponding to the void simplicial complex) to have 0 connected components.</p> <div>Although this method can be applied to graphs, its output does not match the most common meaning for the number of connected components of a graph. Instead, one should use <a href="_num__Connected__Graph__Components.html" title="returns the number of connected components in a graph">numConnectedGraphComponents</a>.</div> <table class="examples"><tr><td><pre>i1 : S = QQ[a..e];</pre> </td></tr> <tr><td><pre>i2 : g = graph {a*b,b*c,c*d,d*e,a*e} -- the 5-cycle (connected) o2 = Graph{edges => {{a, b}, {b, c}, {c, d}, {a, e}, {d, e}}} ring => S vertices => {a, b, c, d, e} o2 : Graph</pre> </td></tr> <tr><td><pre>i3 : h = graph {a*b,b*c,c*a,d*e} -- a 3-cycle and a disjoint edge (not connected) o3 = Graph{edges => {{a, b}, {a, c}, {b, c}, {d, e}}} ring => S vertices => {a, b, c, d, e} o3 : Graph</pre> </td></tr> <tr><td><pre>i4 : numConnectedComponents g o4 = 1</pre> </td></tr> <tr><td><pre>i5 : numConnectedComponents h o5 = 2</pre> </td></tr> </table> <div>The following example contains a hypergraph with an edge of size one. The vertex in this edge is not considered isolated and does count as a connected component.</div> <table class="examples"><tr><td><pre>i6 : S = QQ[a..d];</pre> </td></tr> <tr><td><pre>i7 : H = hyperGraph {a*b,c} o7 = HyperGraph{edges => {{a, b}, {c}} } ring => S vertices => {a, b, c, d} o7 : HyperGraph</pre> </td></tr> <tr><td><pre>i8 : isolatedVertices H o8 = {d} o8 : List</pre> </td></tr> <tr><td><pre>i9 : connectedComponents H o9 = {{a, b}, {c}} o9 : List</pre> </td></tr> <tr><td><pre>i10 : numConnectedComponents H o10 = 2</pre> </td></tr> </table> </div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="___Connected_sp__Components_sp__Tutorial.html" title="clarifying the difference between graph and hypergraph components">Connected Components Tutorial</a> -- clarifying the difference between graph and hypergraph components</span></li> <li><span><a href="_connected__Components.html" title="returns the connected components of a hypergraph">connectedComponents</a> -- returns the connected components of a hypergraph</span></li> <li><span><a href="_num__Connected__Graph__Components.html" title="returns the number of connected components in a graph">numConnectedGraphComponents</a> -- returns the number of connected components in a graph</span></li> <li><span><a href="_is__Connected.html" title="determines if a (hyper)graph is connected">isConnected</a> -- determines if a (hyper)graph is connected</span></li> <li><span><a href="_isolated__Vertices.html" title="returns all vertices not contained in any edge">isolatedVertices</a> -- returns all vertices not contained in any edge</span></li> </ul> </div> <div class="waystouse"><h2>Ways to use <tt>numConnectedComponents</tt> :</h2> <ul><li>numConnectedComponents(HyperGraph)</li> </ul> </div> </div> </body> </html>