# Red-black tree Project solution

\$24.99

Original Work ?

## Description

5/5 - (1 vote)

1. Problem description
You are to implement an event counter using red-black tree. Each event has two
fields: ID and count, where count is the number of active events with the given ID.
The event counter stores only those ID’s whose count is 0. Once a count drops
below 1, that ID is removed. Initially, your program must build red-black tree from
a sorted list of n events (i.e., n pairs (ID, count) in ascending order of ID) in O(n)
time. Your counter should support the following operations in the specified time
complexity.
Command Desctiption Time complexity
Increase(theID, m) Increase the count of the event theID by m. If
theID is not present, insert it. Print the count
O(log n)
Reduce(theID, m) Decrease the count of theID by m. If theID’s
count becomes less than or equal to 0, remove
theID from the counter. Print the count of
theID after the deletion, or 0 if theID is
removed or not present.
O(log n)
Count(theID) Print the count of theID. If not present, print
0.
O(log n)
InRange(ID1, ID2) Print the total count for IDs between ID1 and
ID2 inclusively. Note, ID1 ≤ ID2
O(log n + s) where
s is the number of
IDs in the range.
Next(theID) Print the ID and the count of the event with
the lowest ID that is greater that theID. Print
“0 0”, if there is no next ID.
O(log n)
Previous(theID) Print the ID and the count of the event with
the greatest key that is less that theID. Print
“0 0”, if there is no previous ID.
O(log n)

2. Input/Output Requirements
You may implement this assignment in Java or C++. Your program must be
compilable and runable on the Thunder CISE server using gcc/g++ or standard
JDK. You may access the server using Telnet or SSH client on thunder.cise.ufl.edu.
You must write a makefile document which creates an executable. The names of