June 2018
Intermediate to advanced
316 pages
6h 34m
English
Let's look at the next example:
inline fun operation(n: Int, statement: () -> Unit) { for (i in 0..n) { statement() }}
The execution time of the statement is constant. The time complexity of the preceding code is linear, or O(n) if we're using big O notation. We can rewrite the operation function as follows:
inline fun operation(n: Int, statement: () -> Unit) { for (i in 0..n) { for (k in 0..n) { statement() } }}
When we do, we'll get a quadratic time complexity that can be expressed like this—O(n*n).
Read now
Unlock full access