Dsapractice Durgesh
Dsapractice Durgesh
Dsapractice Durgesh
Topic Graph
Representation of graph-
1. Adjacency list
"""
"""
class AdjNode:
self.next = None
# vertices "V"
class Graph:
self.V = vertices
node = AdjNode(dest)
node.next = self.graph[src]
self.graph[src] = node
node = AdjNode(src)
node.next = self.graph[dest]
self.graph[dest] = node
def print_graph(self):
for i in range(self.V):
temp = self.graph[i]
while temp:
temp = temp.next
print(" \n")
if __name__ == "__main__":
V=5
graph = Graph(V)
graph.add_edge(0, 1)
graph.add_edge(0, 4)
graph.add_edge(1, 2)
graph.add_edge(1, 3)
graph.add_edge(1, 4)
graph.add_edge(2, 3)
graph.add_edge(3, 4)
graph.print_graph()