Data Structure & Algorithms
Time Complexity¶
Time Complexity measures the amount of time an algorithms takes to complete a function. We can simply think it as how many times the code snippet will be executed.
Common Complexity represented by Big O natation:
O(1): Constant Complexity
O(log n): Logarithmic Complexity
O(n): Linear Complexity
O(n^2): N square Complexity
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.println("Hey, I am looking at " + i + " and " + j);
}
}
O(n^3): N cubic Complexity
for example, iterate over a three-dimensional array.
O(2^n): Exponential Growth
O(n!): Factorial
Space Complexity¶
Space Complexity measures the amount of memory an algorithms uses.
O(n): the length of one dimensional array.
-
覃超的算法训练营 - 极客时间 覃超 ↩