DEV Community

Cover image for Understanding Time complexity - Big O Notation

Understanding Time complexity - Big O Notation

Love Huria on October 26, 2019

Lately, I have gotten an interest in algorithms, the first one I chose to understand deeply is how sorting algorithms work and their time complexit...
Collapse
 
peledzohar profile image
Zohar Peled

One iteration is not O(1), it's O(n)...

Collapse
 
lhuria94 profile image
Love Huria

I see what you're trying to say here, what I meant was O(1) is that constant time.

O(n), where n completely depends on the number of items. I see where this is confusing. Thanks for highlighting.

Collapse
 
peledzohar profile image
Zohar Peled

Well, since you have to iterate through the array, the time complexity is dependent on the number of items, therefor it's O(n) and not O(1). Getting values from a hash map is approaching O(1), perhaps that's the source of your confusion.

Collapse
 
mgemard profile image
Mathieu Gemard

Another useful resource if you want to go deeper:

geeksforgeeks.org/analysis-of-algo...