Big O | SoloLearn: Learn to code for FREE!


Big O

I still have so much confusion when it comes to Big O notation. I know its very simple but still struggle with picking them out. But, my question is. What's the Big O notation for this formula? I feel that its O(n) but I'm unsure. public void enqueue(T element) { if(size() == queue.length) expandCapacity(); queue[rear] = element; rear = (rear+1) % queue.length; numElements++; }

3/31/2020 6:41:07 AM


2 Answers

New Answer


Everything would be constant time, except for that expandCapacity function. So the big O Depends on its implementation to determine its complexity.


I may be wrong about this, but since you're not traversing the queue, it should be constant time, O(1).