Coder Social home page Coder Social logo

rbtreeeventcounter's Introduction

ADSProject1

Implemented 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, the program builds 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.

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 countof theID after the addition O(log n)
Reduce(theID, m) Decrease the count of theID by m. If theID’scount 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.