This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: EECS 114: Assignment 1 September 30, 2008 Due Monday 13 Oct 2008 at 11:59pm 1 Programming Problem 1.1 Queue Write a program that implements a queue of integers with enqueue and dequeue interfaces. 1. Provide a test program that takes in integer n, enqueues n elements on the queue, then enqueues and de- queues an element 100,000 times. Use the java time calls to time how long the 100,000 enqueue and dequeue operations take on average. You can take a look under java.util.Date class in the following website http://java.sun.com/j2se/1.5.0/docs/api/index.html for help. 2. Execute the program for n= 1,10,100,1000, 10000,... and record the execution times for the enqueue and dequeue operations in a table. Vary n until the total time the program takes to execute is > 10 seconds or until you run out of memory. 3. State the complexity of the enqueue and dequeue operations using big O notation and provide an argument (analyzing the code for the enqueue and dequeue operations) why the stated complexity is correct. 4. You are not allowed to use anything other than arrays or classes that you define to implement the queue, i.e. vectors or other library data structures are not allowed. First create a subdirectory named hw1 (for homework one). Then, use your editor to create a Java file named hw1queue.java . The file should state your name and exercise number in a comment. 1.1.1 Compiling your code Compiling and running a java program is done in two steps To test your program, it must be compiled with the javac command. To call javac , use the following template: % javac sourcefile.java Upon successful completion of the above command, a .class file is created with the same name as the sourcefile. To run your program, invoke the java command, use the following template: % java sourcefile Note that there is no .class extension required in order to run the java program. Below is an example of how you would compile and execute the problem: % javac hw1queue.java % java hw1queue program executes newport% _ 1 1.2 Doubly Linked List Implement a doubly linked list with the following methods return the first node return the last node remove a node return the previous node (given a node) return the next node (given a node) search for a node that contains a given value 1. Provide a test program that takes in an integer n and m and adds the integers [1,...n] to the list. It then generates a random number between 1 and n, searches for the corresponding node in the list, and repeats this m times. Compute the average time it takes to perform a search operation using the java time calls . 2. Execute the program for n=1,10,100,1000, 10000,... and record the execution times for searching for m=1000 items in the list. Vary n until the total time the program takes to execute is > 10 seconds or until you run out of memory....
View Full Document
This note was uploaded on 03/28/2009 for the course CSE 120A taught by Professor Healey during the Spring '08 term at UC Irvine.
- Spring '08