Complete the code to add a new vertex to the graph.
graph.vertices.push([1]);Vertices are usually represented by labels like 'A', 'B', etc. Here, adding 'A' as a vertex makes sense.
Complete the code to add an edge between two vertices in an undirected graph.
graph.edges.push({ from: 'A', to: [1] });To connect vertex 'A' to 'B', the edge should have 'to' as 'B'.
Fix the error in the code to correctly represent a weighted edge.
graph.edges.push({ from: 'A', to: 'B', weight: [1] });Weights should be numbers, so 5 without quotes is correct.
Fill both blanks to create a directed edge from 'X' to 'Y' with weight 10.
graph.edges.push({ from: [1], to: [2], weight: 10 });The edge goes from 'X' to 'Y', so 'from' is 'X' and 'to' is 'Y'.
Fill all three blanks to create an undirected weighted edge between 'M' and 'N' with weight 7.
graph.edges.push({ from: [1], to: [2], weight: [3] });For an edge between 'M' and 'N' with weight 7, use 'M' and 'N' as vertices and 7 as weight.
