# 查找操作（Searching）

%% range query的函数
function findAll = rangeQuery(obj,id,rect)
% obj是一个k-d tree的对象，id是从某个id开始查起，用于实现递归，rect是待查区间
left = obj.nodeCell{id}.leftID;
right = obj.nodeCell{id}.rightID;
findLeft = [];
findRight = [];

if (isempty(left)==0) && (interRegion(obj.nodeCell{left}.region,rect,obj.dimen)==1)
% 左非空，且左有子集，向左搜索
findLeft = rangeQuery(obj,left,rect);
end

if (isempty(right)==0) && (interRegion(obj.nodeCell{right}.region,rect,obj.dimen)==1)
% 右非空，且右有子集，向右搜索
findRight = rangeQuery(obj,right,rect);
end

if interPoint(rect,obj.nodeCell{id}.point,obj.dimen)==1
% 当前点在range内
findAll = [id,findLeft,findRight];
else
findAll = [findLeft,findRight];
end

end

# 优化操作（Optimize）

Ref.
[Ben75] Bentley, J. L. (1975). Multidimensional binary search trees used for associative searching. Communications of the ACM, 18(9), 509-517.
[FBF77] Friedman, J. H., Bentley, J. L., & Finkel, R. A. (1977). An algorithm for finding best matches in logarithmic expected time. ACM Transactions on Mathematical Software (TOMS), 3(3), 209-226.
[LW77] Lee, D. T., & Wong, C. K. (1977). Worst-case analysis for region and partial region searches in multidimensional binary search trees and balanced quad trees. Acta Informatica, 9(1), 23-29.
[Rob81] Robinson, J. T. (1981, April). The KDB-tree: a search structure for large multidimensional dynamic indexes. In Proceedings of the 1981 ACM SIGMOD international conference on Management of data (pp. 10-18). ACM.

#### K-D tree

2014-11-19 10:12:10

#### 关于B-K tree与k-d tree一些自己想法

2015-05-10 19:19:41

#### 最近邻算法实现K-d tree

2017年09月01日 7KB 下载

#### k近邻算法（KNN）及kd树简介（KD-Tree）

2016-04-24 17:40:19

#### bzoj 4066: 简单题 k-d tree

2016-04-14 19:25:44

#### k-d Tree及其Java实现

2016-07-15 17:36:05

#### K-d树详解

2013-11-13 21:33:41

#### k-d tree算法例子

2016-02-06 18:09:47

#### k-d树+bbf算法的介绍与实现

2016-09-14 10:38:24

#### k-d树与特征匹配

2017-02-28 13:49:06

k-d tree 介绍