Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
O(1) can be worse than O(N) sometimes...
stackodev920212dI suck at math, or remembering these concepts I once learned and never used again. Can I get an explainer?
Thizizmyname10811dTime complexity and how it scales.
O(1) - constant time, meaning regardless of the size, the operation should take the same amount of time. ie reading an element from an array given an offset.
O(log n) - a binary tree with n elements should always have a depth of log n, therefore a lookup takes at most log n.
O(n) - might require iterating through every element, like uppercaseing a string.
O(N!) - for each element you need to operate through every remaining element.
Examples of this are brute force travelling salesman, or sorting a list by checking every permutation of it if the next permutation is more sorted than the previous.
So, for a very small dataset, I still have a chance?