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?
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?
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:])