9
9
use Fhaculty \Graph \Exception \InvalidArgumentException ;
10
10
use Fhaculty \Graph \Exception \UnderflowException ;
11
11
12
+ /**
13
+ * Algorithm for working with connected components
14
+ *
15
+ * @link http://en.wikipedia.org/wiki/Connected_component_%28graph_theory%29
16
+ * @link http://mathworld.wolfram.com/ConnectedGraph.html
17
+ * @link http://math.stackexchange.com/questions/50551/is-the-empty-graph-connected
18
+ */
12
19
class ConnectedComponents extends BaseGraph
13
20
{
14
21
/**
@@ -40,12 +47,21 @@ private function createSearch(Vertex $vertex)
40
47
/**
41
48
* check whether this graph consists of only a single component
42
49
*
43
- * this is faster than calling getNumberOfComponents(), as it only has to
50
+ * If a Graph consists of only a single component, it is said to be a
51
+ * connected Graph, otherwise it's called a disconnected Graph.
52
+ *
53
+ * This method returns exactly the same result as checking
54
+ * <pre>($this->getNumberOfComponents() === 1)</pre>. However, using this
55
+ * method is faster than calling getNumberOfComponents(), as it only has to
44
56
* count all vertices in one component to see if the graph consists of only
45
- * a single component
57
+ * a single component.
58
+ *
59
+ * As such, a null Graph (a Graph with no vertices) is not considered
60
+ * connected here.
46
61
*
47
62
* @return boolean
48
63
* @uses AlgorithmSearchBreadthFirst::getNumberOfVertices()
64
+ * @see self::getNumberOfComponents()
49
65
*/
50
66
public function isSingle ()
51
67
{
@@ -62,6 +78,10 @@ public function isSingle()
62
78
}
63
79
64
80
/**
81
+ * count number of connected components
82
+ *
83
+ * A null Graph (a Graph with no vertices) will return 0 components.
84
+ *
65
85
* @return int number of components
66
86
* @uses Graph::getVertices()
67
87
* @uses AlgorithmSearchBreadthFirst::getVerticesIds()
0 commit comments