我正在阅读由Mark Allen Weiss编写的关于数据结构和算法中树的章节。以下是文本片段。
Let D(n) be the internal path length for some tree T of n nodes. D(1) = 0. An n-node tree consists of an i-node left subtree and an (n - i - 1)-node right subtree, plus a root at depth zero for 0<= i < n. D(i) is the internal path length of the left subtree with respect to its root. In the main tree, all these nodes are one level deeper. The same holds for the right subtree. Thus, we get the recurrence D(n) = D(i) + D(n - i -1) + n -1
如果所有子树大小都是等可能的,这对于二叉搜索树是正确的(因为子树大小仅取决于插入到树中的第一个元素的相对排名),但不适用于二叉树,则D(i)和D(n-i-1)的平均值为(1/n)从j=0到n-1的D(j)之和。这产生了下面的公式。 D(n) = (2/n)(从j=0到n-1的D(j)之和)+ (n-1)。 以上关系获得D(n)的平均值为O(nlogn)。
以下是我对上述文本片段的问题。
1.作者的意思是“由于子树大小只取决于插入到树中的第一个元素的相对排名”,这是什么意思?
2.作者如何从D(n)得到平均值O(nlogn)? 有人能展示一下实现所述结果涉及的步骤吗?
谢谢!
Let D(n) be the internal path length for some tree T of n nodes. D(1) = 0. An n-node tree consists of an i-node left subtree and an (n - i - 1)-node right subtree, plus a root at depth zero for 0<= i < n. D(i) is the internal path length of the left subtree with respect to its root. In the main tree, all these nodes are one level deeper. The same holds for the right subtree. Thus, we get the recurrence D(n) = D(i) + D(n - i -1) + n -1
如果所有子树大小都是等可能的,这对于二叉搜索树是正确的(因为子树大小仅取决于插入到树中的第一个元素的相对排名),但不适用于二叉树,则D(i)和D(n-i-1)的平均值为(1/n)从j=0到n-1的D(j)之和。这产生了下面的公式。 D(n) = (2/n)(从j=0到n-1的D(j)之和)+ (n-1)。 以上关系获得D(n)的平均值为O(nlogn)。
以下是我对上述文本片段的问题。
1.作者的意思是“由于子树大小只取决于插入到树中的第一个元素的相对排名”,这是什么意思?
2.作者如何从D(n)得到平均值O(nlogn)? 有人能展示一下实现所述结果涉及的步骤吗?
谢谢!