Photo by KOBU Agency on Unsplash
One of the fundamental building concepts of Computer Science is big O notation. Students may learn this concept in their data structures and algorithms course because, in basic terms, big O notation is used to describe the efficiency of a certain algorithm. This type of approach lets us compare different algorithms and lets us decide whether or not we should implement that algorithm given its size and function.
To type out this notation shortly, when we want to show the runtime complexity of a linear search algorithm it is
simply: " O(n) "
This means that the time increases linearly as the number of elements increases. This deduction has been made by
considering the worst possible scenario in a given algorithm. The runtime of let's say a sorting algorithm can be as
little as one(instant), however, this is not guaranteed and therefore is not taken into account when we talk about
big O notation. Here are the different algorithms with their big O notations and their relative positions on a
linear graph.
As the graph shows, we can deduct whether an algorithm is efficient and its feasibility
before implementing it.
When combining different big O values, we must follow these mathematical rules. Firstly, let us imagine two
functions, namely f, and g which have their own runtime complexity.
If we want to combine these two algorithms and
deduct the big O notation of the combined algorithm, we would get: O(f(n) + g(n))
Consequently, when we iterate over a set of elements or arrays, we get the size of the element as n where n is the
number of elements( infinitely large) in the loop. The complexity can be expanded when we put the same size loop
inside a loop where at that point, the big O notation expands exponentially.
To conclude this post, big O notation is an essential tool when it comes to scalability, where the feasibility of certain approaches is decided by programmers. It is certainly a great tool for anyone working with the new emerging technologies in IT, namely Artificial Intelligence and Machine Learning.