Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer all the questions, thank you. The topic is about data structures in java CS310: Data Structures Week 2: Dynamic Arrays Page 2 Your

image text in transcribedimage text in transcribed

Please answer all the questions, thank you. The topic is about data structures in java

CS310: Data Structures Week 2: Dynamic Arrays Page 2 Your Name: Section: Self-Study Questions 1. Explain (with a drawing) what the memory looks like for a list stored as a dynamic array list. Make sure to represent the memory needed to store additional helper variables. 2. Write the pseudocode for insert() for a dynamic array list with generic type T. 3. Explain why we say that the worst case big-O of appending to a dynamic array list is O(n) while its amortized cost is only O(1) [covered in readings this week, or lecture next week]. 4. Describe how you make a class "iterable" in Java. What interfaces do you need? What methods are required by those interfaces? Are there any additional optional methods? 5. Write code to implement a basic iterator for a dynamic array list. CS310: Data Structures Week 2: Dynamic Arrays Page 1 Your Name: Section: Participation Questions 1. You have a dynamic array with 2 elements in it and a capacity of 3. The capacity doubles when additional Space is needed and shrinks by 50% (rounding down) when the size is at or below 1/3 capacity. What will be the capacity of the list after the following operations have been performed answer should be a single integer number): Answer: Add, Add, Remove, Remove, Add 2. You have a dynamic array with 2 elements in it and a capacity of 3. The capacity doubles when additional space is needed and shrinks by 50% (rounding down) when the size is at or below 50% capacity. What will be the capacity of the list after the following operations have been performed answer should be a single integer number): Answer: Add, Add, Remove, Add 3. Given the dynamic list named "" below, which contains the elements 1-5 and has a capacity of 8: 1 2 3 4 5 0 0 0 Indicate which of the following operations would be valid and which would produce an error. Assume that cach operation starts with a fresh copy of the list above, Circle the correct answer where: V - VALID I = INVALID / ERROR VII Insert an element at index 7 VI Insert an element at index 0, then another at 0, then another at 0 VII Insert an element at index 5, then another at 6, then another at 7 4. Given the iterator discussed in class, where is the current position of the iterator iter at the end of the code sequence on the right? a positioned at A b. positioned at B c. positioned at C d. positioned before A e. positioned between A and B f. positioned between B and C LL 1 = new LL{(A, B, C, D) iter = l. iterator() iter.next() iter.next() CS310: Data Structures Week 2: Dynamic Arrays Page 2 Your Name: Section: Self-Study Questions 1. Explain (with a drawing) what the memory looks like for a list stored as a dynamic array list. Make sure to represent the memory needed to store additional helper variables. 2. Write the pseudocode for insert() for a dynamic array list with generic type T. 3. Explain why we say that the worst case big-O of appending to a dynamic array list is O(n) while its amortized cost is only O(1) [covered in readings this week, or lecture next week]. 4. Describe how you make a class "iterable" in Java. What interfaces do you need? What methods are required by those interfaces? Are there any additional optional methods? 5. Write code to implement a basic iterator for a dynamic array list. CS310: Data Structures Week 2: Dynamic Arrays Page 1 Your Name: Section: Participation Questions 1. You have a dynamic array with 2 elements in it and a capacity of 3. The capacity doubles when additional Space is needed and shrinks by 50% (rounding down) when the size is at or below 1/3 capacity. What will be the capacity of the list after the following operations have been performed answer should be a single integer number): Answer: Add, Add, Remove, Remove, Add 2. You have a dynamic array with 2 elements in it and a capacity of 3. The capacity doubles when additional space is needed and shrinks by 50% (rounding down) when the size is at or below 50% capacity. What will be the capacity of the list after the following operations have been performed answer should be a single integer number): Answer: Add, Add, Remove, Add 3. Given the dynamic list named "" below, which contains the elements 1-5 and has a capacity of 8: 1 2 3 4 5 0 0 0 Indicate which of the following operations would be valid and which would produce an error. Assume that cach operation starts with a fresh copy of the list above, Circle the correct answer where: V - VALID I = INVALID / ERROR VII Insert an element at index 7 VI Insert an element at index 0, then another at 0, then another at 0 VII Insert an element at index 5, then another at 6, then another at 7 4. Given the iterator discussed in class, where is the current position of the iterator iter at the end of the code sequence on the right? a positioned at A b. positioned at B c. positioned at C d. positioned before A e. positioned between A and B f. positioned between B and C LL 1 = new LL{(A, B, C, D) iter = l. iterator() iter.next() iter.next()

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions