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.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 2
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Suggested prompts:
Oppsummer dette kapittelet
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 7.69
Graph Class Implementation
Sveip for å vise menyen
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.
Alt var klart?
Takk for tilbakemeldingene dine!
Awesome!
Completion rate improved to 7.69Seksjon 1. Kapittel 2
single