Big O notation is a specific notation that indicates the speed of an algorithm. When you use others’ algorithms in your project it is necessary to calculate Big O notation. It will help you to know how fast or slow it will work in your case. To know more about Big O notation visit HERE
Algorithm run-time at different rates
Alex is working on a SpaceX search algorithm. When a rocket is poised to arrive on the Moon, his algorithm will kick in and assist in determining where to land. The Algorithm he has to use must be fast and correct and he has two choices between simple search and binary search algorithm.
Binary search is more efficient. but on other hand, Simple Search is simple to write and lowers the risk of flaws.
Note: Alex just has 10 seconds to figure out and Alex also wants no programming flaws.
Alex chooses to time both methods with a list of 100 elements to be extra cautious.
Time each Search takes
If 1 element check takes 1 millisecond. In a simple search, 100 elements check will take 100ms. In binary search log of 100 elements with a base, 2 will take 7ms to check.
|Number of Elements||Time to Check Elements|
|log(base2)100 = 7||7ms|
|log(base2)billion = 32||32ms|
But Let’s say if Alex has to check a billion elements then it takes 11 days for a simple search technique and just 32ms for the binary search technique. Alex will choose Binary Search in this case because he just has 10 seconds to figure it out.
The binary search takes a bit longer to perform as the number of objects grows but on other hand the Simple search takes a far longer time than Binary Search.
As the number list grows larger, binary search becomes significantly quicker than the basic search.
That’s why knowing how long an algorithm takes to execute isn’t enough. You also need to know how fast it runs. As the list size grows, the running time increases. That’s where Big O notation in Algorithm comes in handy.
Algorithms related posts visit HERE
Data Structures related posts visit HERE
Databases related posts Visit HERE
Python-related posts Visit HERE
C++ related posts Visit HERE
Data Science related posts visit HERE