If the output array already has some elements in it, then dequeue runs in constant time; otherwise, dequeue takes O ( n ) {\displaystyle O(n)} time to add all the elements onto the output array from the input array, where n is the current length of the input array. After copying n elements from input, we can perform n dequeue operations, each taking constant time, before the output array is empty again. Thus, we can perform a sequence of n dequeue operations in only O ( n ) {\displaystyle O(n)} time, which implies that the amortized time of each dequeue operation is O ( 1 ) {\displaystyle O(1)} .[4]