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
What is the output, if userVal is 5? int x; x = 100; if (userVal != 0) { int tmpVal; tmpVal = x / userVal; System.out.print(tmpV
spayn [35]

Answer:

The output is 20

Explanation:

This line divides the value of x by userVal

tmpVal = x / userVal;

i.e.

tmpVal = 100/5

tmpVal = 20

This line then prints the value of tmpVal

System.out.print(tmpVal);

i.e 20

Hence, The output is 20

4 0
3 years ago
What does D'Artagnan discover about Milady? d. That she has the mark of a criminal, the fleur- c. That she is secretly working f
Setler79 [48]
The answers is b .....
6 0
3 years ago
Read 2 more answers
Which wireless standard runs on both the 2.4 and 5 GHz frequencies?
viva [34]

Answer:

Approved in 2009, Wi-Fi 4 enables operation in both the 2.4 and 5 GHz frequencies, a game changer at the time. It was the first standard to use MIMO (Multiple In, Multiple Out) and offered better speed, 300 Mbps, better range, more resistance to interference and backward compatibility with Wi-Fi 2 and

Hope this is helpful to you.......

7 0
3 years ago
X³ + y³ + z³ = k
Kazeer [188]

Answer:  x³+y³+z³=42

- Z poważaniem

5 0
3 years ago
Read 2 more answers
What type of image digital image is shown here?
madreJ [45]

Answer:

soccer tournament youth league

6 0
3 years ago
Read 2 more answers
Other questions:
  • You have implemented nap with dhcp enforcement, so you need to ensure you have an updated anti-virus software package, an update
    7·1 answer
  • What is one way in which tablets differ from laptops and notebooks
    12·2 answers
  • If someone receives a shock, or a piece of equipment is throwing sparks or arcing you should try to pull them away from the sour
    7·1 answer
  • Finally, Lee wants to modify the table he linked to his presentation. How should he begin?
    8·1 answer
  • A card ____ is a device that reads data, instructions, and information stored on flash memory cards.
    8·1 answer
  • Which language would you use to create scripts that send data to a web server?
    12·2 answers
  • Pressing the Backspace key deletes the text to the of the insertion point. The left or the right?
    8·2 answers
  • How would I copy this image?
    5·1 answer
  • Please help i will give you brainlest!!!!!!!!!
    6·1 answer
  • Select the correct answer.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!