ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 24 May 2017 My Price 11.00

priority queue of integers

Hello. I would like to get my program explained to me. You wrote the program for me. I just do not understand it. I read the instruction and do not know what the professor wants. All I understood was that he wants me to write a program implementing priority queue. The second paragraph of the instructions is what really confuses me. Help. Maybe some comments. I normally like to understand the program and add or change stuff to it before I turn it in to no get in trouble.

Write your own implementation of a priority queue of integers: a priority queue maintains its elements sorted. The operations that you need to provide are inserting an integer, removing an integer, checking if a given integer is already contained in the queue. Duplicate elements are permitted. Do not use any of the predefined collections from the Java libraries.

 

Provide a test program that inserts random values into two priority queues (one instance of your implementation, and one instance of the java.util.PriorityQueue<Integer>). Measure the runtime performance for 10000, 20000, ... up to 100000 insertions.

 

Deliverables are your class implementation and your test program, and a document describing your design and your results (no more than 2 pages).

 

 

 

 

/** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/import java.util.PriorityQueue;import java.util.Random;public class

MyPriorityQueue {int arr[];int capacity;int count;public MyPriorityQueue(int capacity) {this.capacity = capacity;this.arr=new int[capacity];count=0;}//this method will insert a new integer into queuepublic void insert(int n){if(count==capacity){System.out.println("Queue is full");}else{arr[count]=Integer.MIN_VALUE;increaseKey(count,n);count++;}}void increaseKey(int i,int n){arr[i]=n;while(i>=0&&arr[i/2]<arr[i]){int temp=arr[i/2];arr[i/2]=arr[i];arr[i]=temp;i=i/2;}}void maxHeapify(int i){int left = 2 * i + 1;int right = 2 * i + 2;int largest = i;if( left < capacity && arr[ left ] > arr[ largest ] )largest = left;if( right < capacity && arr[ right ] > arr[ largest ] )largest = right;if( largest != i ){int temp = arr[ i ];arr[ i ] = arr[ largest ];arr[ largest ] = temp;

import java.util.PriorityQueue;import java.util.Random;public class Test {public static void main(String[] args) {System.out.println("Number of insertMyPriorityQueueJava PriorityQueue");for(int i=1;i<=10;i++){int n=10000*i;MyPriorityQueue p=newMyPriorityQueue(n);PriorityQueue<Integer> javaP=new PriorityQueue<Integer>(n);Random r=new Random();long start=System.nanoTime();for(int j=0;j<n;j++){int num=r.nextInt();javaP.add(num);}long stop=System.nanoTime();long javaQueueTime=stop-start;start=System.nanoTime();for(int j=0;j<n;j++){int num=r.nextInt();p.insert(num);}stop=System.nanoTime();long myQueueTime=stop-start;System.out.printf("%-11d%20d%15d\n",n,myQueueTime,javaQueueTime);}}}

Answers

(11)
Status NEW Posted 24 May 2017 03:05 AM My Price 11.00

-----------

Attachments

file 1495596133-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)