stackToList (stack, true ) = O (n) . In most cases, this call will be O (1). However, when the List.Add function needs to expand more than its capacity, the array must be copied to a new array with a capacity two times higher than the previous one and iterate over the previous elements in order to save them in the new array. Thus, we can represent the actual operation in excel as IF (nLOG (n, 2) (n / 2) / INT (nLOG (n, 2) (n / 2)) = 1, n, 1). Given the lack of resource bottlenecks, if this algorithm completes in 10 seconds with 10 million items to fill 100 million items, you expect this to take about 10 (10) seconds. Actually, we know that it will be slightly worse than Big O Notation, predicts, because the operation O (n) will take many operations O (1) to recoup.
On an enlarged scale, you can see how List.Copy () affects cumulative operations. 
Reduced, you can see that this does not affect the scale compared to the O (n) operation. 
stackToList (stack, false ) = O (n ^ 2) . The list insert function executes a copy of the array, which should move all the elements in the list to a new list. As the pointer begins to iterate through the parent stack, the number of operations starts at 0, and then grows until it reaches n. On average, this happens n / 2 times. Constant 2 is removed in Big O Notation, and you are left with n. Given the lack of resource bottlenecks, if this algorithm completed in 10 seconds with 10 million items to fill 100 million items, you expect it to take about 10 (10 ^ 2) seconds. Actually, we know that the second case will scale better than Big O Notation predicted, because it is actually n * (n-1), but it will not scale better than O (n * Log (n)), the next step down. 
Refusal of operations:
List<int> stackToList(Stack<int> stack, bool reverseOrder) { List<int> items = new List<int>();
Charles Esau
source share