menu COMPSCI 2120/9642/DIGIHUM 2220 1.0 documentation

Problem Set 7ΒΆ

Problem 7.1

Write a function find_element(element,list) that returns True if element is in list and False otherwise. You may not use the in operator.

  • On average, how many iterations through your loop does your function make?

Problem 7.2

  • Compare your function from 7.1 to binary search with a list of size 10. Which requires fewer iterations on average?

  • Repeat this experiment with a list of size 100,000. Which requires fewer iterations on average? Discuss.

Problem 7.3

Write a function sort_list(intlist) that will return a list of integers intlist with the elements sorted from smallest to biggest.