Question: A distributed caching service wants to build an algorithm to measure the efficiency of its network. The network is represented as a number of nodes

A distributed caching service wants to build an algorithm to measure the efficiency of its network. The network is represented as a number of nodes and a list of connected pairs. The efficiency of this network can be estimated by first summing the cost of each isolated set of nodes where each individual node has a cost of 1.

To account for the increase in efficiency as mode nodes are connected, update the cost of each isolated set to be the ceiling of the square root of the original cost and return the final sum of all costs.

Example

graph_nodes=10

graph_form=[1,1,2,3,7]

graph_to=[2,3,4,5,8]

There are two isolated sets with more than one node, {1,2,3,4,5} and {7,8}. The ceilings of their square roots are 5 ^ 1/2 = 2.236 and ceil(2.236) = 3, 2 ^ 1/2 = 1.414 and ceil (1.414) = 2. The other three isolated nodes

are separate and the square root of their weights is 1 ^ 1/2 = 1 respectively. The sum is 3 + 2 + (3 * 1) = 8.

Input has 3 parameters:

int graph nodes: the number of nodes

int graph from graph edges]: an array of integers that represent one end of an edge

int graph tolgraph edges]: an array of integers that represent the other end of an edge

Returns:int an integer that denotes the sum of the values calculated .

Please answer it quickly.It is urgent

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!