Practice Problems 11 Complete before class on 2022-12-09

  1. An algorithm has \(O(\sqrt{n})\) 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 \(O(n)\) or linear, and algorithm B’s running time is \(O(n^2)\) 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:])