Stacks, Lists, and Generics Would we expect that an array-based stack (e.g., ArrayStack) has a push() method that is O(1
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Stacks, Lists, and Generics Would we expect that an array-based stack (e.g., ArrayStack) has a push() method that is O(1
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).
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!