Jump to content

Matt8541

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by Matt8541

  1. Hello, First post here. Question is in regards to Big-O. I'm wondering if a method calls another method which is O(n), does this method become O(n) as well. If not, why not? It seems that it should be. Here's an example (and my professor marked this as O(1), but it calls an O(n)) public void push (T element) { if (size() == stack.length) expandCapacity(); stack[top] = element; top++; } private void expandCapacity() { T[] larger = (T[])(new Object[stack.length*2]); for (int index=0; index < stack.length; index++) larger[index] = stack[index]; stack = larger; } So why is the push function not O(n)?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.