Data Structures and Algotirhtms
CS241 - Fall 2017 - Assignment #2
Assigned: October 5th, 2017 Due: October 13th, 2017 No late submissions. You will be able to complete your submission later if appropriate, but if you do not submit a significant part of the assignment by the due date you will not be able to submit afterwards. Extra credits do not have a deadline.
Collaboration policy: The goal of homework is to give you practice in mastering the course material. Consequently, you are encouraged to collab- orate with others (groups of at most three). In fact, students who form study groups generally do better on exams than do students who work alone. If you do work in a study group, however, you owe it to yourself and your group to be prepared for your study group meeting. Specifically, you should spend at least 30–45 minutes trying to solve each problem beforehand. If your group is unable to solve a problem, it is your responsibility to get help from the instructor before the assignment is due. You must write up each problem solution and/or code any programming assignment by yourself without assistance, even if you collaborate with others to solve the problem. You are asked to identify your collaborators. If you did not work with anyone, you must write “Collaborators: none.” If you obtain a solution through research (e.g., on the web), acknowledge your source, but write up the solution in your own words. It is a violation of this pol- icy to submit a problem solution that you cannot orally explain to the instructor. No other student may use your solutions; this includes your writing, code, tests, documentation, etc. It is a violation of this policy to permit anyone other than the instructor and yourself read-access to the location where you keep your solutions.
1
Submission Guidelines: Your group has to submit your work on Black- board by the due date. Only one submission per group is necessary. Just make sure that you identify your group in the header. For each of the programming assignments you must use the header template pro- vided in Blackboard. The header must contain, your name, course number, semester, homework number, problem number, and list of collaborators (if any, otherwise put “none”). Your answers to questions that do not require coding must be included in this header as well. Your code must follow the Java formatting standards posted in Blackboard. Format will also be part of your grade.
To complete your submission, you have to upload two files to Blackboard: your source file and your class file. The submission will not be accepted otherwise.
Style and Correctness: Keep in mind that your goal is to communi- cate. Full credit will be given only to the correct solution which is described clearly. Convoluted and obtuse descriptions might receive low marks, even when they are correct. Also, aim for concise solutions, as it will save you time spent on write-ups, and also help you conceptualize the key idea of the problem.
2
Assignment #2
Programming Assignment Grading Rubric: The following rubric applies only to programming assignments.
Program characteristic
Program feature Credit possible
Design 30%
Algorithm 30%
Functionality 30%
Program runs without errors
20%
Correct result given 10%
Input 15%
User friendly, typos, spacing
10%
Values read in correctly
5%
Output 15%
Output provided 10%
Proper spelling, spacing, user friendly
5%
Format 10%
Comments, name 5%
Indentation 5%
TOTAL 100%
1(50) 2(20) 3(30) TOTAL(100) EC
3
Assignment:
1. (50 points) The Queue class works as the line at Starbucks R©, that is, each arriving customer joins the line at the end, and the first customer to order is standing at the front. This ordering is called “First-In First-Out” (FIFO). Implement a generic class Queue〈T〉 that maintains a collection of items of generic type T in FIFO order. Use the class ArrayList〈T〉 in the Java API to implement Queue. That is, your Queue must store the items in an ArrayList, and the methods of your Queue must use methods of ArrayList. Your Queue class must provide the following instance methods:
enqueue: that adds a new item to the back of the queue.
dequeue: that removes an item from the front of the queue.
inQueue?: that returns true if a given item is in the queue, or false otherwise.
isEmpty?: that returns true if the queue is empty, or false other- wise.
2. (20 points) Write a testQueue class with a main() method that tests all four operations of the Queue class designed. Override the toString() method of the class Object, and use it to display all the items in the queue after each method is called.
3. (30 points) Compute the big-O running time of each of the four in- stance methods, explaining the running time (basic operation counted, number of iterations in loops, etc.)
4. (Extra credit) Repeat point 1 implementing the queue with a circular array (as we did in class), expanding the array when it is full and shrinking it when it is half empty.
4