【发布时间】:2010-09-19 03:35:35
【问题描述】:
鉴于此算法,我想知道是否存在迭代版本。另外,我想知道迭代版本是否可以更快。
这是某种伪python...
算法返回对树根的引用
make_tree(array a)
if len(a) == 0
return None;
node = pick a random point from the array
calculate distances of the point against the others
calculate median of such distances
node.left = make_tree(subset of the array, such that the distance of points is lower to the median of distances)
node.right = make_tree(subset, such the distance is greater or equal to the median)
return node
【问题讨论】:
标签: recursion iteration binary-tree non-recursive