Question

Definition 1: Point $(x,y)$ is controlling point $(x',y')$ if and only if $x < x'$ and $y < y'$.

Definition 2: Point $(x,y)$ is controlled by point $(x',y')$ if and only if $x' < x $ and $ y' < y$.

I'm trying to come up with data structure to support the following operations:

  • $\mathrm{Add}(x,y)$ - Adds a point $(x,y)$ to the system in $\mathcal{O}(\log n)$ complexity where $n$ is the number of points in the system.

  • $\mathrm{Remove}(x,y)$ - Removes a point $(x,y)$ from the system in $\mathcal{O}(\log n)$ complexity where $n$ is the number of points in the system.

  • $\mathrm{Score}(x,y)$ - Returns the number of points $(x,y)$ controls - number of points that $(x,y)$ is controlled by. Worst case complexity $\mathcal{O}(\log n)$ .


I've tried to solve it using multiple AVL trees, but could not come up with elegant enough solution.

This question appeared on my exams few days ago. The question should have relatively straightforward as it was worth $15/100$ points. I tried to solve this by several AVL trees but couldn't come up with elegant enough solution.

Hints are welcome.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top