Professional Documents
Culture Documents
(Heaps)
________________________________________
Clarifications:
2. REMOVEMAX should also print the details of the athlete removed. There
was an error in test cases. This has been corrected.
________________________________________
This assignment is designed to get you comfortable with heaps and tree
traversals.
The commonwealth games is round the corner and you would like to develop
some simple software which will help you keep track of statistics about
Athletic events. We would like to keep a database of athletes and their scores
in various athletic events. Assume that there is some standardized scoring
mechanism for different athletic events so that we can compare the
performance of athletes across different events (e.g., if A gets a score 7 in
event E1 and B gets a score 8 in event E2, then B has better performance
than A). For each individual sports event, we would like to have quick access
to the details of best sportsperson in that event. We would also like to have
quick access to the details of the best sportsperson across all the athletic
events. For this we maintain a heap of heaps which is explained next.
Heap of Heaps:
For each individual athletic event like 100m, 200m etc., we maintain a max
heap where the key is the standardized score and the value is the details
about the athlete. We maintain another max heap where each node
corresponds to an athletic event. For each node, the key is the best score of
an athlete in that event and the value is the max heap for that event. We
would like to perform the following operations on our data structure.
1. removeMaxFromEvent(event_id): Remove and return the athlete with
the best score in the event denoted by event_id. The athlete should be
removed only from the heap corresponding to this event. The athlete remains
in the heap corresponding to all other events he participates in.
2. removeMax(): Remove and return the athlete with the best score
across all events. Suppose this athlete’s best performance is in event E, then
this athlete should be removed from the heap corresponding to event E and
not from any other event heaps.
Note that when you add an athlete into an event heap you also have to
update the top-level heap (the heap of event heaps). The same is true for all
the other operations.
Following are the main classes you should write. Figure out if you need to
write any other classes or methods.
class Athlete{
String Name;
String Country;
int Age;
double height;
double weight;
int NumEvents;
String EventID[] ;
int score[];
}
Class myHeap{
...
insert(){...}
RemoveMax();
Class HeapsOfHeaps{
...
RemoveMaxFromEvent(){...}
RemoveMax(){...}
InsertAthlete(){...}
PrintHeap(){...}
Any inconsistency in the input file should be detected and reported. Your
program should print ERROR IN INPUT FILE and abort.
INSERT Asafa Powell, Jamaica, 23, 1.90, 93, 3, 100M, 200M, 400M, 8, 7, 6
REMOVEMAX HIGHJUMP
REMOVEMAX HIGHJUMP
REMOVEMAX
PRINTHEAP
PRINTHEAP
For each athlete, you are given the name, country, age, height (in meters),
weight (in kgs), the number of events he participates in, the event ids and
the standardized score on these events respectively.
Construct all the event heaps and the heap of event heaps top-down, i.e.,
insert an element into the heap as soon as you see the element in the input
file. For example, for the following first input line:
You should insert this athlete in the 100M, 200M, and 400M heaps and then
insert these heaps (in that order into the top level heap).
You should write a program named Simulate.java. The input file is given on
the command line, i.e., you will run
For the above input file, your program should print the following:
Ivan Sergeyevich Ukhov, Russia, 24, 1.92, 83, 1, HIGHJUMP, 10
CSL201