Complete the code to declare an adjacency matrix for a graph with 5 nodes.
int[,] adjacencyMatrix = new int[5, [1]];
An adjacency matrix for a graph with 5 nodes is a 5x5 matrix, so both dimensions are 5.
Complete the code to add an edge from node 2 to node 3 in an adjacency list.
adjacencyList[2].[1](3);
To add an edge in an adjacency list, you use the Add method to add the connected node.
Fix the error in the code that initializes an adjacency list for 4 nodes.
List<int>[] adjacencyList = new List<int>[[1]]; for (int i = 0; i < 4; i++) { adjacencyList[i] = new List<int>(); }
The array size must match the number of nodes, which is 4 here.
Fill both blanks to create a condition that checks if the graph is dense (more than half possible edges) using adjacency matrix.
if (edgeCount [1] (nodeCount * (nodeCount - 1) / 2)) { Console.WriteLine("Graph is dense"); }
A graph is dense if the number of edges is greater than half the maximum possible edges.
Fill all three blanks to create a dictionary comprehension that maps each node to its degree using adjacency list.
var degrees = new Dictionary<int, int>() {
{ [1], adjacencyList[[2]].[3] }
};Each node maps to the count of its adjacency list, which is the degree.
