Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Question: * blanancedFriendships * * say the 'balanceFactor' of a friendship is the difference between the two friends' * popularities. If two friends have

Java Question:

* blanancedFriendships * * say the 'balanceFactor' of a friendship is the difference between the two friends' * popularities. If two friends have the same popularity, then the balanceFactor would * be 0. If one of the friends had N total friends and the other had 1, then the * balanceFactor would be N-1 - it would be a 'lopsided' friendship * * the maxBalanceFactor for a graph is the largest balanceFactor for the graph * (note it would always be >=0) * * B-Level: * determine the maximum balanceFactor for the graph. * store the answer in the maxBalanceFactor instance variable * * A-Level * * determine the number of 'friendships' for which the balanceFactor is largest for the graph * store the answer in the numberOfMostUnbalancedFriendships instance variable * * this level is optional. if you choose NOT to complete it, simply leave the assignment * statement to numberOfMostUnbalancedFriendships as given below. * * Example: if all vertices have the same number of friends, then all popularites would be the same * so all balanceFactors would be 0 - the maxBalanceFactor would be 0 * * A-Level: since all balanceFactors are the same, * all friendships would have the maximum balanceFactor * * Example: if one vertex 'a' was connected to 5 other vertices (b,c,d,e,f) and there were no other * edges, then a's popularity would be 5, all the others would be 1. The balanceFactor for * all friendships would be 4. the maxBalanceFactor would be 4 * * A-Level: numberOfMostUnbalancedFriendships would be 5. * */ private void blanancedFriendships(Graph G) {

maxBalanceFactor = -1; // ToDo 4 fix this numberOfMostUnbalancedFriendships = -1; // toDo 5 optiona A Level fix this

}

More information that might be useful:

public class SocialCircles { private int numberOfTrios; // the results of the computations are stored private int[] indirectPopularity; // in these instance variables. private int maxBalanceFactor; // the values of the variables may be accessed by clients using private int numberOfMostUnbalancedFriendships; // the corresponding 'accessor' functions below. private int [] socialRank;

// accessor functions public int getIndirectPopularity(int v) { // getIndirectPopularity of vertex v return indirectPopularity[v]; } public int getNumberOfTrios() { return numberOfTrios; } public int getMaxBalanceFactor() { return maxBalanceFactor; } public int getNumberOfMostUnBlanancedFriendships() { return numberOfMostUnbalancedFriendships; } public int getSocialRank(int v) { // get getSocialRank of vertex v return socialRank[v]; }

// ---end accessors

/** * degree * * Suggestion. copy the degree function (or see if you can write it from scratch) from the textbook. * you may find it a useful utility function for your functions */ public static int degree(Graph G, int v) { int degree = 0; for (int w : G.adj(v)) degree++; return degree; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions