C++_HW9_Solutions - Eng101W07 Sec 100 Homework 9: Graphs,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 left-most 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 off-diagonals above and below the main diagonal. Test your function for a 6-vertex graph. Write your main function to create the star and linear graphs. Include your two functions and your main below, along with a console print-out 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 general-purpose 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 left-most column, and a 5x5 submatrix of 1s below and to the right of the top row and left-most column.) Solution . Console output [chiaroscuro:~/RENOVATE/Eng101/cpp_projects] gregoryw% .//a.out A-square 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 general-purpose 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.

Page1 / 7

C++_HW9_Solutions - Eng101W07 Sec 100 Homework 9: Graphs,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online