You are on page 1of 3

COMP 208: Computers in Engineering Winter, 2013 Assignment 3: Friends and More Friends

Due Date
Assignment 3 is due on Friday, February 22 at midnight. The cutoff is automated and is exactly at this time. Assignments submitted within the next hour will be considered late. After that time they will not be accepted at all. The assignment is to be done individually. You can collaborate on understanding the problem but you must write the solutions independently. Submissions might be subject to being checked by plagiarism detection software.

On a social network site (Facebook, LinkedIn, etc..) pairs of people can be friends. If Alice is friends with Bob and Carol and David is also friends with Bob and Carol, then Alice and David have two mutual friends. If Alice and David are not friends, the site might suggest to each of them that they might want to become friends (since they have at least two mutual friends). The purpose of this assignment is to examine the set of friends in a social network and discover pairs of people who are not friends but have mutual friends.

Your program should read a file containing a description of a social network. It should then output a list of suggested new friends for each pair of members of the network who have the most mutual friends.

Suppose the social network has n members. The set of friends can be represented by an n by n two dimensional matrix. The entry F(i,j) equals 0 if member i and member j are not friends and equals 1 if they are friends. We also require that the diagonal elements (F(i, i)) be equal to 0 since a person cannot be friends with him or herself in the network. We note that the matrix is symmetric since if members i and j are friends, then F(i,j) = F(j,i) = 1.

You will be provided with more sets of data on MyCourses for testing your program. the non-zero terms will be exactly those terms where F(i. given an n by n matrix. 5 or more than 5 mutual friends. Step 3: Define a subroutine which. followed by n lines which describe the “friends” of the corresponding member. It should output the results of this search.f90) and name your file A3_123456789 where 1234567898 is replaced by your student ID number. That means that members i and j have member k as a mutual friend. the top non-zero entry is the one with 3 mutual friends. counts the number of how many members have 0.j) are both 1. The matrix is symmetric so F2(i. Be careful not to double-count pairs of members.Now consider the result of multiplying F by itself to produce the matrix F2. For this sample data your program should output “suggested friends” for members are not already friends and have 2 or 3 mutual friends. Step 2: Define a subroutine to compute the product of two square n by n matrices. the sum counts the number of mutual friends that i and j have. In the sample data there is only one pair with 3 mutual friends but several with 2 mutual friends. 1. say F. Step 4: Output a list of “suggested friends”. do not output the same pair twice. Also be careful not to count the diagonal entries since a member cannot be friends with him or herself. Your program should use this subroutine to multiply the “friends” array by itself and produce the array F2. The subroutine should generate and return an array of length 7 with the counts for each category. Your program should use this subroutine to determine how interconnected the social network is. . Use meaningful variable names Comment and indent your code. In the sum. n. Your program should not make assumptions about the size of the data set other than to assume a maximum size such as 1000. The file will consist of a line with the number of members of the array. It is your responsibility to make it readable to the grader Submit only the source file (.i) will have the same values but should only be counted once. 2. In short. In the sample data provided below. The suggested friends are those in the top two non-zero categories. 3. Methodology Step 1: Read a data file describing a social network into a two dimensional array. Again.j) and F2(j.k) and F(k. Requirements The programs must be written in Fortran Define and use the subroutines as described above. The values in this matrix are defined (using matrix multiplication) as . 4. A sample of data for a network with 27 members is provided below.

Sample Data 27 000000000000000000000010000 000000000001000000000000000 000000000001000000100001000 000000000000000010100000000 000000001001100000000000000 000000000100000000000000101 000000001010001010100010001 000000000000000000000000100 000010100010000000101100010 000001000001100000001000000 000000101000000000000000000 011010000100000000000000000 000010000100010010001001000 000000000000101100000000010 000000100000010000000001000 000000000000010000000000000 000100100000100001010000100 000000000000000010000001000 001100101000000000000001100 000000000000000010001000000 000000001100100000010010001 000000001000000000000000100 100000100000000000001000000 001000000000101001100000000 000001010000000010100100000 000000001000010000000000000 000001100000000000001000000 .