Practice Exercises 11 For the week of 2020-05-04

The following exercises provide additional practice problems (not to turn in) for our material this week. Try to solve each problem on paper first before using Thonny to confirm your answers. You are encouraged to work on these practice exercises with classmates throughout the week.

  1. An algorithm has time complexity. If an input of size 100 takes 10 seconds to solve, how long will an input of size 400 take to solve?

  2. We have two algorithms for solving a problem. Algorithm A’s running time is or linear, and algorithm B’s running time is or quadratic. Does this mean that it would always be more efficient (faster) to use algorithm A?

  3. What are the Big-O time and space complexities of the following Python code?

     def mystery(a_list):
         if a_list == []:
             return 0
         else:
             return a_list[0] + mystery(a_list[1:]) 
    
  4. Convert the following decimal numbers to binary, using 16-bit binary. For example, to convert the number 130 to binary, we note 130 = 128 + 2, so the binary encoding would be 0000000010000010. The binary encoding of -130 would be 1111111101111110.

    1. 35
    2. 150
    3. 513
    4. -512