Randomized Queues and Deques Write a generic ADT for a randomized queue or for a deque. The goal of this assignment is to implement elementary data structures using arrays and linked lists, and to get you reacquainted with programming in Java. Randomized queue. A randomized 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 ADT RandomizedQueue that supports the following operations. public class RandomizedQueue<Item> { public RandomizedQueue() // construct an empty randomized queue public boolean isempty() // return true if the queue is empty, false otherwise public void add(item item) // insert the item into the queue public Item remove() // delete and return an item from the queue, uniformly at random } Your ADT should support all operations in constant amortized time. That is, any sequence of N randomized queue operations (starting from an empty queue) should take O(N) steps. Dequeue. A double ended queue or deque is a generalization of a stack and a queue that supports inserting and removing items from either the front or the back of the data structure. Create a generic ADT Dequethat supports the following operations. public class Deque<Item> { public Deque() // construct an empty deque public boolean isempty() // return true if the queue is empty, false otherwise public void addfirst(item item) // insert the item at the front of the queue public void addlast(item item) // insert the item at the end of the queue public Item removefirst() // delete and return the first item in the queue public Item removelast() // delete and return the last item in the queue } Your ADT should support each operations in constant worst case time. That is, each deque operation should take O(1) steps.
Client. Write a client program to solve one of the following problems depending on the choosen datastructure. You may only declare one variable in your client, and it must be of type Deque or RandomizedQueue. Your client program should avoid casting by using generics. Given a command line parameter k, read in a sequence of strings from standard input, and print out a subset of exactly k of them, uniformly at random. Read in a DNA sequence from standard input using StdIn.readChar. Determine whether the string represents a Watson Crick complemented palindrome (the string equals its reverse when you replace each base with its complement: A T, C G). Palindromes in DNA have have many important biological roles. For example, tumor cells frequently amplify their genes by forming DNA palindromes. Deliverables. Submit the data types RandomizedQueue.java or Deque.java. Each data type should include its own main that thoroughly tests the associated operations. You may not call any Java library functions except the listed ones below. Also submit the client programs Subset.java or Palindrome.java. Finally, submit this file and answer the questions. Libraries that can be used. java.lang package any code from the book code or from the stdlib book package http://algs4.cs.princeton.edu/code/ Name: Student ID: Hours to complete assignment (optional):
* Explain briefly how you implemented the randomized queue or deque. * Which data structure did you choose (array, linked list, etc.) * and why?
* How much memory (in bytes) do your data types use to store N items * in the worst case? Use the 64 bit memory cost model from Section * 1.4 of the textbook and use tilde notation to simplify your answer. * Briefly justify your answers and show your work. * * Do not include the memory for the items themselves (as this * memory is allocated by the client and depends on the item type) * or for any iterators, but do include the memory for the references * to the items (in the underlying array or linked list). Randomized Queue: ~ bytes Deque: ~ bytes
* Known bugs / limitations. /********************************************************************** * Describe any serious problems you encountered.
* List any other comments here. Feel free to provide any feedback * on how much you learned from doing the assignment, and whether * you enjoyed doing it.