forked from shohan-pherones/dsa-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
002-time-and-space-complexity.js
14 lines (9 loc) · 1.77 KB
/
002-time-and-space-complexity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// What is time complexity?
// Time complexity is a way to analyze the performance of an algorithm by describing the amount of time it takes to run as a function of the size of the input. It is commonly expressed using big O notation, which describes the upper bound on the number of operations the algorithm will perform. For example, an algorithm with a time complexity of O(n) will take proportionally longer to run as the size of the input (n) increases.
// What is space complexity?
// Space complexity is a way to analyze the storage requirements of an algorithm by describing the amount of memory it uses as a function of the size of the input. Like time complexity, it is commonly expressed using big O notation. An algorithm with a space complexity of O(1) uses a constant amount of memory regardless of the size of the input, while an algorithm with a space complexity of O(n) uses proportionally more memory as the input size (n) increases.
// What is asymptotic notation?
// Asymptotic notation is a way to describe the performance of an algorithm as the input size grows towards infinity. The three most commonly used asymptotic notations are:
// 01. Big O notation: describes the upper bound on the number of operations the algorithm will perform. For example, an algorithm with a time complexity of O(n) will take at most a certain multiple of n operations.
// 02. Big Ω notation: describes the lower bound on the number of operations the algorithm will perform. For example, an algorithm with a time complexity of Ω(n) will take at least a certain multiple of n operations.
// 03. Big Θ notation: describes the tight bound on the number of operations the algorithm will perform. For example, an algorithm with a time complexity of Θ(n) will take exactly a certain multiple of n operations.