Complete the code to initialize an adjacency matrix with zeros.
matrix := make([][]int, n) for i := 0; i < n; i++ { matrix[i] = make([]int, [1]) }
The adjacency matrix is a square matrix of size n x n, so each row must have length n.
Complete the code to add an edge from vertex u to vertex v in the adjacency matrix.
matrix[u][[1]] = 1
To add an edge from u to v, set matrix[u][v] to 1.
Fix the error in the code to check if there is an edge from vertex x to vertex y.
if matrix[[1]][y] == 1 { fmt.Println("Edge exists") }
The first index is the source vertex x, so use matrix[x][y].
Fill both blanks to correctly iterate over all edges in the adjacency matrix.
for [1] := 0; [1] < n; [1]++ { for [2] := 0; [2] < n; [2]++ { if matrix[[1]][[2]] == 1 { fmt.Printf("Edge from %d to %d\n", [1], [2]) } } }
Use i and j as loop variables to iterate over rows and columns of the matrix.
Fill all three blanks to create a function that returns true if there is an edge from a to b.
func hasEdge(matrix [][]int, [1] int, [2] [3]) bool { return matrix[[1]][[2]] == 1 }
The function parameters are a and b of type int, used to index the matrix.
