Stacks, Lists, and Generics Would we expect that an array-based stack (e.g., ArrayStack) has a push() method that is O(1
Posted: Mon Jun 06, 2022 6:27 pm
Stacks, Lists, and Generics Would we expect that an array-based stack (e.g., ArrayStack) has a push() method that is O(1) on the number of times the array is accessed? O No, there is always a chance the array may need to resize, resulting in O(n). No, all stack implementations require that existing elements are shifted over to make room for a new element. Yes, a loop is not needed to find the correct index to add the element, so it must be 0(1). Yes, all algorithms that use arrays will run in O(1).