Eng101W07 Sec 100
Homework 9:
Graphs, Adjacency matrices, and Hubs
1. [10 pts.] Load up adjacency matrices for star and line graphs
Write functions to create adjacency matrices for star and line graphs for an arbitrary number of vertices. To
simplify this process, please do the following. For the
star
graph, let the first vertex be the
hub
. This yields
an adjacency matrix with (i) ones along the top row and the leftmost column, with (ii) the exception that
there is a zero in the upper left corner of the matrix. For the line graph, order your rows (columns)
according to the “left to right path”. This yields an adjacency matrix is ones along the first offdiagonals
above
and
below
the main diagonal.
Test your function for a 6vertex graph. Write your main function to create the star and linear graphs.
Include your two functions and your main below, along with a console printout of your two adjacency
matrices (use the function
outputMat
, as in HW8).
Solution
.
•
Console output
[chiaroscuro:~/RENOVATE/Eng101/cpp_projects] gregoryw% .//a.out
Adjacency matrix for the Star graph
[ 0
1
1
1
1
1
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0]
Adjacency matrix for the Line graph
[ 0
1
0
0
0
0
1
0
1
0 0
0
0
1
0
1
0
0
0
0
1
0
1
0
0
0
0
1
0
1
0
0
0
0
1
0]
•
Code: two functions (makeStar, makeLine) and main
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
2. [10 pts.] Computing powers of the adjacency matrix
Write a generalpurpose function that multiplies two square matrices. Feel free to use code we’ve already
written, but note your function should be able to handle any size matrix. Test this function as follows: using
the
star
matrix you created in 1, multiply the star matrix by itself (that is, compute A
2
). Include your
multiplication function and
main
code below, along with the console output for A
2
. (If all goes well, your
squared matrix should have a 5 in the upper left corner, 0’s otherwise along the top row and leftmost
column, and a 5x5 submatrix of 1’s below and to the right of the top row and leftmost column.)
Solution
.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '07
 Ringenberg
 Graph Theory, Derivative, Matrices, line graph, adjacency matrix

Click to edit the document details