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++; }

31st Mar 2020, 6:41 AM
1 Answer
Pretty much everything in that method is O(1) besides probably expandCapacity(). Therefore the whole method will obtain the O( ) of whatever the O( ) of expandCapacity() is. That *should* be O(n) but depends on implementation after all.
16th Aug 2022, 8:59 PM
Fynn Nix
Fynn Nix - avatar