Randomized Queues and Deques

Similar documents
Project 2 (Deques and Randomized Queues)

COS 226 Algorithms and Data Structures Fall Midterm

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal

COMP 250 Midterm #2 March 11 th 2013

I have neither given nor received any assistance in the taking of this exam.

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

infix expressions (review)

Basic Data Structures

Basic Data Structures 1 / 24

CS171 Midterm Exam. October 29, Name:

ITI Introduction to Computing II

PA3 Design Specification

Midterm Exam (REGULAR SECTION)

Computer Science First Exams Pseudocode Standard Data Structures Examples of Pseudocode

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

CSC 1052 Algorithms & Data Structures II: Queues

How to Win Coding Competitions: Secrets of Champions. Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue.

Stacks, Queues (cont d)

CS 10, Fall 2015, Professor Prasad Jayanti

COS 226 Algorithms and Data Structures Fall Midterm

CSCA48 Term Test 1 Seminar

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s.

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

9/26/2018 Data Structure & Algorithm. Assignment04: 3 parts Quiz: recursion, insertionsort, trees Basic concept: Linked-List Priority queues Heaps

Apply to be a Meiklejohn! tinyurl.com/meikapply

Assignment 2. CS 234 Fall 2018 Sandy Graham. Create()

Name: After line 1: After line 3: After line 5: After line 8: After line 11:

CSC212:Data Structure

COS 226 Algorithms and Data Structures Spring Midterm Exam

CS W3134: Data Structures in Java

csci 210: Data Structures Stacks and Queues

You must include this cover sheet. Either type up the assignment using theory4.tex, or print out this PDF.

Abstract Data Types - Lists Arrays implementa4on Linked- lists implementa4on

DS L9: Queues

CSE wi: Practice Midterm

Lists. ordered lists unordered lists indexed lists 9-3

The Abstract Data Type Queue. Module 8. The Abstract Data Type Queue. The Abstract Data Type Queue. The Abstract Data Type Queue

Queue Implemented with a CircularArray. Queue Implemented with a CircularArray. Queue Implemented with a CircularArray. Thursday, April 25, 13

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011

CS 261: Data Structures. Dynamic Array Queue

Assignment 1. Check your mailbox on Thursday! Grade and feedback published by tomorrow.

COSC 2011: Assignment 1 (v.4)

CS2012 Programming Techniques II

Computer Science 136 Exam 2

CH7. LIST AND ITERATOR ADTS

Data Abstraction and Specification of ADTs

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

Department of Computer Science and Engineering. CSE 2011: Fundamentals of Data Structures Winter 2009, Section Z

STACKS AND QUEUES. Problem Solving with Computers-II

School of Electrical Engineering & Computer Science Oregon State University. CS Recitation 3 Spring 2012

Name CPTR246 Spring '17 (100 total points) Exam 3

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle.

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

6.7 b. Show that a heap of eight elements can be constructed in eight comparisons between heap elements. Tournament of pairwise comparisons

Queues. Stacks and Queues

Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006

Lecture 4. The Java Collections Framework

Midterm I Exam Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas. September 30, 2010

Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

ITI Introduction to Computing II

LIFO : Last In First Out

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

ECSE 321 Assignment 2

Examination Questions Midterm 1

The Java Collections Framework. Chapters 7.5

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

Data structure and algorithm in Python

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

CSE 143 SAMPLE MIDTERM

Queues 4/11/18. Many of these slides based on ones by Cynthia Lee

Data Structure: Lists and Iterators. Instructor: Prof. Young-guk Ha Dept. of Computer Science & Engineering

Soda Machine Laboratory

CSE 131 Computer Science 1 Module 9a: ADT Representations. Stack and queue ADTs array implementations Buffer ADT and circular lists

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

CS 216 Exam 1 Fall SOLUTION

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

COMP 213 Advanced Object-oriented Programming Lecture 8 The Queue ADT (cont.)

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

This lecture. Iterators ( 5.4) Maps. Maps. The Map ADT ( 8.1) Comparison to java.util.map

COMPUTER SCIENCE. Paper 1

January 24, Abstract Data Types (ADTs) An ADT is an abstraction of a data structure.

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

Array Lists Outline and Required Reading: Array Lists ( 7.1) CSE 2011, Winter 2017, Section Z Instructor: N. Vlajic

Stacks and queues (chapters 6.6, 15.1, 15.5)

Stacks and Queues. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG

Computer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures

CH7. LIST AND ITERATOR ADTS

Data Structures Lecture 5

Lecture Data Structure Stack

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

Computer Science E-119 Fall Problem Set 3. Due before lecture on Wednesday, October 31

CH 6. VECTORS, LISTS, AND SEQUENCES

Linked Structures. See Section 3.2 of the text.

UNIVERSITY REGULATIONS

Name: I. 20 II. 20 III. 20 IV. 40. CMSC 341 Section 01 Fall 2016 Data Structures Exam 1. Instructions: 1. This is a closed-book, closed-notes exam.

Transcription:

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.