Skip to main content

Command Palette

Search for a command to run...

Time complexity

Updated
2 min readView as Markdown

Big O (O), Big Omega (Ω), and Big Theta (Θ) Notations

These notations are used to describe the time complexity of an algorithm, which is a way to express how the runtime of an algorithm changes with respect to the size of the input (denoted as n).

  1. Big O Notation (O):

    • Worst-Case Time Complexity: Describes the upper bound of the algorithm's runtime. It represents the longest time an algorithm can take to complete, regardless of the input.

    • Example: If an algorithm takes at most 3n^2 + 2n + 1 operations, the worst-case time complexity is O(n^2).

  2. Big Omega Notation (Ω):

    • Best-Case Time Complexity: Describes the lower bound of the algorithm's runtime. It represents the minimum time an algorithm can take, given the best possible input.

    • Example: If an algorithm takes at least n operations, the best-case time complexity is Ω(n).

  3. Big Theta Notation (Θ):

    • Average-Case Time Complexity: Describes the tight bound on the algorithm's runtime. It represents the average time an algorithm will take, considering all possible inputs.

    • Example: If an algorithm consistently takes n log n operations regardless of the input size, the average-case time complexity is Θ(n log n).

Suppose you're searching for an element in an unsorted list.

  • Worst-Case (Big O):

    • The element you're searching for is at the end of the list or not present at all.

    • The time complexity is O(n) because you might have to look through every element in the list.

  • Best-Case (Big Ω):

    • The element you're searching for is the first element in the list.

    • The time complexity is Ω(1) because you only need one comparison.

  • Average-Case (Big Θ):

    • On average, the element might be somewhere in the middle of the list.

    • The time complexity is Θ(n) because, on average, you'd expect to look through about half of the elements.

Key Points:

  • Worst Case (Big O): How bad can it get?

  • Best Case (Big Ω): How good can it get?

  • Average Case (Big Θ): What's the expected performance?

More from this blog

Amit singh's blog

235 posts