Skip to content

Commit

Permalink
updated driver class to test Graph operations
Browse files Browse the repository at this point in the history
  • Loading branch information
NirmalSilwal committed Apr 15, 2021
1 parent d8795ab commit f02a661
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions Interview Prep/section20_Graph/GraphClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package section20_Graph;

import java.util.ArrayList;
import java.util.HashMap;

public class GraphClient {
Expand Down Expand Up @@ -111,11 +112,42 @@ public static void main(String[] args) {
// graph.depthFirstTraversal();

/* test 8 */
System.out.println("cyclic: " + graph.isCyclic()); // true
graph.removeEdge("C", "D");
System.out.println("cyclic: " + graph.isCyclic()); // true
graph.removeEdge("F", "G");
System.out.println("cyclic: " + graph.isCyclic()); // false

// System.out.println("cyclic: " + graph.isCyclic()); // true
// graph.removeEdge("C", "D");
// System.out.println("cyclic: " + graph.isCyclic()); // true
// graph.removeEdge("F", "G");
// System.out.println("cyclic: " + graph.isCyclic()); // false

/* test 9 */

// System.out.println("is connected Graph: " + graph.isConnected()); //
// true
// System.out.println("removing Edge DE");
// graph.removeEdge("D", "E");
// System.out.println("is connected Graph: " + graph.isConnected()); //
// false

/* test 10 */

// System.out.println("is Tree: " + graph.isTree()); // false
// graph.removeEdge("C", "D");
// graph.removeEdge("F", "G");
// System.out.println("is Tree: " + graph.isTree()); // true

/* test 11 */

ArrayList<ArrayList<String>> cc = graph.getConnectedComponents();
System.out.println(cc); // [[A, B, D, C, E, F, G]]

graph.removeEdge("D", "E");
ArrayList<ArrayList<String>> ccRemovedEdge = graph.getConnectedComponents();
System.out.println(ccRemovedEdge); // [[A, B, D, C], [E, F, G]]

graph.addVertex("H");
ArrayList<ArrayList<String>> ccAddedVtx = graph.getConnectedComponents();
System.out.println(ccAddedVtx); // [[A, B, D, C], [E, F, G], [H]]


}
}

0 comments on commit f02a661

Please sign in to comment.