@@ -41,7 +41,8 @@ class Graph {
4141 * Removes node from graph
4242 * It also removes the reference of the deleted node from
4343 * anywhere it was adjacent to.
44- * Runtime: O(|V| + |E|)
44+ * Runtime: O(|V|) because adjacency list is implemented with a HashSet.
45+ * It were implemented with an array then it would be O(|V| + |E|).
4546 * @param {any } value node's value
4647 */
4748 removeVertex ( value ) {
@@ -55,9 +56,9 @@ class Graph {
5556
5657 // tag::addEdge[]
5758 /**
58- * Create a connection between source node and destination node.
59- * If the graph is undirected it will also create the conneciton from destination to destination .
60- * If the nodes doesn 't exist then it will create them on the fly
59+ * Create a connection between the source node and the destination node.
60+ * If the graph is undirected, it will also create the link from destination to source .
61+ * If the nodes don 't exist, then it will make them on the fly.
6162 * Runtime: O(1)
6263 * @param {any } source
6364 * @param {any } destination
@@ -79,10 +80,11 @@ class Graph {
7980
8081 // tag::removeEdge[]
8182 /**
82- * Remove connection between source node and destination.
83- * If the graph is undirected it will also remove the conneciton from destination to destination .
83+ * Remove the connection between source node and destination.
84+ * If the graph is undirected, it will also create the link from destination to source .
8485 *
85- * Runtime: O(|E|)
86+ * Runtime: O(1): implemented with HashSet.
87+ * If implemented with array, would be O(|E|).
8688 *
8789 * @param {any } source
8890 * @param {any } destination
@@ -105,7 +107,7 @@ class Graph {
105107
106108 // tag::areAdjacents[]
107109 /**
108- * True if two nodes are adjacent to each other
110+ * True if two nodes are adjacent.
109111 * @param {any } source node's value
110112 * @param {any } destination node's value
111113 */
0 commit comments