Big-O notation basics for web developers
Big O Notation...the eye stretcher at first glanceπππππ£π’π
BIG O => Order Of Magnitude...
Confused about Big 0 Notation? Well it looks all intimidating at first but luckily as a entry-level Web Developer, it is important to understand that Big O notation is used to describe and analyze the performance of code so don't get too freaked out my the mathematics of it for now.
Let's dive straight into the definition of Big O notation:
Big O notation is a mathematical function used in computer science to describe the performance or complexity of algorithms.
It can describe things like the execution time required or the space used by the algorithms..
Why is it important for Web Developers to understand Big O notation?
It is a fundamental tool as we now know, to analyze the time and space of algorithms. This becomes very useful to Web Dev's when starting to write software for millions of users because it will allow you to analyze the efficiency of different algorithms. This will help you as a Web Developer to build a well designed and thought out Web application. This could potentially help your application to scale and perform better than competitors.
There are many types of big O complexities used but we'll discuss some of the more common types of Big O complexities that are used, let's take a closer look at these:
1) O(1) - Used to measure constant time complexity
* Regardless of the input size, the algorithm will always maintain a constant runtime.
A code example of this would be as follows:
The input size will not effect the time to run the algorithm and it remains constant throughout.
2) O(log n)- Logarithmic time complexity

* This will will happen when an algorithm's performance grows in line with the size of the input data.
Code example:
Constant time operations will run in a basic for loop function.
Difference between Linear & The Logarithmic search:
Linear search algorithm- Each element of an array is searched one by one in logical order to see if it is the desired element. Depending on where the desired element is in the array will detemine the time complexity of the algorithm. It is easy to use and it has no need for ordered elements, it also requires less lines of code.
compared to Logarithmic or Binary search algorithm- The binary search algorithm is faster in finded the desired comparison within the array due to it's order system. A very complex algorithm where elements have to be in a specific order and require more lines of code.
The binary search algorithm will be the most efficient algorithm between the two as it takes less time to search through the sorted list of elements because it's prerequisite is that all elements need to be sorted in order whereas the linear algorithm has no such requirement.
4) O(n2) Quadratic time complexity
This complexity is exactly as the name states, it takes a tremendous amount of time to run the algorithm based on the data input set.The good example of Quadratic time complexity functions would be that of nested loops. The size of the input data set will dramatically affect the run time of the algorithm as shown in the diagram above. The inner loop runs "n" times and isn't dependant on the value of n hence the algorithm's time complexity. The time complexity will take place when we nest over multiple iterations within the data set.
// Fibonacci sequence output : 11123...
Comments
Post a Comment