Provide a Java class named sorted PriorityQueue that implements a priority queue using a Java array...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Provide a Java class named sorted PriorityQueue that implements a priority queue using a Java array of type int. The constructor of the class should be passed the size of the queue. Each time the add method is called, the value passed to it should be inserted into the array to ensure that the array remains in sorted order. If the array is full when add is called, a RuntimeException should be thrown. If the array is empty when remove is called, a RuntimeException should also be thrown Make the implementation as efficient as possible. Consider the following sorting algorithm that uses the class you wrote in the previous problem: void sort (int[] array) { SortedPriorityQueue queue = new SortedPriorityQueue (100); for (int i = 0; i < array.length; i++) queue.add (array[i]); for (int i = 0; i < array.length; i++) array[i] = queue.remove(); } Analyze its execution time efficiency in the worst case. In your analysis you may ignore the possibility that the array may overflow. Indicate whether this implementation is more or less efficient than the one that uses the Java priority queue. Provide a Java class named sorted PriorityQueue that implements a priority queue using a Java array of type int. The constructor of the class should be passed the size of the queue. Each time the add method is called, the value passed to it should be inserted into the array to ensure that the array remains in sorted order. If the array is full when add is called, a RuntimeException should be thrown. If the array is empty when remove is called, a RuntimeException should also be thrown Make the implementation as efficient as possible. Consider the following sorting algorithm that uses the class you wrote in the previous problem: void sort (int[] array) { SortedPriorityQueue queue = new SortedPriorityQueue (100); for (int i = 0; i < array.length; i++) queue.add (array[i]); for (int i = 0; i < array.length; i++) array[i] = queue.remove(); } Analyze its execution time efficiency in the worst case. In your analysis you may ignore the possibility that the array may overflow. Indicate whether this implementation is more or less efficient than the one that uses the Java priority queue.
Expert Answer:
Answer rating: 100% (QA)
Selfdriving cars navigation system simulation Initial coordinates of the car currentx 50 currenty 50 ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Write out the first three terms in the expansion (x + y) 12 .
-
When two plane mirrors are parallel, such as on opposite walls in a barber shop, multiple images arise because each image in one mirror serves as an object for the other mirror. A point object is...
-
In 2010, 4.9 million barrels of oil spilled into the Gulf of Mexico due to an explosion on an oil rig. Describe both the negative and positive impact this disaster had on GDP. Explain how this...
-
In 2001, the City of New York and the Dormitory Authority of the State of New York (DASNY) entered into an agreement to build a forensic biology laboratory in Manhattan. Per the agreement, DASNY...
-
Arial Company maintains a petty cash fund for small expenditures. The following transactions occurred over a 2-month period. July 1 Established petty cash fund by writing a check on Coulter Bank for...
-
Make a Relational Model Table and Define Keys from Entity Relation Diagram Q2: Design the World Music Association Database using given ERD. ORCHESTRA "Orchestra Name City Country Music Director...
-
Gordon Temper is a single taxpayer (birthdate July 1, 1985, and Social Security number 242-11-6767) who operates a food truck that specializes in food from South Africa. His business is named "Mobile...
-
4:33 PM Fri Mar 4 Use linearization of f(x) = to estimate X 1 7.99513 0 + 1/3 5 L(8-1000) c) Use tangent line to find estimate of 7.99513 = 94% a) what is the slope of tangent line of f(x) = 1 when...
-
Question 1 (Bayes' rule) You have four coins in the bag: Coin 1 (C1) is a fair coin that comes up heads with probability 0.5 Coin 2 (C2) is a biased coin that comes up heads with probability 0.2...
-
Covey suggests that effective people learn to put first things first. This implies that: Group of answer choices Work-related activities always come first Personal time is of least importance...
-
For a certain multi-state lottery the prize was $12,200,000 that was paid out over 20 years with each year payments of $610,000.00 paid at the end of each year. If money is worth 6.4%, compounded...
-
Valerie, a food service worker in a college dining hall, decides that the college should offer flu shots to students and staff. She organizes her peers'support for the project, which is then carried...
-
Short-hour workers are usually scheduled to work Group of answer choices between 20 and 40 hours per week. less than 20 hours per week. whenever they are needed; hours are not specified. less than 40...
-
The heights (in inches) of 30 adult mates are listed below. A frequency distribution shows the frequency and relative frequency using five classes. 70 72 71 70 69 73 69 68 70 71 67 71 70 74 69 68 71...
-
Which of the companies has the lowest accounts receivable turnover in the year 20X2? a. Company A. b. Company B. c. Company C. d. CompanyD. 20X1 20X2 Credit Sales Average Receivables Balance $1.0...
-
Write a program that prompts the user to enter the year and first day of the year and displays the calendar table for the year on the console. For example, if the user entered the year 2013, and 2...
-
The Hilbert curve, first described by German mathematician David Hilbert in 1891, is a space-filling curve that visits every point in a square grid with a size of 2 * 2, 4 * 4, 8 * 8, 16 * 16, or any...
-
An n ? n matrix is called a positive Markov matrix if each element is positive and the sum of the elements in each column is 1. Write the following method to check whether a matrix is a Markov...
-
Flaherty Ltd sells two types of shoes, mens shoes and womens shoes. During the financial year ended 30 June 2019, fixed costs were $460 800 and sales were in the ratio of three units (pairs) of mens...
-
Newbery and Newstead is a public accounting firm specialising in auditing local medium-sized businesses. Fees charged for each audit are determined on the basis of identifiable hours worked on an...
-
Hotbox Ltd produces pizza boxes using two processes cutting and packaging. The production budget for the year ending 30 June 2019 estimated raw materials use of $400 000, factory overhead of $270...
Study smarter with the SolutionInn App