3.1 45pts first implement kruskal’s

Info iconThis preview shows pages 5–7. 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 Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3.1 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 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 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 : 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 55pts Dijkstra’s algorithm is essentially an extension of breadth-first search for weighted graphs. It produces the shortest path between given source and destination nodes in a directed graph with non-negative edge weights. Pseudocode for Dijkstra’s algorithm is given in page 655 of your text- book....
View Full Document

{[ snackBarMessage ]}

Page5 / 10

3.1 45pts First implement Kruskal’s...

This preview shows document pages 5 - 7. Sign up to view the full document.

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