A certain undirected graph G has n vertices. An n x n adjacency matrix A can be used to store the weight of the edges in G (assumed positive). However, it is more efficient to use a one-dimensional array.
Explain how the data in A can be stored in a one-dimensional array B, conserving storage as much as possible.
Write a function, edgeWeight, which accesses B to return the weight of the edge between vertex i and vertex j. If there is no such edge, it returns -1. The prototype of edgeWeight is as follows:
int edgeWeight(int i, int j);
Using the edgeWeight function from b), write another function minCostVertex, which given a vertex u, finds the edge with the least cost weight from u and returns the corresponding vertex. If there is no such edge, it returns -1. The prototype of minCostVertex is as follows:
int minCostVertex(int u);