graph algorithms class graph """representation of simple graph using an adjacency map "" def init (selfdirected=false) """create an empty graph (undirectedby default graph is directed if optional paramter is set to true "" self outgoing only create second map for directed graphuse alias for undirected self incoming if directed else self outgoing def is directed(self) """return true if this is directed graphfalse if undirected property is based on the original declaration of the graphnot its contents "" return self incoming is not self outgoing directed if maps are distinct def vertex count(self) """return the number of vertices in the graph "" return len(self outgoing def vertices(self) """return an iteration of all vertices of the graph "" return self outgoing keys def edge count(self) """return the number of edges in the graph "" total sum(len(self outgoing[ ]for in self outgoing for undirected graphsmake sure not to double-count edges return total if self is directedelse total / def edges(self) """return set of all edges of the graph "" result setavoid double-reporting edges of undirected graph for secondary map in self outgoing values)add edges to resulting set result update(secondary map values) return result code fragment graph class definition (continued in code fragment