Big O | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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
Cyrus
1 Answer
0
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