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
olga nikolaevna [1]
4 years ago
15

In this question, we give two implementations for the function: def intersection_list(lst1, lst2) This function is given two lis

ts of integers lst1 and lst2. When called, it will create and return a list containing all the elements that appear in both lists. For example, the call: intersection_list([3, 9, 2, 7, 1], [4, 1, 8, 2])could create and return the list [2, 1]. Note: You may assume that each list does not contain duplicate items. a) Give an implementation for intersection_list with the best worst-case runtime. b) Give an implementation for intersection_list with the best average-case runtime.
Computers and Technology
1 answer:
castortr0y [4]4 years ago
6 0

Answer:

see explaination

Explanation:

a)Worst Case-time complexity=O(n)

def intersection_list(lst1, lst2):

lst3 = [value for value in lst1 if value in lst2]

return lst3

lst1 = []

lst2 = []

n1 = int(input("Enter number of elements for list1 : "))

for i in range(0, n1):

ele = int(input())

lst1.append(ele) # adding the element

n2 = int(input("Enter number of elements for list2 : "))

for i in range(0, n2):

ele = int(input())

lst2.append(ele) # adding the element

print(intersection_list(lst1, lst2))

b)Average case-time complexity=O(min(len(lst1), len(lst2))

def intersection_list(lst1, lst2):

return list(set(lst1) & set(lst2))

lst1 = []

lst2 = []

n1 = int(input("Enter number of elements for list1 : "))

for i in range(0, n1):

ele = int(input())

lst1.append(ele)

n2 = int(input("Enter number of elements for list2 : "))

for i in range(0, n2):

ele = int(input())

lst2.append(ele)

print(intersection_list(lst1, lst2))

You might be interested in
Select the correct answer.
Nataly [62]

Answer:

B. is grayed out

Explanation:

ALL HIDDEN FOLDERS > GRAYED OUT

7 0
3 years ago
True or False? Inserting special characters in a document can be completed using the Ribbon or a keyboard shortcut.
lina2011 [118]
True. hope this helps!
5 0
3 years ago
You are trying to connect a new USB device to your computer. You install the driver and then connect the device to an open USB
nadezda [96]

Answer:

By order of increasing magnitude:

D. Make sure the USB device is plugged in properly.

A. Try a different USB cable.

B. Replace the USB device.

C. Install a new USB controller card.

Explanation:

Start with whatever is simplest first. Most errors are simply ID-10-T mistakes.

3 0
3 years ago
Restricting certain information on the Internet is an example of:
vagabundo [1.1K]
Confedention confinery
4 0
3 years ago
Read 2 more answers
Aisha is opening a flower shop and wants to set up a web site so her customers can find her shop. What type of domain is typical
hjlf

Answer: .com      

Explanation:

.com is the part of Domain name system with which any organization or company name can be attached for working as online website..Com is the top-level domain. Company names are registered with ICANN organization to make it official website over internet and so that users can approach towards it.

  • According top the question, .com is the domain name that mostly used for sites for selling goods and products that related with an organization.
  • Thus, Aisha would be using .com domain name for her flower shop website so that customers can buy her flowers through online mode.
7 0
3 years ago
Other questions:
  • GIMP's official website is _____
    6·1 answer
  • What is a partition gap, and how might it be used to hide data?â?
    8·2 answers
  • A computer that no longer works after having minor repair work done to it may have been damaged by ____
    13·2 answers
  • What is a catalyst? a chemical found in leaves a chemical which promotes a chemical reaction a chemical which reacts with sunlig
    10·1 answer
  • Write a program to insert student grade and print the following
    8·1 answer
  • What is an unknown network called
    6·1 answer
  • What is the purpose of a Macro in Word?: *
    13·1 answer
  • Assume that strikeCounter has already been declared to be a "pointer to int". Assume further that strikeCounter has been initial
    5·1 answer
  • ELO 3.6 Which type of iSCSI name requires a registered domain name to generate a unique iSCSI identifier?
    12·1 answer
  • when you sent email your email can be set to automatically keep a copy where do you find these copies​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!