A sequential search of a sorted list can halt when

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()

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top