Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2: Lists as Arrays These questions are all about implementing the List interface using arrays 2.1 ArrayStacks Recall that an ArrayStack stores n elements in

image text in transcribed

2: Lists as Arrays These questions are all about implementing the List interface using arrays 2.1 ArrayStacks Recall that an ArrayStack stores n elements in a backing array a at locatiosn a[0].,a[n-1]: public class ArrayStack a.length. Explain, in general termswhy we choose to double rather than just add 1 or a constant. Recall that, immediately after an ArrayStack is resized it has a.length 2*n 3. If we are currently about to grow the backing array a, what can you say about the number of add() and remove() operations since the last time the ArrayStack was resized? a. b. Recall that we shrink the back array a when 3*n Tl a int j; int n; 1. Describe, in words, how to perform an add(i,x) operation (a) if i -n/2 2. What is the running time of add(i,x) and remove(i) operations as a function of i and size()? 3. Describe, in words, why using System.arraycopy() to perform shifting of elements in the add(ix) and remove(i) operations is so much more complicated for an ArrayDeque than an ArrayStack. 4. Explain why, using an example, if a.length is a power of 2, then x mod a.length - x & (a.length-1) Why is this relevant when discussing ArrayDeques? 2: Lists as Arrays These questions are all about implementing the List interface using arrays 2.1 ArrayStacks Recall that an ArrayStack stores n elements in a backing array a at locatiosn a[0].,a[n-1]: public class ArrayStack a.length. Explain, in general termswhy we choose to double rather than just add 1 or a constant. Recall that, immediately after an ArrayStack is resized it has a.length 2*n 3. If we are currently about to grow the backing array a, what can you say about the number of add() and remove() operations since the last time the ArrayStack was resized? a. b. Recall that we shrink the back array a when 3*n Tl a int j; int n; 1. Describe, in words, how to perform an add(i,x) operation (a) if i -n/2 2. What is the running time of add(i,x) and remove(i) operations as a function of i and size()? 3. Describe, in words, why using System.arraycopy() to perform shifting of elements in the add(ix) and remove(i) operations is so much more complicated for an ArrayDeque than an ArrayStack. 4. Explain why, using an example, if a.length is a power of 2, then x mod a.length - x & (a.length-1) Why is this relevant when discussing ArrayDeques

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How is our behavior affected by the presence of others?

Answered: 1 week ago