Reputation: 648
I need to implement a grid of pixels triples of type (x_coord, y_coord, color)
, using some number of AVL-trees.
Particularly, I should be able to execute this functions:
nextInRow(x,y)
nextInCol(x,y)
readColor(x,y)
with complexity O(log n).
I am completely lost and have no idea how to do it efficiently. Any help or pointer will be appreciated.
Upvotes: 1
Views: 234
Reputation: 648
One smart way to implement this using AVL-trees is to have two separate AVL-trees, one that is sorted by x-coordinate and the other that is sorted by y-coordinate. So you will use the first one to implement nextInRow(x,y)
and the second one for nextInCol(x,y)
.
Mind that you should sync your changes for one tree with another tree.
Upvotes: 1