【发布时间】:2022-01-08 10:54:48
【问题描述】:
是否会是 O(26n),其中 26 是字母表中的字母数,n 是 trie 的级别数?例如,这是打印 trie 的代码:
public void print()
{
for(int i = 0; i < 26; i++)
{
if(this.next[i] != null)
{
this.next[i].print();
}
}
if(this.word != null)
{
System.out.println(this.word.getWord());
}
}
所以看这段代码让我觉得我对时间复杂度的近似值在最坏的情况下是正确的,即 26 个节点已满 n 级。
【问题讨论】:
-
数字 26 是一个常数,它不依赖于数据的大小,因此在 O 表示法中应该忽略它。
-
关于landau符号的备注:没有
O(26n)。因为26是一个常数,所以它应该是O(n)。
标签: java data-structures tree nodes trie