Complete the code to declare a graph vertex as a struct with an ID.
type Vertex struct {
ID [1]
}In Go, struct fields are declared as 'Name Type', and vertex IDs are integers (int).
Complete the code to add an edge from vertex u to vertex v in a directed graph adjacency list.
graph[u] = append(graph[u], [1])To add an edge from u to v, we append v to u's adjacency list.
Fix the error in the code to correctly check if an edge exists from u to v in an undirected graph.
for _, neighbor := range graph[[1]] { if neighbor == v { return true } } return false
We must iterate over the adjacency list of u to check if v is a neighbor.
Fill both blanks to define a weighted edge struct with to and weight fields.
type Edge struct {
to [1]
weight [2]
}The target vertex is an integer ID, and weight is a floating-point number.
Fill all three blanks to create a map representing an undirected weighted graph adjacency list.
graph := map[int][][1] { 1: [][2] { {to: 2, weight: 3.5} }, 2: [][3] { {to: 1, weight: 3.5} }, }
The graph maps integers to slices of Edge structs representing weighted connections.
