Three formulas for algorithm complexity analysis
May 15, 2021
1 + 2 + 3 + 4 + … +n
I feel the above visualization can help us better understand the sum of an arithmetic sequence.
(a_1 + a_n)*n/2, where a1 is the first element and a_n is the last one.
insertion sort algorithm has the complexity of O(n²) as 1 + 2 +3 +… +n = (n+1)*n/2
Sum of 1 + 1/2 + 1/4 +… + 1/(2^(i-1))
Quick selection algorithm has the complexity of O(n).
Sum of 1 + 1/2 + 1/3 +… + 1/n
See the following Leetcode
Reference
[2]https://math.stackexchange.com/questions/3367037/sum-of-1-1-2-1-3-1-n
[3]https://en.wikipedia.org/wiki/1/2_%2B_1/4_%2B_1/8_%2B_1/16_%2B_%E2%8B%AF