1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sattari [20]
2 years ago
12

Your team at amazon is overseeing the design of a new high-efficiency data center at HQ2. A power grid need to be generated for

supplying power to N servers. All servers in the grid have to be connected such that they have access to power. The cost of connections between different servers varies. Assume that there are no ties, names of servers are unique, connections are directionless, there is at most one connection between a pair of servers, all costs are greater than zero, and a server does not connect to itself. Write an algorithm to minimize the cost of connecting all servers in the power grid. Input two arguments - num, an Integer representing number of connections. connectons, representing a list of connections where each element of the list consists of two servers and the cost of connection between the servers.
Computers and Technology
1 answer:
Alla [95]2 years ago
7 0

Following are the python program to the given question:

from collections import defaultdict #import package

import heapq as h#import package

def primsMST(gr, st_v): # defining a method primsMST that takes two values in parameters  

   primalMST = defaultdict(set)#defining primalMST as a variable that calls defaultdict method  

   v = set([st_v])# defining a variable v that calls the set method and hold its value

   e_list = [(c, st_v, to)for to, c in gr[st_v].items()]#defining variable e_list that use loop to hold value in list

   h.heapify(e_list)# use package that holds heapify and holds its value

   while e_list:#defining while loop that checks e_list  

       c, s, e = h.heappop(e_list)#holding heapop method value in c,s,and e variable

       if e not in v:#defining if block checks e value is not in v

           v.add(e)# use add method to add value in v

           primalMST[s].add(e)#use primalMST as list that adds value in mwthod

   for nxt, c in gr[e].items():#defining for loop that uses nxt, and c variable that checks value in list

       if nxt not in v:#defining nxt variable that checks value is not in v

           h.heappush(e_list, (c, e, nxt))#add value into the heappush method

   return primalMST#return method value

connects=[['A','B',1],['B','C',4],['B','D',6],['D','E',5],['C','E',1]]#defining a list connects

my_gr=dict()#defining a variable my_gr that holds method dict() value  

for el in connects:#defining a for loop that uses el to count connects list value

   my_gr[el[0]]=dict()#use my_gr as list hold value in dict method

   my_gr[el[1]]=dict()#use my_gr as list hold value in dict method

for el in connects:#defining another for loop that uses el to count connects list

   my_gr[el[0]].update({el[1]:el[2]}) # use update method that update value in my_gr

   my_gr[el[1]].update({el[0]:el[2]})# use update method that update value in my_gr

x=dict(primsMST(my_gr, list(my_gr.keys())[0]))#defining x variable that calls dict method and  hold its value  

a=[]#defining an empty list

for k in x:#defining a for loop that uses k to hold dict method value

   for no in x[k]:#defining a loop that checks list value

       a.append([k,no,my_gr[k][no]])#use a that add value in list  

       print(a)#print list value.

Output:

Please find the attached file.

Program Explanation:

  • Import package.
  • defining a method primsMST that takes "gr and st_v" as parameters.
  • Inside the method, a primalMST as a variable is declared that calls "defaultdict" method.
  • Use the v variable that calls the set method and hold its value.
  • Defining "e_list" that uses the loop to hold value in lists, and define the heapify and holds its value.
  • In the next step, it defines a while loop checks e_list, and defines variable and hold value into the method and use another if to check value and return its value.
  • A list "connects" is declared that holds a value and defines a "my_gr" that holds "dict" method value and uses multiple for loop to print the calculated list value.

Learn more:

dictionary: brainly.in/question/14673591

List: brainly.in/question/25140412

You might be interested in
A friend is having a problem with keeping a fish tank at the right temperature so the fish stay healthy. Describe how you could
omeli [17]

Answer:

water temperature gauge sensor

Explanation:

  • We can connect a temperature sensor connected to the water and a heater or cooler sensor, we have created a program to check the temperature from the sensor.
  • when the water is hotter than recommended, we turn on the refrigerator and when it is cold, we turn on the heater
  • so correct answer is water temperature gauge sensor

4 0
2 years ago
Josephine is in the process of creating ads within her Standard Display campaign. She finds that there are two main ad formats t
Dennis_Churaev [7]

Answer:

d.Responsive Display ads

e.Uploaded ads (Image & AMPHTML)

Explanation:

The two main ad formats used in a Standard Display campaign are;

1. Responsive Display ads: they are Google's new default ad format and are automatically created by Google using assets provided by users in a square and landscape format.

2. Uploaded ads (Image & AMPHTML): they are created using a tool like Google Web Designer to create adverts outside of Google Ads.

They can be uploaded as a jpeg, gif, zip file and png extension into Google Ads.

3 0
2 years ago
Your program is going to compare the distinct salaries of two individuals for the last 5 years. If the salary for the two indivi
kirza4 [7]

In python:

i = 1

lst1 = ([])

lst2 = ([])

while i <= 5:

   person1 = int(input("Enter the salary individual 1 got in year {}".format(i)))

   person2 = int(input("Enter the salary individual 1 got in year {}".format(i)))

   lst1.append(person1)

   lst2.append(person2)

   i += 1

if sum(lst1) > sum(lst2):

   print("Individual 1 has the highest salary")

else:

   print("Individual 2 has the highest salary")

This works correctly if the two individuals do not end up with the same salary overall.

4 0
2 years ago
1.) what is the minimum number of bits required to represent -3,997 using 2's complement form?
lisabon 2012 [21]

The binary representation of +3997 is 1111 1001 1101.

In one's complement this is simply adding a sign bit and inverting all the bits:

1 0000 0110 0010

The two's complement is the one's complement plus 1:

1 0000 0110 0011

That's 13 bits. Normally the sign bit would be at an 8, 16 or 32,... bit boundary.

For -436 it's 10 0100 1100 and 10 bits


8 0
3 years ago
Darpa was created to
I am Lyosha [343]
Darpa is an agency that emerges technologies for the military. I would say B. investigate technologies. This is logical because they are working with technologies investigating how, where, and why they need to emerge in the first place.
7 0
3 years ago
Other questions:
  • Briefly describe "SoftwareEngineering Framework". Do provide examples and diagrams wherenecessary.
    15·1 answer
  • Design and implement a class Country that stores the name of the country, its population, its area, and the population density (
    6·1 answer
  • Which of the following is true? A)Checks and Debit Cards both withdraw money directly from a bank account. B)Checks are the most
    13·2 answers
  • Based on the passage​ and/or drawing on your prior​ knowledge, you realize that an HMO is​ what?
    9·1 answer
  • 14<br> Select the correct answer.<br> Which activity is a marketing technique?
    9·1 answer
  • Laura wants to know more about the organization to which she has applied. What can she do to know more about the organization’s
    12·1 answer
  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Promp
    10·1 answer
  • To configure a router/modem, what type of IP interface configuration should you apply to the computer you are using to access th
    10·1 answer
  • Gus has decided to organize his inbox on June 26 by using folders and deleting irrelevant messages. He creates a folder called "
    12·2 answers
  • Josh is learning about hackers known for causing damage and altering functions of websites. Which type of hacker is he learning
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!