Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class ListGraph(object): | |
def __init__(self, number_of_vertices): | |
self.number_of_vertices = number_of_vertices | |
self.matrix = [[0] * number_of_vertices for _ in range(number_of_vertices)] | |
def add_edge(self, v1, v2): | |
self.matrix[v1][v2] = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class Graph(dict): | |
def __init__(self, vertex_list, edge_list): | |
for v in vertex_list: | |
self[v] = set() | |
for e in edge_list: | |
self.add_edge(e) |