I have the following code which basically takes a list of sorted integer arrays and merges them together removing the duplicates.   I have tried to do the complexity analysis and came to a rough conclusion that it may be O(n2) order. Could you please see if my understanding is correct here.   Also, if you could suggest ways to make the code better in terms of its running time, I would really be grateful.If you need the implementation of PrioQueue, please let me know.public ArrayList MergeMultiple(Object[] input){    ArrayList result = new ArrayList();    int activeArrayIndex = -1;    int inputArrayCount = input.Count();     // Keep track of indices of the arrays    int[] indices = new int[inputArrayCount];    // Keep track of whether the end has been reached for each array    bool[] endOfArray = new bool[inputArrayCount];    // Heap    PrioQueue heap = new PrioQueue();    while (endOfArray.Contains(false)) // O(N)    {        for (int i = 0; i < inputArrayCount; i++) // O(N)         {            int[] active = (int[])input[i];            int index = indices[i];            if (activeArrayIndex == -1 || (i == activeArrayIndex && !endOfArray[i]))            {                int value = active[index];                // Add value to the heap                heap.Enqueue(i + | + value, value); // O(N)??            }        }        // Add to result        if (!heap.IsEmpty())        {            activeArrayIndex = activeArrayIndex == -1 ? 0 : activeArrayIndex;            string activeArrayIndexWithVal = (string)heap.Dequeue(); // O(1)            string[] activeArrayObject = activeArrayIndexWithVal.Split('|');            // Identifying active array            activeArrayIndex = Convert.ToInt32(activeArrayObject[0]);            int[] activeArray = (int[])input[activeArrayIndex];            // Adding value to result object if not already in the array list            if (!result.Contains(activeArrayObject[1]))  // O(N)            {                result.Add(activeArrayObject[1]);            }            // Update index list with active array            indices[activeArrayIndex]++;            // update end of array count list for current array            endOfArray[activeArrayIndex] = activeArray.Length == (indices[activeArrayIndex]);        }    }    return result;}
Big-O complexity calculation for a merge and sort function
c#;queue;complexity