kd tree prototype algo