# Please tell me I am not crazy... Time Complexity (Big-O) Question

• 11-03-2008, 11:38 PM
Jordan
Please tell me I am not crazy... Time Complexity (Big-O) Question
Hi there,

New to the forums and I hope to help out as much as I can. I have lurked for a bit, however this is my first post. Anyways, here goes.

Is the time complexity of this code O(n^2)?

Code:

```    public void placeLargest(int[] list, int N)     {                         // N is how many of the largest items we want to find (N=3, find 3 largest)             int n = 0;             int largest, index;             int[] tempList = list;                         while (n < N)//Pass through the array N times             {                     largest = tempList[0];                     index = 0;                     for (int i = 0; i < tempList.length; i++)                     {                             if (tempList[i] > largest)                             {                                     largest = tempList[i];                                     index = i;                                    }                     }                     tempList[index] = 0;                     Nlargest.enqueue(largest);//Simlply place the value in a queue created earlier                     n++;             }     }```
• 11-04-2008, 12:53 AM
emceenugget
I'm pretty sure that it's O(N*tempList.length)
• 11-04-2008, 03:48 AM
Norm
Can you execute the code with worst case data and use a counter to find out?