#Big-O Notation
- A way computer algorithm scales with large input
Big-O Notation:
- Time Complexity
- Space Complexity
Examples:
def sum_all_nums(n):
sum_of_nums = 0;
for x in range(0,n):
sum_of_nums += x
return sum_of_nums
def sum_all_nums(n):
return (n*(n+1))/2
For the fist answer the (time comlexity), which means the time it takes to run the function is O(n), while the second answer
time complexity is O(1).
The reason for the second answer to be efficient is that O(1) constatnt is considered the most efficient functions among Big-O functions, because it return ONLY one statement(no loops, no ifs)