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]
3 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]3 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
Is an applications program is a program designed to perform a specific task for specific users
Vika [28.1K]

Answer:

application software or tailored software

6 0
3 years ago
Assuming that the actual process ids of the parent and child process are 2600 and 2650 respectively, what will be printed out at
VashaNatasha [74]

Answer:

Output explanation to the given code can be defined as follows:

Explanation:

In A the output is 0 , It will return fork value of the child process that is 0. so, 0 is printed during child process.  

In B the output is 2650 , in which the getpid() method returns the child process id  value that is 2650.  

In C the output is 140, As it is declared in key, all process have their own "value" copies. 20 are inserted during childhood, so 140 are written.  

In D the output is 2650, its fork() method returns the child ID to the parent process. so the value 2650 is printed.  

In E the output is 2600, Its getpid() method will returns parent process id  that is equal to 2600.  

In F the output is 120 Since the value is declared in primary, all process so their own "value" copies. 120 will be printed during process.

4 0
3 years ago
What is one advantage of using object-oriented programming?
maxonik [38]
That answer would be B hope it helps
6 0
3 years ago
Read 2 more answers
You have heard that the Linux distribution your are going to install to run a new application runs best on a RISC architecture.
Artyom0805 [142]

Answer:

SPARC .

Explanation:

When the user has understood they're required to install the linux distribution to set up a specific program works better on such a RISC architecture. SPARC must therefore find the device from which it would work that following distribution for the Linux. It is a RISC and ISA that was previously designed through both Fujitsu and Sun.

6 0
3 years ago
Juan Garcia is the network administrator for a small company that also maintains its own web server. He has taken the following
Lesechka [4]

Answer:

Yes Juan has done enough to secure the network

Explanation:

All the computers are patched, have antivirus software, and have unneeded services shut down - this is done to prevent malware from residing in the system.

The network has a firewall with proxy server and IDS - the firewall limit access to network so as to limit intrusion into the network

The organization has a policy requiring passwords of ten characters in length, and must be changed every 90 days - this is done to prevent leakage of sensitive information in the network especially when there is a compromise in the network.

4 0
3 years ago
Other questions:
  • What can a folder on a computer contain?
    13·2 answers
  • ________ is a set of rules for exchanging files such as text, graphic images, sound, video, and other multimedia files on the we
    14·1 answer
  • You're the network administrator for a company that has just expanded from one floor to two floors of a large building, and the
    7·1 answer
  • A client contacted you to request your help in researching and supplying the hardware necessary to implement a SOHO solution at
    5·1 answer
  • Which increases the rate of soil formation?
    10·1 answer
  • Use HTML to create a web page
    10·1 answer
  • When designing your navigation, your primary objective should be to include keywords for search engines.
    6·1 answer
  • What does XD mean? I keep seeing people say it and I dont know what it means
    6·2 answers
  • Handhed computer is otherwise called as<br> 1.laptop<br> 2.Notebook<br> 3.Palmtop
    7·1 answer
  • How do we store value in a variable? Give an example
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!