O(1) – constant time
Algorithms written in constant time have an upper bound that does not depend on the input size of the algorithm. Constant time is an upper bound by a constant value, and thus won't take longer than the upper bound of the dataset. This type of algorithm is usually okay to add to a function in practice – it doesn't add a lot of processing time to your function. Make sure to note the constant that occurs here. A single array lookup adds a negligible amount of time to a function. Looking up thousands of individual values in an array may add some overhead. Performance is always relative, and it is important to maintain cognizant of the additional load you're adding to your functions, even if they only perform a trivial amount ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access