Time complexity, Space complexity & Big O Notation often seems like a hard topic to many people because of the mathematical equations and stuff but I’m here to explain you in simple terms and you’ll not get confused at all!
First let’s start with understanding programming algorithm. In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(n) and produces the desired output.
Now let’s say we have to develop an algorithm to sort numbers in a list. Now there could be a million types of algorithms which can do that. Some would be faster and much efficient on the other hand some could be slower and take more time to be executed or do the work. Now “faster and much efficient” is often referred to as “best case scenario” and “slower and take more time” is often referred to as “ worst case scenario” and you’ll come up with these terms more often in the programming world when you’re mostly learning Data Structures and Algorithms.
Best case = fastest time to complete, with optimal inputs chosen. For example, the best case for a sorting algorithm would be data that’s already sorted. Worst case = slowest time to complete, with pessimal inputs chosen.
Leave a Comment