Sobes.tech
Junior — Middle

Can you list the main categories of algorithm complexity and their criteria?

sobes.tech AI

Answer from AI

The main categories of algorithm complexity describe how the execution time or memory usage grows with increasing input size (n). Here are the main classes:

  • O(1) — constant complexity: time does not depend on data size.
  • O(log n) — logarithmic: time grows proportionally to the logarithm of n (e.g., binary search).
  • O(n) — linear: time is proportional to the input size.
  • O(n log n) — linear-logarithmic: often found in efficient sorting algorithms (e.g., quicksort).
  • O(n²) — quadratic: time grows proportionally to the square of the input size (e.g., bubble sort).
  • O(2^n) — exponential: time doubles with each increase in n (e.g., exhaustive search of all subsets).
  • O(n!) — factorial: very rapidly increasing complexity (e.g., permutation enumeration).

Evaluation criteria:

  • How time/memory changes with increasing input data.
  • Worst, average, and best cases.

Understanding these categories helps in choosing efficient algorithms for tasks.