Q1. Implement in Java the greedy algorithm for giving change with minimum number of coins: while (more coin-sizes && change

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Q1. Implement in Java the greedy algorithm for giving change with minimum number of coins:
while (more coin-sizes && change<amount owed)
choose the largest remaining coin-size
if (adding the coin does not make the change exceed the amount owed)
then add coin to change
else delete coin-size
Design specifications:
Represent the coin denominations in a heap ADT using the PriorityQueue or the PriorityBlockingQueue class. Make
the heap independent of the application by using class IntegerCompare, implementing Comparator.
Represent the change in a set ADT using the HashMap or the TreeMap class.
• You should enter the coin denominations (any denominations, not only the "normal" denominations) and the
amount owed. The program should display the change.
Q2. Find an instance (the amount owed and the available set of coin sizes) for which your program cannot give the
change, even when this is theoretically possible.
Q3. Analyze your algorithm (worst case only). Don't forget that you are using a heap and a map (it is a good idea to
review execution times for these data structures).
Q4. Could we use other data structures instead of heap and map to improve our implementation? Give ideas and use
arguments (asymptotic time, easy to implement, etc).
Submit the source code for Q1 and the answers to Q2-Q4.
Transcribed Image Text:Q1. Implement in Java the greedy algorithm for giving change with minimum number of coins: while (more coin-sizes && change<amount owed) choose the largest remaining coin-size if (adding the coin does not make the change exceed the amount owed) then add coin to change else delete coin-size Design specifications: Represent the coin denominations in a heap ADT using the PriorityQueue or the PriorityBlockingQueue class. Make the heap independent of the application by using class IntegerCompare, implementing Comparator. Represent the change in a set ADT using the HashMap or the TreeMap class. • You should enter the coin denominations (any denominations, not only the "normal" denominations) and the amount owed. The program should display the change. Q2. Find an instance (the amount owed and the available set of coin sizes) for which your program cannot give the change, even when this is theoretically possible. Q3. Analyze your algorithm (worst case only). Don't forget that you are using a heap and a map (it is a good idea to review execution times for these data structures). Q4. Could we use other data structures instead of heap and map to improve our implementation? Give ideas and use arguments (asymptotic time, easy to implement, etc). Submit the source code for Q1 and the answers to Q2-Q4.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Linear Programming Concepts
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education