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
Assume values 10, 20, 30, and 40 are entered in the cell range A1:A4. Cell A10 contains the formula: =A1+A2+A3+A4 and displays v
r-ruslan [8.4K]

Answer:

The formula and value to this question is "=A1+A3+A4+A5 with value 100"

Explanation:

The explanation of the given question as follows:

  • In question, it is defined that four cells that are "A1, A2, A3, and A4"  contains value that are "10, 20, 30, and 40".
  • To add these values we use addition formula that is "=A1+A2+A3+A4". it will give value 100.
  • If the user inserts a new row that is "A2" and assigns a value in the cell that is "50" so, we use the above formula that adds values with these values we also use the value "100".
8 0
2 years ago
I'll give brainlist to right answers
xeze [42]
I think it’s number 1. Check the answer first.
5 0
2 years ago
Will a debit card still work if i put stickers on it?
laiz [17]

Answer:

Explanation:

Yes, it may still be readable, but if they refuse to take it you have no ground to stand on. (If you obscure the signature, at least make sure the CVV is readable or reprinted on top.) The plastic covering should not interfere with the mag stripe.

8 0
3 years ago
Read 2 more answers
Jabez needs to alert through an SMS text message those corporate users who have a specific brand and type of mobile device regar
Maslowich

Answer:

Push notification services.

Explanation:

Push notification services can be used to deliver important messages on mobile devices in an efficient and timely manner. The different mobile platforms such as android, iOS have their services which makes it easy for Jabez to send the messages to users with a specific brand and type of mobile device. The messages will pop up on the mobile device of the user, whether the app or the website associated with notifications is running or not.

7 0
3 years ago
1 Which skill-based video game requires quick reflexes and skills with weapons?
kirill [66]

The Answer to Number 1 is Shooter Games

The Answer to Number 2 is Dice Throwing

The Answer to Number 3 is Games are organized play

The Answer to Number 4 is Either Simulation or Adventure

The Answer to Number 5 is Stories have no rules to follow, you can learn from countless other lifetime through stories

The Answer to Number 6 is Setting

The Answer to Number 7 is False

The Answer to Number 8 is Objective

7 0
2 years ago
Other questions:
  • Write a program, NumberStatistics.java, that reads an unspecified number of integers. The program ends with the input 0. The pro
    14·1 answer
  • How can i do a back up on one computer and save it to the hard drive in another computer without it being seen by others on the
    9·1 answer
  • Which command will display the current contents of non-volatile random-access memory (nvram)?
    14·1 answer
  • Suppose that a computer can read or write a memory word in 5 nsec. Also suppose that when an interrupt occurs, all 32 CPU regist
    10·2 answers
  • Which page feature is used in long documents to assist readers in quickly finding information in the document without having to
    11·2 answers
  • your friend's parent's are worried about going over their budget for the month. Which expense would you suggest is NOT a need?
    11·1 answer
  • What are like arms surrounding all the other code blocks?
    11·2 answers
  • The address for the website you want to visit is called the browser internet URL World Wide Web
    5·2 answers
  • What is the decimal value for the jump control?
    12·1 answer
  • How many dlcs in total were in each black ops game (including dlc weapons) answer for 25 whole points
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!