Skip to main content

šŸ§ Big O - Asymptotic Complexity (O(x))

All code has a complexity, like:ā€‹

  • O(log n) - Logaritmics ā†’ Performatic, option to loop performatively. Example: binary search.

  • O(1) - Constant -> Complexity doesn't change independent of the input param. Example: IF

  • O(n) - Linear ā†’ More values, less performance. Example: FOR.

  • O(nĀ²) - Exponencial ā†’ Repetition inside repetition. Will repeat each element again. Example: FOR inside FOR.

  • O(nĀ³)

  • O(2^n)

  • O(3^n)

  • O(n!) - Fatorial -> The worst. Example: Recursive function.


Big O NotationTypeComputations for 10 elementsComputations for 100 elementsComputations for 1000 elements
O(1)Constant111
O(log N)Logarithmic369
O(N)Linear101001000
O(N log N)n log(n)306009000
O(N^2)Quadratic100100001000000
O(2^N)Exponential10241.26e+291.07e+301
O(N!)Factorial36288009.3e+1574.02e+2567

Complexity Chart


Data Structure Operations Complexity

Data StructureAccessSearchInsertionDeletionComments
Array1nnn
Stacknn11
Queuenn11
Linked Listnn1n
Binary Search TreennnnIn case of balanced tree costs would be O(log(n))
AVL Treelog(n)log(n)log(n)log(n)