# 查找操作（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 介绍 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)