1
我試圖執行並瞭解KdTree
,以下是我找到的鏈接。 http://ldots.org/kdtree/#buildingAkDTree 但我不明白下面的算法Kd-Tree問題
tuple function build_kd_tree(int depth, set points):
if points contains only one point:
return that point as a leaf.
if depth is even:
Calculate the median x-value.
Create a set of points (pointsLeft) that have x-values less than
the median.
Create a set of points (pointsRight) that have x-values greater
than or equal to the median.
else:
Calculate the median y-value.
Create a set of points (pointsLeft) that have y-values less than
the median.
Create a set of points (pointsRight) that have y-values greater
than or equal to the median.
treeLeft = build_kd_tree(depth + 1, pointsLeft)
treeRight = build_kd_tree(depth + 1, pointsRight)
return(median, treeLeft, treeRight)
我不明白什麼是 Calculate the median x-value.
算法遞歸時會發生什麼情況,是否應刪除插入的元素並取剩餘值的中值。 – Avinash 2011-06-06 12:22:40
@Avinash:顯然是的,因爲在遞歸調用中你正在處理一組不同的'points'。 – 2011-06-06 13:04:04
謝謝,還有一個疑問,這似乎是處理靜態數據點集,是否有不同的數據點算法,這些數據點在構建樹時是未知的。 – Avinash 2011-06-06 13:11:23