03 Useful Formulae - Data Structures For Coding Interviews in C#
03 Useful Formulae - Data Structures For Coding Interviews in C#
Useful Formulae
Study some mathematical formulae that would make calculating time complexity easier!
• Formulas
• General tips
Formulas#
Here is a list of handy formulas, which can be helpful when calculating
the time complexity of an algorithm:
(/learn)
Summation Equation
(∑i=1
n
c) = c + c + c + ⋯ + c cn
n(n+1)
(∑i=1
n
i) = 1 + 2 + 3 + ⋯ + n 2
n 2
(∑i=1 i )=1+4+9+⋯+ n(n+1)(2n+1)
n2 6
n
(∑i=0 ri ) = r0 + r1 + r2 + ⋯ (rn+1
−1)
+ rn r−1
n
∑i=0 2i = 20 + 21 + ... + 2n 2n+1 − 1
https://www.educative.io/courses/data-structures-interviews-cs/xVlqk4xQyVJ 1/3
06/11/2021, 12:16 Useful Formulae - Data Structures for Coding Interviews in C#
log an n log a
n
∑i=1 log i = log 1 + log
2 + ... + log n log n!
= log(1.2...n)
General tips#
1. Every time a list or array gets iterated over c × length times, it is
most likely in O(n) time.
2. When you see a problem where the number of elements in the
problem space gets halved each time, that will most likely be in
O(logn) runtime.
3. Whenever you have a singly nested loop, the problem is most likely in
quadratic time.
Back Next
Mark as Completed
Report an Issue
https://www.educative.io/courses/data-structures-interviews-cs/xVlqk4xQyVJ 2/3
06/11/2021, 12:16 Useful Formulae - Data Structures for Coding Interviews in C#
https://www.educative.io/courses/data-structures-interviews-cs/xVlqk4xQyVJ 3/3