Advertisement

02.22.2007 at 09:45AM PST, ID: 22406970
[x]
Attachment Details

Simple Big O Notation Question

Asked by pendulumx in Algorithms

Tags: notation, o, big

Hi there. Just a quick question about Big O.

If you take this simple code:
public class delete {

  public static void main(String args[]) {

    test(10000);

  }

  public static int test(int numberIn) {

    int x = 0;
    if (x != 0) { return 1; }
    int y[] = new int[numberIn];
    int x[] = new int[numberIn];
    return 0;

  }
}

I understand that the statements "int x = 0" is O(1) + k because it is so simple. I realise that "if (x != 0) { return 1; }" is also O(1) +k as it is so simple.

I am a bit unsure of what this is: int y[] = new int[numberIn]; because the input gets passed to the statement. If the input was just 5 for instance then it would be no problem. But if the input was a billion say, surely it would take longer for the new int statement to perform its function?

Should I just assume that the int y[] = new int[numberIn]; (and x[] = new int[numberIn]) are both just simple O(1) statements or is each one a O(N) statement equalling O(n2)?

Thanks
Start Free Trial
 
Keywords: Simple Big O Notation Question
 
Loading Advertisement...
 
[+][-]02.22.2007 at 10:44AM PST, ID: 18590207

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Algorithms
Tags: notation, o, big
Sign Up Now!
Solution Provided By: wwfarch
Participating Experts: 3
Solution Grade: A
 
 
[+][-]02.22.2007 at 11:17AM PST, ID: 18590516

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.22.2007 at 02:25PM PST, ID: 18592155

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.24.2007 at 12:35AM PST, ID: 18601358

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32