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
"Memory refers to: A.the brain processes involved in the encoding, storage, and retrieval of information. B.the mechanisms drivi
natali 33 [55]

Answer: A

Explain:

you can use memory on a computer to retrieve passed data if your referring to brains memory that is memory of passed events

memory:1 the faculity by which the mind stores and members information

2 something remembered from the past a recollection

8 0
3 years ago
Which one of the following media is unguided media ?​
krok68 [10]

Explanation:

1. radio transmission.

2. microwave transmission

3. infrared transmission.

4 0
3 years ago
What is the typical first shot that everyone takes? In photography
Firlakuza [10]

Answer:

the sky or of nature in general

Explanation:

7 0
3 years ago
8.7 Code Practice: Question 1 edhesive
Ronch [10]

Answer:

here got from a friend

Explanation:

w = ["Algorithm", "Logic", "Filter", "Software", "Network", "Parameters", "Analyze", "Algorithm", "Functionality", "Viruses"]

for i in range (len(w)):

   print(w[i].upper())

5 0
3 years ago
How do i clear my search history ?
nydimaria [60]
If an iphone go to the open book icon then go to history and clear from there if on a laptop go to the top right and look at the three ... press it and go to history and press clear history I don’t remember about android
4 0
3 years ago
Read 2 more answers
Other questions:
  • To create a file in dos edit, type ____ at the command prompt to start dos edit, and then begin typing in the document window.
    8·1 answer
  • How can you add and remove categories from a previously created chart? A. Click the Format tab. B. Click the Chart Styles button
    13·2 answers
  • What is the recommended secure protocol for voice and video applications? secure real-time transport protocol (srtp) hypertext t
    9·1 answer
  • How does kinetic energy affect the stopping distance of a small vehicle compared to a large vehicle?
    14·2 answers
  • What word describes a violation of copyright laws? What rights do copyright holders have over their work of art
    5·2 answers
  • What is DATE data type and its syntax and what is TIMESTAMP data type and its syntax in SQL language.Explain the difference betw
    14·1 answer
  • Translate the following pseudocode for randomly permuting the characters in a string into a C++ program.
    15·1 answer
  • What are some best practices for file management
    8·1 answer
  • Enumerate the the risk in the preparation and cooking in starch and cereal dishes and other food​
    11·1 answer
  • The process of arranging the item of a column in some sequence or order is known as?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!