The efficiency of algorithms is important in Competitive Programming. The large challenge of competitive programming / interviewing isn’t necessarily coming up with a solution, but rather coming up with an efficient solution. The time complexity of an algorithm estimates how much time the algorithm uses for some input. Typically we are concerned with the worst case computation time with respect to the input as it tends towards infinity so that it becomes the dominating term. We use “Big O Notation” to do so ().

Recursion

The time complexity of a recursive function depends on the number of times the function is called and the time complexity of that call, the total time complexity a product of these values.

Complexity Classes

  • : Constant time
  • : Halves the input size on each step
  • : ???
  • : Linear time
  • : This type of algorithm usually sorts the input and then implements a solution
  • : Usually indicates two nested loops
  • : Usually indicates three nested loop
  • : Usually indicates the algorithm iterating through all subsets of the input elements
  • : Usually indicates the algorithm iterating through all permutations of the input elements

Notes

  • Loops make things slow

Polynomial

An algorithm is polynomial if its time complexity is at most where k is a constant. In practice, k is usually small so a polynomial time complexity roughly means an efficient algorithm. There are many problems that do not have polynomial solutions (NP Hard problems)

You can try to estimate efficiency based on input size…

Input SizeRequired Time Complexity
or
is large or