As I noted in my comment, I think the comparison should be ```dimCurrMax >= median```, because if the elements can have equal coordinates, also the right sub-tree can have elements with the coordinate equal to ```dimCurrMax```.