Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/python/algorithm_graph.py
1240 views
1
"""
2
Simplest possible graph representation.abs
3
4
In theory, Graph is represented with vertices "V" and edges "E". We use the same notation here.
5
6
Expected Output
7
---------------
8
9
['a', 'c', 'b']
10
True
11
True
12
"""
13
14
class Graph:
15
def __init__(self , g):
16
self.g = g
17
18
def V(self):
19
return list(self.g.keys())
20
21
def E(self, node1, node2):
22
return node2 in self.g[node1]
23
24
if __name__ == '__main__':
25
gobject = Graph({"a":["b","c"],"b":["e","c"],"c":["a","b"]})
26
print((gobject.V()))
27
print((gobject.E("a","c")))
28
print((gobject.E("b","e")))
29
30