Computer Science, Comprehensive understanding of big O Notations

KD Knowledge Diet
3 min readJun 9, 2023

--

Understanding n-notation is crucial in computer science as it allows us to compare the performance of different algorithms and analyze how they scale with increasing input sizes. In this blog post, we will explore the basics of n-notation, its significance, and the various symbols associated with it.

N-notation, represented as a function of ‘n,’ relates the program’s performance to the input size, which is typically denoted by ‘n.’ Rather than using specific input values, we use a variable to represent the number of operations or data elements involved in the algorithm.

The main purpose of n-notation is to examine how an algorithm’s efficiency changes with varying input sizes. As computer scientists, we cannot predict the exact amount of data our programs will handle. By using ’n’ as a variable, we can compare different algorithms and understand how they perform under different circumstances.

The n-notation chart demonstrates the impact of different functions on algorithm performance. The difference between ’n’ and ‘n²’ is significant, and as the input size increases, the difference becomes even more pronounced. Comparing these values helps us assess how algorithms will react to different input sizes.

However, n-notation alone is not sufficient for analyzing algorithm performance. We often combine it with Greek letters to provide additional context. One commonly used symbol is Big O (O), which represents the worst-case scenario for an algorithm’s performance. By specifying O(n²), for example, we indicate that the algorithm’s performance will be faster or equal to n².

The most significant aspect of Big O notation is that it establishes a worst-case scenario for the program. By considering this scenario during algorithm design, we can avoid unexpected issues or edge cases. We can also compare the worst-case scenarios of different programs to determine their relative efficiency. Since the Big O notation represents the slowest possible runtime, we can conclude that one program will always be slower than another.

For instance, let’s consider two programs, A and B. Program A runs at Ω(n), while program B runs at Ω(n²). The Ω notation only guarantees that program A is slower or equal to n, and program B is slower or equal to n². However, this information alone doesn’t provide a definitive answer regarding which program is better. Program A could potentially run at n³ or even n!, satisfying the Ω(n) requirement. The same could apply to program B. To make a meaningful comparison, we need to use O(n) for program A and O(n²) for program B. With this notation, we can conclude that program A will never be slower than program B.

To illustrate the importance of Big O notation, let’s consider a time scale where smaller values indicate faster algorithms. Comparing different notations for the number 7, we observe the following:

  • ω(7): The algorithm will run slower than 7, but we cannot determine the extent of the slowdown. It could potentially take an incredibly long time to complete even simple tasks.
  • Ω(7): The algorithm will run slower or equal to 7, but there is still a possibility of extremely long runtimes. (At Best)
  • Θ(7): The algorithm will always take exactly 7 units of time. Although desirable, this scenario is rare in practice.
  • O(7): The algorithm will run faster or equal to 7, providing a clear upper limit on its performance. This knowledge allows for effective planning without unexpected surprises. (At Worst)
  • o(7): The algorithm will run faster than 7, but the exact extent of improvement is unknown. While it still permits planning for a worst-case scenario, it is less accurate than O(7) notation and is therefore less commonly used.

In conclusion, n-notation is essential for comparing.

--

--

KD Knowledge Diet
KD Knowledge Diet

Written by KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!

No responses yet