- Stacks Lists And Generics Would We Expect That An Array Based Stack E G Arraystack Has A Push Method That Is O 1 1 (17.89 KiB) Viewed 20 times
Stacks, Lists, and Generics Would we expect that an array-based stack (e.g., ArrayStack) has a push() method that is O(1
-
- Site Admin
- Posts: 899603
- 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).