Question: 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:

This is java. Problem. (Random Queue) A random queue is similar to

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:

a stack or queue, except that the item removed is chosen uniformly

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

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

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: The order of two or more iterators

to the same randomized queue must be mutually independent; each iterator must

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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!