Create a function: That takes a list and an integer v, -And returns True if the value v is in the list (and False otherwise). The function must be efficient and stop looking as soon as possible. -The main program should generate a very large list with random elements, call the function to look for a value, and display the result. -Add in the function a NPas variable to count the number of steps taken by the algorithm (the number of times the loop is executed) and display a message with this information. EXEMPLE >>> 13 = [7, 23, 86, 71, 17, 5, 63, 91, 69, 92, 76, 49, 22, 45, 39, 52, 84, 51, 72, 28, 81, 52, 7, 50, 96, 64, 18, 71, 44, 46, 96, 89, 31, 9, 31, 83, 80, 20, 17, 12, 97, 51, 90, 53, 25, 24, 6, 86, 41, 2, 69, 26, 63, 9, 32, 91, 13, 33, 32, 96, 63, 10, 63, 63, 79, 96, 82, 9, 70, 16, 84, 100, 55, 86, 22, 8, 2, 90, 91, 99, 15, 38, 30, 7, 44, 8, 1, 8, 81, 86, 44, 44, 64, 2, 78, 96, 28, 80, 42, 44] >>> search (13, 78) Number of steps 95 %3D True
Create a function: That takes a list and an integer v, -And returns True if the value v is in the list (and False otherwise). The function must be efficient and stop looking as soon as possible. -The main program should generate a very large list with random elements, call the function to look for a value, and display the result. -Add in the function a NPas variable to count the number of steps taken by the algorithm (the number of times the loop is executed) and display a message with this information. EXEMPLE >>> 13 = [7, 23, 86, 71, 17, 5, 63, 91, 69, 92, 76, 49, 22, 45, 39, 52, 84, 51, 72, 28, 81, 52, 7, 50, 96, 64, 18, 71, 44, 46, 96, 89, 31, 9, 31, 83, 80, 20, 17, 12, 97, 51, 90, 53, 25, 24, 6, 86, 41, 2, 69, 26, 63, 9, 32, 91, 13, 33, 32, 96, 63, 10, 63, 63, 79, 96, 82, 9, 70, 16, 84, 100, 55, 86, 22, 8, 2, 90, 91, 99, 15, 38, 30, 7, 44, 8, 1, 8, 81, 86, 44, 44, 64, 2, 78, 96, 28, 80, 42, 44] >>> search (13, 78) Number of steps 95 %3D True
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Please write your own code and put some commentary. Thank you
![Create a function:
That takes a list and an integer v,
-And returns True if the value v is in the list (and False
otherwise). The function must be efficient and stop looking as
soon as possible.
-The main program should generate a very large list with
random elements, call the function to look for a value, and
display the result.
-Add in the function a NPas variable to count the number of
steps taken by the algorithm (the number of times the loop is
executed) and display a message with this information.
EXEMPLE
>>> 13 = [7, 23, 86, 71, 17, 5, 63, 91, 69, 92, 76, 49, 22, 45, 39,
52, 84, 51, 72, 28, 81, 52, 7, 50, 96, 64, 18, 71, 44, 46, 96, 89,
31, 9, 31, 83, 80, 20, 17, 12, 97, 51, 90, 53, 25, 24, 6, 86, 41, 2,
69, 26, 63, 9, 32, 91, 13, 33, 32, 96, 63, 10, 63, 63, 79, 96, 82, 9,
70, 16, 84, 100, 55, 86, 22, 8, 2, 90, 91, 99, 15, 38, 30, 7, 44, 8,
1, 8, 81, 86, 44, 44, 64, 2, 78, 96, 28, 80, 42, 44]
>>> search (13, 78)
Number of steps 95
%3D
True](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F32c13ba7-237d-4629-8f55-05e99d86aab8%2F24ced42f-2566-4971-a259-89551ee54fb1%2Fgmupgsk_processed.png&w=3840&q=75)
Transcribed Image Text:Create a function:
That takes a list and an integer v,
-And returns True if the value v is in the list (and False
otherwise). The function must be efficient and stop looking as
soon as possible.
-The main program should generate a very large list with
random elements, call the function to look for a value, and
display the result.
-Add in the function a NPas variable to count the number of
steps taken by the algorithm (the number of times the loop is
executed) and display a message with this information.
EXEMPLE
>>> 13 = [7, 23, 86, 71, 17, 5, 63, 91, 69, 92, 76, 49, 22, 45, 39,
52, 84, 51, 72, 28, 81, 52, 7, 50, 96, 64, 18, 71, 44, 46, 96, 89,
31, 9, 31, 83, 80, 20, 17, 12, 97, 51, 90, 53, 25, 24, 6, 86, 41, 2,
69, 26, 63, 9, 32, 91, 13, 33, 32, 96, 63, 10, 63, 63, 79, 96, 82, 9,
70, 16, 84, 100, 55, 86, 22, 8, 2, 90, 91, 99, 15, 38, 30, 7, 44, 8,
1, 8, 81, 86, 44, 44, 64, 2, 78, 96, 28, 80, 42, 44]
>>> search (13, 78)
Number of steps 95
%3D
True
![import random
N = 100 # try with N = 1000 or N = 100000
# list in ascending order from 1 to N I1 = [v for v in range (1, N +
1)] print (1)
# list in descending order from N to 1 12 = [v for v in range (N, 0,
-1)] print (12)
# list with random elements 13 = []
for i in range (N):
V = random.randrange (1, N + 1)
13.append (v) print (13)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F32c13ba7-237d-4629-8f55-05e99d86aab8%2F24ced42f-2566-4971-a259-89551ee54fb1%2Fcd5chos_processed.png&w=3840&q=75)
Transcribed Image Text:import random
N = 100 # try with N = 1000 or N = 100000
# list in ascending order from 1 to N I1 = [v for v in range (1, N +
1)] print (1)
# list in descending order from N to 1 12 = [v for v in range (N, 0,
-1)] print (12)
# list with random elements 13 = []
for i in range (N):
V = random.randrange (1, N + 1)
13.append (v) print (13)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 3 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY