我必须增加树木的分量(理想)。 我正在努力确定最低的O(n)技术是什么。
我的数据如下:
Id ParentId Value
0 null Bob
1 0 Amy
2 1 Susan
3 1 Matt
4 2 Keith
5 4 Craig
6 4 Derrick
因此,树木希望:
All I can come up with is an n^2 algorithm which for every entry scans every other entry to see if they belong as a sub node. I also am removing entries from the array to scan as they are being added. So it s a little less than n^2 if memory serves (probably not).
是否有更好的技术?