Question: HELP SOLVE FOR INDIRECTPOPULARITY and SOCIALSTATUS Here is the graph class: public class Graph { private final int V; private int E; private final Bag

HELP SOLVE FOR INDIRECTPOPULARITY and SOCIALSTATUS

Here is the graph class:

public class Graph { private final int V; private int E; private final Bag[] adj;

/** * Create an empty graph with V vertices. */ @SuppressWarnings("unchecked") public Graph(int V) { if (V < 0) throw new Error("Number of vertices must be nonnegative"); this.V = V; this.E = 0; this.adj = new Bag[V]; for (int v = 0; v < V; v++) { adj[v] = new Bag<>(); } }

/** * Return the number of vertices in the graph. */ public int V() { return V; }

/** * Return the number of edges in the graph. */ public int E() { return E; }

/** * Add the undirected edge v-w to graph. * @throws java.lang.IndexOutOfBoundsException unless both 0 <= v < V and 0 <= w < V */ public void addEdge(int v, int w) { if (v < 0 || v >= V) throw new IndexOutOfBoundsException(); if (w < 0 || w >= V) throw new IndexOutOfBoundsException(); E++; adj[v].add(w); adj[w].add(v); }

/** * Return the list of neighbors of vertex v as in Iterable. * @throws java.lang.IndexOutOfBoundsException unless 0 <= v < V */ public Iterable adj(int v) { if (v < 0 || v >= V) throw new IndexOutOfBoundsException(); return adj[v]; }

/** * Returns the degree of vertex {@code v}. * * @param v the vertex * @return the degree of vertex {@code v} * @throws IllegalArgumentException unless {@code 0 <= v < V} */ public int degree(int v) { if (v < 0 || v >= V) throw new IndexOutOfBoundsException(); return adj[v].size(); }

/** * Return a string representation of the graph. */ public String toString() { StringBuilder s = new StringBuilder(); String NEWLINE = System.getProperty("line.separator"); s.append(V + " vertices, " + E + " edges " + NEWLINE); for (int v = 0; v < V; v++) { s.append(v + ": "); for (int w : adj[v]) { s.append(w + " "); } s.append(NEWLINE); } return s.toString(); }

/** * Save a graphviz representation of the graph. * See graphviz.org. */ public void toGraphviz(String filename) { GraphvizBuilder gb = new GraphvizBuilder (); for (int v = 0; v < V; v++) { gb.addNode (v); boolean showSelfLoop = false; for (int w : adj[v]) { if (v < w) // only once each edge gb.addEdge (v, w); if (v == w) { showSelfLoop = !showSelfLoop; if (showSelfLoop) gb.addEdge (v, w); } } } gb.toFileUndirected (filename); }

/** * Test client. */ public static void main(String[] args) { //args = new String [] { "data/tinyCG.txt" }; args = new String [] { "data/tinyG.txt" }; //args = new String [] { "20", "40" };

Graph G; if (args.length == 1) { In in = new In(args[0]); G = GraphGenerator.fromIn (in); } else { int V = Integer.parseInt (args[0]); int E = Integer.parseInt (args[1]); G = GraphGenerator.simple(V, E); } StdOut.println(G); G.toGraphviz ("g.png"); } }

NOW SOLVE FOR

**

* determineIndirectPopularity

*

* concept: people accrue social status from the people they associate with.

* and while an individual may not be 'popular', they may achieve some level

* of popularity - indirectly - through the popularity of their friends. This

* is the notion of 'indirectPopularity'

*

* for each vertex v, determine the average popularity of its friends, rounded down.

* The popularity of each friend of v should NOT include v itself

*

*

* the IndirectPopularity of a vertex with no friends is 0

*

* store the answer in indirectPopularity[v]

*/

private void determineIndirectPopularity(Graph G) {

AND SOLVE FOR

/**

* socialStatus

*

* concept: a person's (relative) social status can be measured by how many people

* are *more* popular. The smaller the number, the higher the social status.

*

* Example: a social status value of 0 indicates no one is more popular

* Example: in a group of 10 friends, the lowest possible socialStatus value is 9;

*

* for each vertex v, determine how many vertices have degree more than v

* "how many people are more popular than v?"

* store the answer in socialStatus[v]

*/

private void determineSocialStatus(Graph G) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!