Graph Class Implementation
In this course, weβll use Graph
implementation as class:
1234567891011121314class Graph: def __init__(self, vertices): # init graph with its vertices self.graph = {v : [] for v in vertices} def addEdge(self, u, v): self.graph[u].append(v) def __str__(self): out = "" for vertex in self.graph: out += vertex + ":"+self.graph[vertex] return out
This works for oriented graph. Main methods are implemented, and youβll add some methods according to the next tasks.
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Summarize this chapter
Explain the code in file
Explain why file doesn't solve the task
Awesome!
Completion rate improved to 7.69
Graph Class Implementation
Swipe to show menu
In this course, weβll use Graph
implementation as class:
1234567891011121314class Graph: def __init__(self, vertices): # init graph with its vertices self.graph = {v : [] for v in vertices} def addEdge(self, u, v): self.graph[u].append(v) def __str__(self): out = "" for vertex in self.graph: out += vertex + ":"+self.graph[vertex] return out
This works for oriented graph. Main methods are implemented, and youβll add some methods according to the next tasks.
Everything was clear?
Thanks for your feedback!
Awesome!
Completion rate improved to 7.69SectionΒ 1. ChapterΒ 2
single