SlideShare ist ein Scribd-Unternehmen logo
1 von 15
/* PQTimer.java
A simple driver program to run timing tests on your ArrayPQ
and BinaryHeapPQ.
Programming Assignment #2
*/
import java.util.Iterator;
import java.util.ConcurrentModificationException;
import data_structures.*;
public class PQTimer {
public static void main(String [] args) {
///////////////////////////////////////////////////////////
/// Change this variable to something smaller if timing takes too
long.
final int INITIAL_SIZE = 15000;
///////////////////////////////////////////////////////////
final int ITERATIONS = 10000;
final int NUMBER_OF_STEPS = 15;
final int MAX_SIZE = INITIAL_SIZE * NUMBER_OF_STEPS
+1;
final int NUMBER_OF_PRIORITIES = 20;
int size = INITIAL_SIZE;
long sequence_number = 0;
long start, stop;
int priority;
PQTestObject [] array = new PQTestObject[MAX_SIZE];
for(int i=0; i < MAX_SIZE; i++)
array[i] = new PQTestObject((int)
((10000*Math.random() %
NUMBER_OF_PRIORITIES) +1), sequence_number++);
for(int j=0; j < 15; j++) {
PriorityQueue<PQTestObject> queue =
new
HeapPriorityQueue<PQTestObject>(MAX_SIZE);
queue.clear();
for(int i = 0; i < size; i++)
queue.insert(array[i]);
start = System.currentTimeMillis(); // start the timer
for(int i = 0; i < ITERATIONS; i++) {
queue.insert(array[(int)(100000*Math.random() %
MAX_SIZE)]);
queue.remove();
}
stop = System.currentTimeMillis();
System.out.println("HeapPQ, Time for n=" + size + ": " +
(stop-start));
queue.clear();
queue = new
ArrayPriorityQueue<PQTestObject>(MAX_SIZE);
for(int i = 0; i < size; i++)
queue.insert(array[i]);
start = System.currentTimeMillis(); // start the timer
for(int i = 0; i < ITERATIONS; i++) {
queue.insert(array[(int)(100000*Math.random() %
MAX_SIZE)]);
queue.remove();
}
stop = System.currentTimeMillis();
System.out.println("ArrayPQ, Time for n=" + size + ": " +
(stop-start)+"n");
size += INITIAL_SIZE;
}
}
}
/* PQTestObject.java
A simple testing object that has a priority. The sequence
number in this class is NOT the insertion sequence number
you will have in the BinaryHeapPQ class. It is only used
for verification of correct behavior, and never used in
ordering objects of this class.
*/
public class PQTestObject implements
Comparable<PQTestObject> {
private int priority;
private long sequence_number;
public PQTestObject(int p, long s) {
priority = p;
sequence_number = s;
}
public int compareTo(PQTestObject o) {
return priority - o.priority;
}
public String toString() {
return priority + " " + sequence_number;
}
}
/* PQTester.java
A simple driver program to test your ArrayPQ and
BinaryHeapPQ.
NOTE: Does not test all of the methods in your PQs. The
fact
that your program runs with this driver does not mean that it
is error free.
Requires PQTestObject class
Alan Riggins
CS310 Fall 2012
Programming Assignment #2
*/
import java.util.Iterator;
import java.util.ConcurrentModificationException;
import data_structures.*;
public class PQTester {
public static void main(String [] args) {
final int SIZE = 50;
long sequence_number = 0;
int priority;
//////////////////////////////////////////////////////////////////////
/// Select the implementation you wish to test
PriorityQueue<PQTestObject> queue =
new ArrayPriorityQueue<PQTestObject>(SIZE);
//////////////////////////////////////////////////////////////////////
System.out.println("Now testing the ARRRAY
implementation");
PQTestObject [] array = new PQTestObject[SIZE];
for(int i=0; i < SIZE; i++)
array[i] = new PQTestObject((int)
((1000*Math.random() % 20) +1),
sequence_number++);
for(int i=0; i < SIZE; i++)
queue.insert(array[i]);
// check to see what happens if insertion beyond capacity
try {
if(queue.insert(new PQTestObject(1,1)))
throw new RuntimeException("ERROR, inserted
beyond
capacity");
}
catch(Exception e) {
e.printStackTrace();
}
if(queue.size() != SIZE)
System.out.println("ERROR, wrong size!");
System.out.println("Now printing with the iterator. " +
"They should come out in any order.n" +
"Priorty SequenceNumber");
Iterator<PQTestObject> iter = queue.iterator();
while(iter.hasNext())
System.out.print(iter.next()+ " ");
System.out.println();
try {
PQTestObject obj = iter.next();
}
catch(Exception e) {
System.out.println("Good, iterator passed.");
}
for(PQTestObject o : queue)
;
System.out.println("================================
==============");
System.out.println("Now removing them all...");
for(int i=0; i < SIZE; i++)
System.out.print(queue.remove()+ " ");
System.out.println();
if(!queue.isEmpty())
System.out.println("ERROR, queue should be empty");
queue.clear();
System.out.println("================================
==============");
queue.insert(new PQTestObject(25,1));
queue.insert(new PQTestObject(25,2));
queue.insert(new PQTestObject(1,1));
queue.insert(new PQTestObject(1,2));
queue.insert(new PQTestObject(25,3));
System.out.println("Now emptying remaining elements");
while(!queue.isEmpty())
System.out.println(queue.remove());
//////////////////////////////////////////////////////////////////////
queue = new HeapPriorityQueue<PQTestObject>(SIZE);
//////////////////////////////////////////////////////////////////////
System.out.println("nnNow testing the HEAP
implementation");
array = new PQTestObject[SIZE];
for(int i=0; i < SIZE; i++)
array[i] = new PQTestObject((int)
((1000*Math.random() % 20) +1),
sequence_number++);
for(int i=0; i < SIZE; i++)
queue.insert(array[i]);
// check to see what happens if insertion beyond capacity
try {
if(queue.insert(new PQTestObject(1,1)))
throw new RuntimeException("ERROR, inserted
beyond
capacity");
}
catch(Exception e) {
e.printStackTrace();
}
if(queue.size() != SIZE)
System.out.println("ERROR, wrong size!");
System.out.println("Now printing with the iterator. " +
"They should come out in any order.n" +
"Priorty SequenceNumber");
iter = queue.iterator();
while(iter.hasNext())
System.out.print(iter.next()+ " ");
System.out.println();
try {
PQTestObject obj = iter.next();
}
catch(Exception e) {
System.out.println("Good, iterator passed.");
}
for(PQTestObject o : queue)
;
System.out.println("================================
==============");
System.out.println("Now removing them all...");
for(int i=0; i < SIZE; i++)
System.out.print(queue.remove()+ " ");
System.out.println();
if(!queue.isEmpty())
System.out.println("ERROR, queue should be empty");
queue.clear();
System.out.println("================================
==============");
queue.insert(new PQTestObject(25,1));
queue.insert(new PQTestObject(25,2));
queue.insert(new PQTestObject(1,1));
queue.insert(new PQTestObject(1,2));
queue.insert(new PQTestObject(25,3));
System.out.println("Now emptying remaining elements");
while(!queue.isEmpty())
System.out.println(queue.remove());
}
}
The Program:
For this assignment, you will write two implementations of a
Priority Queue. For this ADT, removal
operations always return the object in the queue of highest
priority that has been in the queue the
longest. That is, no object of a given priority is ever removed as
long as the queue contains one or more
objects of a higher priority. Within a given priority FIFO order
must be preserved. Your two
implementations will be:
Both implementations must have identical behavior, and must
implement the PriorityQueue interface
(provided). Both implementations must have two constructors,
a default constructor with no
arguments that uses the DEFAULT_MAX_CAPACITY constant
from the PriorityQueue.java interface, and
a constructor that takes a single integer parameter that
represents the maximum capacity of the
PQ. The PriorityQueue interface follows:
/* The PriorityQueue ADT may store objects in any order.
However,
removal of objects from the PQ must follow specific criteria.
The object of highest priority that has been in the PQ longest
must be the object returned by the remove() method. FIFO
return
order must be preserved for objects of identical priority.
Ranking of objects by priority is determined by the
Comparable
interface. All objects inserted into the PQ must implement
this
interface.
*/
package data_structures;
import java.util.Iterator;
public interface PriorityQueue<E> extends Iterable<E> {
static final int DEFAULT_MAX_CAPACITY = 1000;
// Inserts a new object into the priority queue. Returns true
if
// the insertion is successful. If the PQ is full, the insertion
// is aborted, and the method returns false.
public boolean insert(E object);
// Removes the object of highest priority that has been in the
// PQ the longest, and returns it. Returns null if the PQ is
empty.
public E remove();
// Returns the object of highest priority that has been in the
// PQ the longest, but does NOT remove it.
// Returns null if the PQ is empty.
public E peek();
// Returns the number of objects currently in the PQ.
public int size();
// Returns an iterator of the objects in the PQ, in no
particular
// order. The iterator must be fail-fast.
public Iterator<E> iterator();
// Returns an iterator of the objects in the PQ, in exactly the
// same order in which they will be dequeued. The iterator
must
// be fail-fast.
public Iterator<E> orderedIterator();
// Returns the PQ to an empty state.
public void clear();
// Returns true if the PQ is empty, otherwise false
public boolean isEmpty();
// Returns true if the PQ is full, otherwise false. List based
// implementations should always return false.
public boolean isFull();
}
Thus, your project will consist of the following files. You must
use exactly these filenames.
The ordered array must use binary
search to identify the correct insertion point for new additions.
heap must be stable.
Additional Details:
les specified, no
additional source code files are
permitted. (Do not hand in a copy of PriorityQueue.java, as it is
provided to you).
interface provided. I will grade your
project with my copy of this file.
number at the beginning of the file.
'data_structures'.
java.util.NoSuchElementException, and
ConcurrentModificationException only. If you feel that you
need to import anything else, let
me know. You are expected to write all of the code yourself,
and you may not use the Java API
for any containers.
nt anything.
catch any exceptions.
Your iterators should throw:
o ConcurrentModificationException
o NoSuchElementException
o UnsupportedOperationException
but must handle any/all error
conditions gracefully. i.e. if the
user attempts to call the clear() method on an empty PQ, or
remove an item from an empty PQ,
the program should not crash.
provided. You may not add any public
methods to the implementations, but you may add private ones,
or inner classes if needed.
compiled, but it must compile and run
correctly on rohan using JDK1.6 to receive any credit.
binary heap implementation. Sorting
methods are available in the class lecture notes, and you are
welcome to use the code (now and
in the future). However, you should create a private method in
the appropriate place rather
than using any external class directly. You should select a O(n
logn) method that is stable.
The Report:
In addition to the source code, you will write a report that
contains an analysis of the runtime
complexity of the insert and remove methods for both
implementations. You will also perform timing
tests on your code, and provide empirical proof that your
methods perform in accordance with your
analysis. Provide a summary that highlights the strengths and
weaknesses of each implementation, and
recommend the implementation that you think would be best for
this application. We will discuss
methods for timing your structures in class.

Weitere ähnliche Inhalte

Ähnlich wie PQTimer.java A simple driver program to run timing t.docx

Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdffashiongallery1
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupDror Helper
 
Objective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdfObjective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdfezhilvizhiyan
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 KotlinVMware Tanzu
 
Ive posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfIve posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfdeepaarora22
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxalanfhall8953
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfarjuntelecom26
 
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdfpublic void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdfisenbergwarne4100
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docxmercysuttle
 
package algs13;import stdlib.;import java.util.Iterator;im.docx
package algs13;import  stdlib.;import java.util.Iterator;im.docxpackage algs13;import  stdlib.;import java.util.Iterator;im.docx
package algs13;import stdlib.;import java.util.Iterator;im.docxgerardkortney
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfsiennatimbok52331
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfanushkaent7
 
Below is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdfBelow is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdfaroraenterprisesmbd
 

Ähnlich wie PQTimer.java A simple driver program to run timing t.docx (20)

Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
 
Microkernel Development
Microkernel DevelopmentMicrokernel Development
Microkernel Development
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Objective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdfObjective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdf
 
3 j unit
3 j unit3 j unit
3 j unit
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
Ive posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfIve posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdf
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdfpublic void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
 
Thread
ThreadThread
Thread
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx
 
package algs13;import stdlib.;import java.util.Iterator;im.docx
package algs13;import  stdlib.;import java.util.Iterator;im.docxpackage algs13;import  stdlib.;import java.util.Iterator;im.docx
package algs13;import stdlib.;import java.util.Iterator;im.docx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
Below is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdfBelow is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdf
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 

Mehr von joyjonna282

In a 250-300 word response, critically examine your personal level o.docx
In a 250-300 word response, critically examine your personal level o.docxIn a 250-300 word response, critically examine your personal level o.docx
In a 250-300 word response, critically examine your personal level o.docxjoyjonna282
 
In a 10 –12 page paper, identify and analyze the benefits and challe.docx
In a 10 –12 page paper, identify and analyze the benefits and challe.docxIn a 10 –12 page paper, identify and analyze the benefits and challe.docx
In a 10 –12 page paper, identify and analyze the benefits and challe.docxjoyjonna282
 
In a 1-2 page Microsoft Word document, discuss the following case st.docx
In a 1-2 page Microsoft Word document, discuss the following case st.docxIn a 1-2 page Microsoft Word document, discuss the following case st.docx
In a 1-2 page Microsoft Word document, discuss the following case st.docxjoyjonna282
 
In a 16–20 slide PowerPoint presentation (excluding title and refere.docx
In a 16–20 slide PowerPoint presentation (excluding title and refere.docxIn a 16–20 slide PowerPoint presentation (excluding title and refere.docx
In a 16–20 slide PowerPoint presentation (excluding title and refere.docxjoyjonna282
 
In a 1-2 page Microsoft Word document, using APA, discuss the follow.docx
In a 1-2 page Microsoft Word document, using APA, discuss the follow.docxIn a 1-2 page Microsoft Word document, using APA, discuss the follow.docx
In a 1-2 page Microsoft Word document, using APA, discuss the follow.docxjoyjonna282
 
In a 1-2 page paper, discuss how the government, the media, and the .docx
In a 1-2 page paper, discuss how the government, the media, and the .docxIn a 1-2 page paper, discuss how the government, the media, and the .docx
In a 1-2 page paper, discuss how the government, the media, and the .docxjoyjonna282
 
In 2010, plans were announced for the construction of an Islamic cul.docx
In 2010, plans were announced for the construction of an Islamic cul.docxIn 2010, plans were announced for the construction of an Islamic cul.docx
In 2010, plans were announced for the construction of an Islamic cul.docxjoyjonna282
 
In 2011, John Jones, a middle school social science teacher began .docx
In 2011, John Jones, a middle school social science teacher began .docxIn 2011, John Jones, a middle school social science teacher began .docx
In 2011, John Jones, a middle school social science teacher began .docxjoyjonna282
 
In 5-7 pages (double-spaced,) provide a narrative explaining the org.docx
In 5-7 pages (double-spaced,) provide a narrative explaining the org.docxIn 5-7 pages (double-spaced,) provide a narrative explaining the org.docx
In 5-7 pages (double-spaced,) provide a narrative explaining the org.docxjoyjonna282
 
In 2004 the Bush Administration enacted changes to the FLSA and the .docx
In 2004 the Bush Administration enacted changes to the FLSA and the .docxIn 2004 the Bush Administration enacted changes to the FLSA and the .docx
In 2004 the Bush Administration enacted changes to the FLSA and the .docxjoyjonna282
 
In 200-250 wordsGiven the rate of technological chang.docx
In 200-250 wordsGiven the rate of technological chang.docxIn 200-250 wordsGiven the rate of technological chang.docx
In 200-250 wordsGiven the rate of technological chang.docxjoyjonna282
 
in 200 words or more..1  do you use twitter if so , how often do.docx
in 200 words or more..1  do you use twitter if so , how often do.docxin 200 words or more..1  do you use twitter if so , how often do.docx
in 200 words or more..1  do you use twitter if so , how often do.docxjoyjonna282
 
In 200 words or more, answer the following questionsAfter reading .docx
In 200 words or more, answer the following questionsAfter reading .docxIn 200 words or more, answer the following questionsAfter reading .docx
In 200 words or more, answer the following questionsAfter reading .docxjoyjonna282
 
In 2005, serial killer Dennis Rader, also known as BTK, was arrested.docx
In 2005, serial killer Dennis Rader, also known as BTK, was arrested.docxIn 2005, serial killer Dennis Rader, also known as BTK, was arrested.docx
In 2005, serial killer Dennis Rader, also known as BTK, was arrested.docxjoyjonna282
 
In 2003, China sent a person into space. China became just the third.docx
In 2003, China sent a person into space. China became just the third.docxIn 2003, China sent a person into space. China became just the third.docx
In 2003, China sent a person into space. China became just the third.docxjoyjonna282
 
In 250 words briefly describe the adverse effects caused by exposure.docx
In 250 words briefly describe the adverse effects caused by exposure.docxIn 250 words briefly describe the adverse effects caused by exposure.docx
In 250 words briefly describe the adverse effects caused by exposure.docxjoyjonna282
 
In 2.5 pages, compare and contrast health care reform in two differe.docx
In 2.5 pages, compare and contrast health care reform in two differe.docxIn 2.5 pages, compare and contrast health care reform in two differe.docx
In 2.5 pages, compare and contrast health care reform in two differe.docxjoyjonna282
 
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docx
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docxIn 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docx
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docxjoyjonna282
 
In 200-300 words  - How is predation different from parasitism What.docx
In 200-300 words  - How is predation different from parasitism What.docxIn 200-300 words  - How is predation different from parasitism What.docx
In 200-300 words  - How is predation different from parasitism What.docxjoyjonna282
 
In 3 and half pages, including a title page and a reference page, di.docx
In 3 and half pages, including a title page and a reference page, di.docxIn 3 and half pages, including a title page and a reference page, di.docx
In 3 and half pages, including a title page and a reference page, di.docxjoyjonna282
 

Mehr von joyjonna282 (20)

In a 250-300 word response, critically examine your personal level o.docx
In a 250-300 word response, critically examine your personal level o.docxIn a 250-300 word response, critically examine your personal level o.docx
In a 250-300 word response, critically examine your personal level o.docx
 
In a 10 –12 page paper, identify and analyze the benefits and challe.docx
In a 10 –12 page paper, identify and analyze the benefits and challe.docxIn a 10 –12 page paper, identify and analyze the benefits and challe.docx
In a 10 –12 page paper, identify and analyze the benefits and challe.docx
 
In a 1-2 page Microsoft Word document, discuss the following case st.docx
In a 1-2 page Microsoft Word document, discuss the following case st.docxIn a 1-2 page Microsoft Word document, discuss the following case st.docx
In a 1-2 page Microsoft Word document, discuss the following case st.docx
 
In a 16–20 slide PowerPoint presentation (excluding title and refere.docx
In a 16–20 slide PowerPoint presentation (excluding title and refere.docxIn a 16–20 slide PowerPoint presentation (excluding title and refere.docx
In a 16–20 slide PowerPoint presentation (excluding title and refere.docx
 
In a 1-2 page Microsoft Word document, using APA, discuss the follow.docx
In a 1-2 page Microsoft Word document, using APA, discuss the follow.docxIn a 1-2 page Microsoft Word document, using APA, discuss the follow.docx
In a 1-2 page Microsoft Word document, using APA, discuss the follow.docx
 
In a 1-2 page paper, discuss how the government, the media, and the .docx
In a 1-2 page paper, discuss how the government, the media, and the .docxIn a 1-2 page paper, discuss how the government, the media, and the .docx
In a 1-2 page paper, discuss how the government, the media, and the .docx
 
In 2010, plans were announced for the construction of an Islamic cul.docx
In 2010, plans were announced for the construction of an Islamic cul.docxIn 2010, plans were announced for the construction of an Islamic cul.docx
In 2010, plans were announced for the construction of an Islamic cul.docx
 
In 2011, John Jones, a middle school social science teacher began .docx
In 2011, John Jones, a middle school social science teacher began .docxIn 2011, John Jones, a middle school social science teacher began .docx
In 2011, John Jones, a middle school social science teacher began .docx
 
In 5-7 pages (double-spaced,) provide a narrative explaining the org.docx
In 5-7 pages (double-spaced,) provide a narrative explaining the org.docxIn 5-7 pages (double-spaced,) provide a narrative explaining the org.docx
In 5-7 pages (double-spaced,) provide a narrative explaining the org.docx
 
In 2004 the Bush Administration enacted changes to the FLSA and the .docx
In 2004 the Bush Administration enacted changes to the FLSA and the .docxIn 2004 the Bush Administration enacted changes to the FLSA and the .docx
In 2004 the Bush Administration enacted changes to the FLSA and the .docx
 
In 200-250 wordsGiven the rate of technological chang.docx
In 200-250 wordsGiven the rate of technological chang.docxIn 200-250 wordsGiven the rate of technological chang.docx
In 200-250 wordsGiven the rate of technological chang.docx
 
in 200 words or more..1  do you use twitter if so , how often do.docx
in 200 words or more..1  do you use twitter if so , how often do.docxin 200 words or more..1  do you use twitter if so , how often do.docx
in 200 words or more..1  do you use twitter if so , how often do.docx
 
In 200 words or more, answer the following questionsAfter reading .docx
In 200 words or more, answer the following questionsAfter reading .docxIn 200 words or more, answer the following questionsAfter reading .docx
In 200 words or more, answer the following questionsAfter reading .docx
 
In 2005, serial killer Dennis Rader, also known as BTK, was arrested.docx
In 2005, serial killer Dennis Rader, also known as BTK, was arrested.docxIn 2005, serial killer Dennis Rader, also known as BTK, was arrested.docx
In 2005, serial killer Dennis Rader, also known as BTK, was arrested.docx
 
In 2003, China sent a person into space. China became just the third.docx
In 2003, China sent a person into space. China became just the third.docxIn 2003, China sent a person into space. China became just the third.docx
In 2003, China sent a person into space. China became just the third.docx
 
In 250 words briefly describe the adverse effects caused by exposure.docx
In 250 words briefly describe the adverse effects caused by exposure.docxIn 250 words briefly describe the adverse effects caused by exposure.docx
In 250 words briefly describe the adverse effects caused by exposure.docx
 
In 2.5 pages, compare and contrast health care reform in two differe.docx
In 2.5 pages, compare and contrast health care reform in two differe.docxIn 2.5 pages, compare and contrast health care reform in two differe.docx
In 2.5 pages, compare and contrast health care reform in two differe.docx
 
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docx
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docxIn 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docx
In 2014 Virginia scientist Eric Betzig won a Nobel Prize for his res.docx
 
In 200-300 words  - How is predation different from parasitism What.docx
In 200-300 words  - How is predation different from parasitism What.docxIn 200-300 words  - How is predation different from parasitism What.docx
In 200-300 words  - How is predation different from parasitism What.docx
 
In 3 and half pages, including a title page and a reference page, di.docx
In 3 and half pages, including a title page and a reference page, di.docxIn 3 and half pages, including a title page and a reference page, di.docx
In 3 and half pages, including a title page and a reference page, di.docx
 

Kürzlich hochgeladen

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Kürzlich hochgeladen (20)

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

PQTimer.java A simple driver program to run timing t.docx

  • 1. /* PQTimer.java A simple driver program to run timing tests on your ArrayPQ and BinaryHeapPQ. Programming Assignment #2 */ import java.util.Iterator; import java.util.ConcurrentModificationException; import data_structures.*; public class PQTimer { public static void main(String [] args) { /////////////////////////////////////////////////////////// /// Change this variable to something smaller if timing takes too long. final int INITIAL_SIZE = 15000; /////////////////////////////////////////////////////////// final int ITERATIONS = 10000; final int NUMBER_OF_STEPS = 15; final int MAX_SIZE = INITIAL_SIZE * NUMBER_OF_STEPS +1; final int NUMBER_OF_PRIORITIES = 20; int size = INITIAL_SIZE; long sequence_number = 0; long start, stop; int priority; PQTestObject [] array = new PQTestObject[MAX_SIZE];
  • 2. for(int i=0; i < MAX_SIZE; i++) array[i] = new PQTestObject((int) ((10000*Math.random() % NUMBER_OF_PRIORITIES) +1), sequence_number++); for(int j=0; j < 15; j++) { PriorityQueue<PQTestObject> queue = new HeapPriorityQueue<PQTestObject>(MAX_SIZE); queue.clear(); for(int i = 0; i < size; i++) queue.insert(array[i]); start = System.currentTimeMillis(); // start the timer for(int i = 0; i < ITERATIONS; i++) { queue.insert(array[(int)(100000*Math.random() % MAX_SIZE)]); queue.remove(); } stop = System.currentTimeMillis(); System.out.println("HeapPQ, Time for n=" + size + ": " + (stop-start)); queue.clear(); queue = new ArrayPriorityQueue<PQTestObject>(MAX_SIZE); for(int i = 0; i < size; i++) queue.insert(array[i]); start = System.currentTimeMillis(); // start the timer for(int i = 0; i < ITERATIONS; i++) {
  • 3. queue.insert(array[(int)(100000*Math.random() % MAX_SIZE)]); queue.remove(); } stop = System.currentTimeMillis(); System.out.println("ArrayPQ, Time for n=" + size + ": " + (stop-start)+"n"); size += INITIAL_SIZE; } } } /* PQTestObject.java A simple testing object that has a priority. The sequence number in this class is NOT the insertion sequence number you will have in the BinaryHeapPQ class. It is only used for verification of correct behavior, and never used in ordering objects of this class. */ public class PQTestObject implements Comparable<PQTestObject> { private int priority; private long sequence_number; public PQTestObject(int p, long s) { priority = p; sequence_number = s; }
  • 4. public int compareTo(PQTestObject o) { return priority - o.priority; } public String toString() { return priority + " " + sequence_number; } } /* PQTester.java A simple driver program to test your ArrayPQ and BinaryHeapPQ. NOTE: Does not test all of the methods in your PQs. The fact that your program runs with this driver does not mean that it is error free. Requires PQTestObject class Alan Riggins CS310 Fall 2012 Programming Assignment #2 */ import java.util.Iterator; import java.util.ConcurrentModificationException; import data_structures.*; public class PQTester { public static void main(String [] args) { final int SIZE = 50; long sequence_number = 0; int priority;
  • 5. ////////////////////////////////////////////////////////////////////// /// Select the implementation you wish to test PriorityQueue<PQTestObject> queue = new ArrayPriorityQueue<PQTestObject>(SIZE); ////////////////////////////////////////////////////////////////////// System.out.println("Now testing the ARRRAY implementation"); PQTestObject [] array = new PQTestObject[SIZE]; for(int i=0; i < SIZE; i++) array[i] = new PQTestObject((int) ((1000*Math.random() % 20) +1), sequence_number++); for(int i=0; i < SIZE; i++) queue.insert(array[i]); // check to see what happens if insertion beyond capacity try { if(queue.insert(new PQTestObject(1,1))) throw new RuntimeException("ERROR, inserted beyond capacity"); } catch(Exception e) { e.printStackTrace(); } if(queue.size() != SIZE) System.out.println("ERROR, wrong size!"); System.out.println("Now printing with the iterator. " + "They should come out in any order.n" + "Priorty SequenceNumber"); Iterator<PQTestObject> iter = queue.iterator(); while(iter.hasNext()) System.out.print(iter.next()+ " ");
  • 6. System.out.println(); try { PQTestObject obj = iter.next(); } catch(Exception e) { System.out.println("Good, iterator passed."); } for(PQTestObject o : queue) ; System.out.println("================================ =============="); System.out.println("Now removing them all..."); for(int i=0; i < SIZE; i++) System.out.print(queue.remove()+ " "); System.out.println(); if(!queue.isEmpty()) System.out.println("ERROR, queue should be empty"); queue.clear(); System.out.println("================================ =============="); queue.insert(new PQTestObject(25,1)); queue.insert(new PQTestObject(25,2)); queue.insert(new PQTestObject(1,1)); queue.insert(new PQTestObject(1,2)); queue.insert(new PQTestObject(25,3)); System.out.println("Now emptying remaining elements"); while(!queue.isEmpty()) System.out.println(queue.remove());
  • 7. ////////////////////////////////////////////////////////////////////// queue = new HeapPriorityQueue<PQTestObject>(SIZE); ////////////////////////////////////////////////////////////////////// System.out.println("nnNow testing the HEAP implementation"); array = new PQTestObject[SIZE]; for(int i=0; i < SIZE; i++) array[i] = new PQTestObject((int) ((1000*Math.random() % 20) +1), sequence_number++); for(int i=0; i < SIZE; i++) queue.insert(array[i]); // check to see what happens if insertion beyond capacity try { if(queue.insert(new PQTestObject(1,1))) throw new RuntimeException("ERROR, inserted beyond capacity"); } catch(Exception e) { e.printStackTrace(); } if(queue.size() != SIZE) System.out.println("ERROR, wrong size!"); System.out.println("Now printing with the iterator. " + "They should come out in any order.n" + "Priorty SequenceNumber"); iter = queue.iterator();
  • 8. while(iter.hasNext()) System.out.print(iter.next()+ " "); System.out.println(); try { PQTestObject obj = iter.next(); } catch(Exception e) { System.out.println("Good, iterator passed."); } for(PQTestObject o : queue) ; System.out.println("================================ =============="); System.out.println("Now removing them all..."); for(int i=0; i < SIZE; i++) System.out.print(queue.remove()+ " "); System.out.println(); if(!queue.isEmpty()) System.out.println("ERROR, queue should be empty"); queue.clear(); System.out.println("================================ =============="); queue.insert(new PQTestObject(25,1)); queue.insert(new PQTestObject(25,2)); queue.insert(new PQTestObject(1,1)); queue.insert(new PQTestObject(1,2)); queue.insert(new PQTestObject(25,3)); System.out.println("Now emptying remaining elements"); while(!queue.isEmpty()) System.out.println(queue.remove()); }
  • 9. } The Program: For this assignment, you will write two implementations of a Priority Queue. For this ADT, removal operations always return the object in the queue of highest priority that has been in the queue the longest. That is, no object of a given priority is ever removed as long as the queue contains one or more objects of a higher priority. Within a given priority FIFO order must be preserved. Your two implementations will be: Both implementations must have identical behavior, and must implement the PriorityQueue interface (provided). Both implementations must have two constructors, a default constructor with no arguments that uses the DEFAULT_MAX_CAPACITY constant from the PriorityQueue.java interface, and a constructor that takes a single integer parameter that represents the maximum capacity of the PQ. The PriorityQueue interface follows: /* The PriorityQueue ADT may store objects in any order. However,
  • 10. removal of objects from the PQ must follow specific criteria. The object of highest priority that has been in the PQ longest must be the object returned by the remove() method. FIFO return order must be preserved for objects of identical priority. Ranking of objects by priority is determined by the Comparable interface. All objects inserted into the PQ must implement this interface. */ package data_structures; import java.util.Iterator; public interface PriorityQueue<E> extends Iterable<E> { static final int DEFAULT_MAX_CAPACITY = 1000; // Inserts a new object into the priority queue. Returns true
  • 11. if // the insertion is successful. If the PQ is full, the insertion // is aborted, and the method returns false. public boolean insert(E object); // Removes the object of highest priority that has been in the // PQ the longest, and returns it. Returns null if the PQ is empty. public E remove(); // Returns the object of highest priority that has been in the // PQ the longest, but does NOT remove it. // Returns null if the PQ is empty. public E peek(); // Returns the number of objects currently in the PQ. public int size(); // Returns an iterator of the objects in the PQ, in no particular // order. The iterator must be fail-fast.
  • 12. public Iterator<E> iterator(); // Returns an iterator of the objects in the PQ, in exactly the // same order in which they will be dequeued. The iterator must // be fail-fast. public Iterator<E> orderedIterator(); // Returns the PQ to an empty state. public void clear(); // Returns true if the PQ is empty, otherwise false public boolean isEmpty(); // Returns true if the PQ is full, otherwise false. List based // implementations should always return false. public boolean isFull(); } Thus, your project will consist of the following files. You must
  • 13. use exactly these filenames. The ordered array must use binary search to identify the correct insertion point for new additions. heap must be stable. Additional Details: les specified, no additional source code files are permitted. (Do not hand in a copy of PriorityQueue.java, as it is provided to you). interface provided. I will grade your project with my copy of this file. number at the beginning of the file. 'data_structures'. java.util.NoSuchElementException, and ConcurrentModificationException only. If you feel that you need to import anything else, let me know. You are expected to write all of the code yourself,
  • 14. and you may not use the Java API for any containers. nt anything. catch any exceptions. Your iterators should throw: o ConcurrentModificationException o NoSuchElementException o UnsupportedOperationException but must handle any/all error conditions gracefully. i.e. if the user attempts to call the clear() method on an empty PQ, or remove an item from an empty PQ, the program should not crash. provided. You may not add any public methods to the implementations, but you may add private ones, or inner classes if needed. compiled, but it must compile and run correctly on rohan using JDK1.6 to receive any credit. binary heap implementation. Sorting methods are available in the class lecture notes, and you are welcome to use the code (now and in the future). However, you should create a private method in the appropriate place rather
  • 15. than using any external class directly. You should select a O(n logn) method that is stable. The Report: In addition to the source code, you will write a report that contains an analysis of the runtime complexity of the insert and remove methods for both implementations. You will also perform timing tests on your code, and provide empirical proof that your methods perform in accordance with your analysis. Provide a summary that highlights the strengths and weaknesses of each implementation, and recommend the implementation that you think would be best for this application. We will discuss methods for timing your structures in class.