Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is java. Problem. (Random Queue) A random queue is similar to a stack or queue, except that the item removed is chosen uniformly at

This is java.

Problem. (Random Queue) A random queue is similar to a stack or queue, except that the item removed is chosen uniformly at random from items in the data structure. Create a generic iterable data type ResizingArrayRandomQueue in ResizingArrayRandomQueue.java that uses a resizing array to implement the following random queue API:

image text in transcribed

The order of two or more iterators to the same randomized queue must be mutually independent; each iterator must maintain its own random order.

Corner cases.

Throw a java.lang.NullPointerException if the client attempts to add a null item; throw a java.util.NoSuchElementException if the client attempts to sample or dequeue an item from an empty randomizedqueue;

throw a java.lang.UnsupportedOperationException if the client calls the remove() method in the iterator; throw a java.util.NoSuchElementException if the client calls the next() method in the iterator and there are no more items to return.

Performance requirements.

Your randomized queue implementation must support each randomized queue operation (besides creating an iterator) in constant amortized time and use space proportional to linear in the number of items currently in the queue. That is, any sequence of M randomized queue operations (starting from an empty queue) must take at most cM steps in the worst case, for some constant c. Additionally, your iterator implementation must support next() and hasNext() in constant worst-case time and construction in linear time; you may use a linear amount of extra memory per iterator.

--------------------------------------------------------------------------------------------------------------------------

And the result should look like this:

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

And here's what I have and the format should look like:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

--------------------------------------------------------------------------------------------------------------------------

method ResizingArrayRandomQueue) boolean isEmpty () int sizeC) void enqueue (Item item) Item dequeue) Item sample) description construct an empty queue is the queue empty? the number of items on the queue add item to the queue remove and return a random item from the queue return a random item from the queue, but do not remove it Iterator Item> iterator) an independent iterator over items in the queue in random order String toString() a string representation of the queue method ResizingArrayRandomQueue) boolean isEmpty () int sizeC) void enqueue (Item item) Item dequeue) Item sample) description construct an empty queue is the queue empty? the number of items on the queue add item to the queue remove and return a random item from the queue return a random item from the queue, but do not remove it Iterator Item> iterator) an independent iterator over items in the queue in random order String toString() a string representation of the queue

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