private KDTreeNode buildTree(List<Pair> data, final int split){
		if(data == null || data.size() == 0)
			return null;
		Comparator<Pair> comparator = new Comparator<Pair>(){
			public int compare(Pair o1, Pair o2) {
				double v1 = o1.data_vector[split];
				double v2 = o2.data_vector[split];
				return v1<=v2?-1:1;
			}
		};
		Collections.sort(data, comparator);
		int middle = data.size()/2;
		KDTreeNode root = new KDTreeNode(data.get(middle).data_vector, split);
		List<Pair> left_data = new ArrayList<Pair>();
		List<Pair> right_data = new ArrayList<Pair>();
		for(int i=0;i<middle;i++)
			left_data.add(data.get(i));
		for(int i=middle+1;i<data.size();i++)
			right_data.add(data.get(i));
		root.left = buildTree(left_data, (split+1)%N);
		root.right = buildTree(right_data, (split+1)%N);
		return root;
	}