Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

A sequential search of a sorted list can halt when the target is less than a given element in the list. Define a modified version

A sequential search of a sorted list can halt when the target is less than a given element in the list.

Define a modified version of this algorithm, and state the computational complexity, using big-O notation, of its best-, worst-, and averagecase performances.

"""

File: search.py

Defines functions for sequential search and binary search with a profiler.

"""

defsequentialSearch(target, lyst):

"""Returns the position of the target item if found,

or -1 otherwise."""

position = 0

while position <len(lyst):

if target == lyst[position]:

return position

position += 1

return -1

def main():

"""Tests with three lists."""

print(sequentialSearch(3, [0, 1, 2, 3, 4]))

print(sequentialSearch(3, [0, 1, 2]))

# Should stop at second position.

print(sequentialSearch(3, [0, 4, 5, 6]))

if __name__ == "__main__":

main()

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

File searchpy Defines functions for seque... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discrete Mathematics and Its Applications

Authors: Kenneth H. Rosen

7th edition

0073383090, 978-0073383095

More Books

Students explore these related Programming questions