tmac_balla
tmac_balla

Reputation: 648

Implement a pixel grid using AVL-trees

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:

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

Answers (1)

tmac_balla
tmac_balla

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

Related Questions