Question: This lab will read in the array-pointer representation of a graph, tell which nodes are isolated, and print out the adjacency matrix. There will be
This lab will read in the array-pointer representation of a graph, tell which nodes are isolated, and print out the adjacency matrix.
There will be no more than 5 nodes in the graph, and there will be no parallel edges, so the array-pointer must be size 30X2 (the graphs will be unweighted) and the adjacency matrix must be 5X5.
(note: That doesn't mean that all of that will actually be used or printed since there could be fewer nodes and fewer edges.)
The program will need to ask how many nodes are in the graph and how many rows are in the array-pointer prior to reading the array-pointer representation. It will then create the adjacency matrix, then print out which nodes are isolated followed by printing the adjacency matrix.
Note 1: -1 will mean end of list in the array-pointer. Note 2: numbering will start at 1 for the node names and index locations. Note 4: the array locations that are normally empty in an array-pointer that are for the head pointers for the lists will have the node names. This will make it easier to code. Note 5: Remember a graph can be directed so a node is really not isolated unless both its row and column in the adjacency matrix are 0, but you could shortcut by only checking the columns in the adjacency matrix of the nodes whose initial entry in the array-pointer is -1 (that guarantees a row of all 0's).
sample run:
Please input the number of nodes: 3 How many rows are in the array-pointer representation? 5 Please input the array-pointer representation of the graph: 1 4 2 5 3 -1 2 -1 1 -1 node 3 is isolated The adjacency matrix is 0 1 0 1 0 0 0 0 0
NO pointers, stucts, or classes can be used
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
