Skip to content

Commit 1ef46db

Browse files
authored
Update GraphAlgos
1 parent 01d5814 commit 1ef46db

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

DataStructures/Graphs/GraphAlgos

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
package DataStructures.Graphs;
2+
/*
3+
Implementation of graph by using hashmap for vertices of class which contains hashmap for vertex and then algos like prims dijktsra ,depth for search and traversal ,breadth for search and traversal ,algo for cycle present or not ,connected or not ,if not connected then connect it
4+
Test case
5+
Graph gp=new Graph();
6+
gp.addVertex("A");
7+
gp.addVertex("B");
8+
gp.addVertex("C");
9+
gp.addVertex("D");
10+
gp.addVertex("E");
11+
gp.addVertex("F");
12+
gp.addVertex("G");
13+
gp.addEdge("A", "B", 2);
14+
gp.addEdge("A", "D", 10);
15+
gp.addEdge("B", "C", 3);
16+
gp.addEdge("C", "D", 1);
17+
gp.addEdge("D", "E", 8);
18+
gp.addEdge("E", "F", 5);
19+
gp.addEdge("E", "G", 6);
20+
gp.addEdge("F", "G", 4);
21+
22+
// gp.display();
23+
// System.out.println(gp.numVertex());
24+
// System.out.println(gp.numEdge());
25+
// System.out.println(gp.containsEdge("A", "C"));
26+
//
27+
// System.out.println(gp.containsEdge("E", "F"));
28+
// gp.removeEdge("D", "E");
29+
// gp.display();
30+
// gp.removeVertex("F");
31+
// gp.addVertex("F");
32+
// gp.display();
33+
// System.out.println(gp.hasPath("A", "F", new HashMap<>()));
34+
// System.out.println(gp.dfs("A", "F"));
35+
// gp.bft();
36+
// gp.dft();
37+
// gp.removeEdge("B","C");
38+
// gp.removeEdge("F","G");
39+
// System.out.println(gp.isConnected());
40+
// System.out.println(gp.isCyclic());
41+
// System.out.println(gp.isTree());
42+
// System.out.println(gp.getConnectedComp());
43+
// gp.prims().display();
44+
System.out.println(gp.Dijktsra("A"));
45+
46+
47+
48+
*/
49+
50+
151
import java.util.ArrayList;
252
import java.util.HashMap;
353
import java.util.LinkedList;

0 commit comments

Comments
 (0)