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]
3 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]3 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 are the features of G-mail <br><br>(Write in your own words)​
wlad13 [49]

Answer:

here is what I think!

Explanation:

G-mail is:

  1. secure
  2. easy to use
  3. fast
  4. can be used to sign in anywhere!<u>(including brainly)</u>
  5. you don't need to pay when creating one
  6. can help you in billing and buying apps and their paid product
  7. <em><u>you </u></em> can use it because <em>why no!</em>
  8. some websites need G-mail to be used

thats why you should use G-mail

tell me if you have an idea!

3 0
3 years ago
Read 2 more answers
JOIN GO.OGLE CLASSROOM IF YOUR A FAN OF FRANK OCEAN
Mrrafil [7]
Yes i agree perfectly
3 0
3 years ago
Read 2 more answers
What should you do when an error message pops up on the screen?
Shtirlitz [24]
The best thing to do when an error message appears when it is not supposed to, as in if you are blocked by an administrator and it appears then its supposed to, it is best to contact someone who can investigate whether or not something is happening to your computer. That could be a parent, if they are good with computers, or just tech support at a store, provided they also know computers. Most of the time your computer just makes a mistake so nothing to worry about, but make sure to have it checked just to be sure. 
7 0
3 years ago
Which of the following is powered by energy from earth's interior ?
butalik [34]
I think the correct answer from the choices listed above is option D. It would be plate tectonics that is powered by energy from Earth's interior since it is the only choice that is underneath the surface of the Earth. Hope this answers the question. Have a nice day.
3 0
3 years ago
Please create a brute force password cracker using python
serg [7]

Answer:

0

2

I need to make small programs for school to brute force crack different types of passwords; I'm looking to create a brute force python code that will run through every possible combination of alphabetical and alphanumerical passwords and give me the password and the amount of time it took to crack.

I did the same with purely numerical passwords and got this:

import datetime as dt

Password4 = 123456

def crack_password():

   start = dt.datetime.now()

   for n in range(1000000):

       password_guess = '{0:04d}'.format(n)

            if password_guess == str(Password4):

               end = dt.datetime.now()

               print("Password found: {} in {}".format(password_guess, end - start))

              break

   guesses = crack_password()

I then tried to do something somewhat similar for alphabet/alphanumerical passwords but did not work whatever I tried:

   import random

   letters = [str(i) for i in range('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p')]

   s = [''.join([a,b,c,d,e,f,g,h]) for a in letters for b in letters for c   in letters for d in letters for e in letters for f in letters for g in letters  for h in letters]

   random.shuffle(s)

   real_password = 'aaaaaaaa'

   i = 0

Explanation:

8 0
3 years ago
Other questions:
  • How to know if somebody else is listening my conversations by cellphone?
    13·1 answer
  • How to search for the largest files on my computer vista?
    5·1 answer
  • To remove an embedded chart, you should _____ it and press the DELETE key. (Points : 2) move drag hide click
    15·1 answer
  • Using Python I need to Prompt the user to enter in a numerical score for a Math Class. The numerical score should be between 0 a
    7·1 answer
  • Code works, need help writing header file.
    8·1 answer
  • Can someone help me calculate this Multimedia math:
    11·1 answer
  • What is intellectual property rights law ?​
    8·1 answer
  • Which button in the Sort &amp; Filter gallery of the Data tab would alphabetize from A to Z quickly?
    6·2 answers
  • Jose would like to have text with predefined styles that can flow around an image in a variety of shapes and sizes
    10·2 answers
  • Which of the following shows data conversion taking place?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!