This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 3.1 MSTKruskal.java 45pts First, implement Kruskal’s algorithm in order to finding a minimum spanning tree. To reiterate what you have learnt / will learn in class, a spanning tree is a subgraph S of a connected, weighted graph G such that for all u in G, u is an element of S connected to all v in S. A minimum spanning tree is a spanning tree with the minimal weight across all its edges. We require your implementation of Kruskal’s algorithm to run in O(ElogV) , with E being the number of edges and V being the number of nodes. You should return a HashSet<Edge> and also output to a file called MST.out in the following format: 123;345 325;345 345;789 Each number is the Fakebook ID of a node. In the example above, each line represents a single edge from one node to another, e.g. the first line represents an edge from node 123 to 345. The example above represents an MST of the following graph (with edge weights = 1000/(mutual friends + 1), or 500, 500, 500, 1000 from left to right): Note that there can be multiple valid MSTs for a particular graph. If this is the case, returning any of them is fine. 5 Once you have completed this task, generate a file MST.out using the input 300.json. Now, you will visualize the results of your calculations with Gephi, a graph visualization tool. Download Gephi from https://gephi.org/users/download/. Save the contents of MST.out into a csv filed called MST.csv. To load your graph, click “File”, select “Open”, locate your MST.csv, and then press “Open”. In Graph Type, choose the “Undirected” tab, and then press OK. Your graph should now appear (If not, select Window — Graph). Play with your graph a bit  change the layout (on the left side) so you can better see the spanning tree, show the node labels, color the graph. You won’t be able to draw the graph such that no edges cross. Once the graph looks meaningful (just a blob of nodes and edges will receive no credit), take a screenshot of your graph and save it as MST.jpg. Feel free to use Gephi to visualize your graph at any point by saving the edges in a csv file and following the above instructions. 3.2 Measures of Centrality The following exercises will examine different ways of defining metrics for social graphs. 3.2.1 DegreeCentrality.java 10pts Degree centrality is the simplest measure of centrality and is defined as the number of edges that are incident on a node. Find the degree centrality for a given node in our friend graph by implementing the following method in DegreeCentrality.java : public static int getDegree(Set<Friend> people, String source) where people is the representation of the friend graph and source is the id of a Friend. If people is null or if source cannot be found in the graph, then throw an IllegalArgumentException. 3.2.2 Dijkstra.java 55pts Dijkstra’s algorithm is essentially an extension of breadthfirst search for weighted graphs. It produces the shortest path between given source and destination nodes in a directed graph with nonnegative edge weights. Pseudocode for Dijkstra’s algorithm is given in page 655 of your text book....
View
Full Document
 Spring '09
 TANNEN
 Algorithms, Graph Theory, Data Structures, JSON, Shortest path problem, friend graph

Click to edit the document details