This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 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 2. [10 pts.] Computing powers of the adjacency matrix Write a generalpurpose function that multiplies two square matrices. Feel free to use code weve 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, 0s otherwise along the top row and leftmost column, and a 5x5 submatrix of 1s below and to the right of the top row and leftmost column.) Solution . Console output [chiaroscuro:~/RENOVATE/Eng101/cpp_projects] gregoryw% .//a.out Asquare for Star matrix [ 5 0 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1] Code: 1 function (prodMat) and main 2. [10 pts.] Computing powers of the adjacency matrix Write a generalpurpose function that multiplies two square matrices. Feel free to use code weve already written, but note your function should be able to handle any size matrix. Test this function as follows: using written, but note your function should be able to handle any size matrix....
View
Full
Document
This note was uploaded on 04/04/2008 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.
 Fall '07
 Ringenberg

Click to edit the document details