implementation of 2d tree