Skip to content

Commit

Permalink
Adding more stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
br80 committed May 13, 2019
1 parent c649b54 commit 251e14d
Showing 1 changed file with 62 additions and 17 deletions.
79 changes: 62 additions & 17 deletions projects/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,75 @@ class Graph:
def __init__(self):
self.vertices = {}
def add_vertex(self, vertex):
"""
Add a vertex to the graph.
"""
pass # TODO
def add_edge(self, v1, v2):
"""
Add a directed edge to the graph.
"""
pass # TODO
def bft(self, starting_vertex):
"""
Print each vertex in breadth-first order
beginning from starting_vertex.
"""
pass # TODO
def dft(self, starting_vertex):
"""
Print each vertex in depth-first order
beginning from starting_vertex.
"""
pass # TODO
def dft_recursive(self, starting_vertex):
"""
Print each vertex in depth-first order
beginning from starting_vertex.
This should be done using recursion.
"""
pass # TODO
def bfs(self, starting_vertex, destination_vertex):
"""
Return a list containing the shortest path from
starting_vertex to destination_vertex in
breath-first order.
"""
pass # TODO
def dfs(self, starting_vertex, destination_vertex):
"""
Return a list containing a path from
starting_vertex to destination_vertex in
depth-first order.
"""
pass # TODO





if __name__ == '__main__':
graph = Graph() # Instantiate your graph
graph.add_vertex('1')
graph.add_vertex('2')
graph.add_vertex('3')
graph.add_vertex('4')
graph.add_vertex('5')
graph.add_vertex('6')
graph.add_vertex('7')
graph.add_edge('5', '3')
graph.add_edge('6', '3')
graph.add_edge('7', '1')
graph.add_edge('4', '7')
graph.add_edge('1', '2')
graph.add_edge('7', '6')
graph.add_edge('2', '4')
graph.add_edge('3', '5')
graph.add_edge('2', '3')
graph.add_edge('4', '6')
graph.add_vertex(1)
graph.add_vertex(2)
graph.add_vertex(3)
graph.add_vertex(4)
graph.add_vertex(5)
graph.add_vertex(6)
graph.add_vertex(7)
graph.add_edge(5, 3)
graph.add_edge(6, 3)
graph.add_edge(7, 1)
graph.add_edge(4, 7)
graph.add_edge(1, 2)
graph.add_edge(7, 6)
graph.add_edge(2, 4)
graph.add_edge(3, 5)
graph.add_edge(2, 3)
graph.add_edge(4, 6)
print(graph.vertices)
graph.dft(1)
graph.bft(1)
graph.dft_recursive(1)
print(graph.bfs(1, 4))
print(graph.dfs(1, 4))

0 comments on commit 251e14d

Please sign in to comment.