Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer thank you Q.1 Suppose list1 is a java.util.ArrayList object and list2 is a java.util.LinkedList object. Both lists are initially empty. Analyze the following

Please answer thank you

Q.1

Suppose list1 is a java.util.ArrayList object and list2 is a java.util.LinkedList object. Both lists are initially empty. Analyze the following code and from the statements below select those that are true:

A: for (int i = 0; i < 100000; i++) list1.add(0, i); B: for (int i = 0; i < 100000; i++) list2.add(0, i);

Group of answer choices

A.Code fragment B runs faster than code fragment A since adding an element at a beginning of the linked list is O(1) whereas in an array list the same operation is O(n)

B. Both lists contain 100000 elements after fragments A and B are executed

C. While the actual runtimes may vary between the two code fragments, the complexity of adding an element at the beginning is O(1) for both types of lists

D. While the actual runtimes may vary between the two code fragments, the complexity of adding an element at the beginning is O(n) for both types of lists

E. Code fragment A runs faster than code fragment B since adding an element at the beginning of an array list is a O(1) whereas in a linked list the same operation is O(n)

Q.2

Suppose list1 is a java.util.ArrayList object and list2 is a java.util.LinkedList object. Both contains 1 million double values. Analyze the following code and from the statements below select those that are true:

A: while (list1.size() > 0) list1.remove(list1.size() - 1); B: while (list2.size() > 0) list2.remove(list2.size() - 1);

Group of answer choices

A. Both A and B remove all elements from the lists

B. While the actual runtimes may vary between the two code fragments, the complexity of removing the first element is O(n) for both list implementations

C. Code fragment B runs faster than code fragment A since removing last element from this linked list implementation is O(1) whereas in an array list the same operation is O(n)

D. While the actual runtimes may vary between the two code fragments, the complexity of removing the last element is O(1) for both list implementations

E. Code fragment A runs faster than code fragment B since removing last element from an array list is O(1) whereas in this linked list implementation the same operation is O(n)

Q.3

Which of the following statements about stacks are true?

Group of answer choices

A. Only stacks implemented using linked lists have unlimited capacity

B. A stack can be viewed as a special type of list, where the elements are accessed, inserted, and deleted only from the end, called the top, of the stack

C. It is possible to implement a stack using a singly linked list with only the head reference for storage and achieve O(1) complexity for push() and pop() operations

D. All stack operations other than isEmpty() are O(n)

E. While a stack may be implemented using a linked list, pop() and push() operations of such implementations will neccessarily be O(n)

Q.4

Which of the following statements about queues are true?

Group of answer choices

A.While a stack may be implemented using an array, enqueue() and dequeue() operations of such implementation will neccessarily be O(n)

B. It is possible to implement a queue using a singly linked list with tail reference for storage and achieve O(1) complexity for enqueue() and dequeue() operations

C. A queue can be viewed as a special type of list, where the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue.

D. In a circular array implementation of a queue the enqueue() and dequeue() operations are O(1) but capacity is limited by the size of the array

E. All queue operations other than isEmpty() are O(n)

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_2

Step: 3

blur-text-image_3

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

What is the difference between trade deficits and balance of trade

Answered: 1 week ago

Question

e. What are notable achievements of the group?

Answered: 1 week ago