Assuming I have a large set of Coordinates such us (3,4), (5,-6), etc., where x and y are integers; is it possible to order them using a BST?
How can I go about determining what should be on the left vs right node?
The reason why I’m looking at BST instead of simply using a list of coordinates is so that I can more efficiently (vs linear search) determine those coordinates that would be in the Moore neighborhood (Chebyshev distance 1) of another.
I’ve thought about alternating comparisons to x and y values; is that a good approach?
How else can I apply BST to this situation? Or is using BST untenable?
Despite the simplicity of the approach by aioobe to create a grid of cells (two dimensional array), it was a bit heavy handed/inefficient to store the state of all possible cells/coordinates especially when I may have cases where there is only have a handful of actual coordinates in a very large space (sparse array).
Ultimately I realised using a BST is feasible (there are other approaches) and this is what I did to find Moore Neighbours efficiently using a balanced BST:
Then to search for the Moore Neighbours of a coordinate, I can then just look up/search for the 8 possible neighbour coordinates in the tree (as aioobe suggests) in O(log n).