如何计算函数的搜索复杂度
how to work out the search complexity of a function
我有以下两个函数,我正在尝试比较时间复杂度 我的第一个函数是一个简单的 for 循环:
For (i=0;i<m;i++)
// do stuff
时间复杂度:
i=0 执行一次
i
i++ 执行 n 次
=2n+2 = 0(N(
我正在努力计算第二个函数的时间复杂度:
void search(string word)
{
Index index;
if (tree.AVL_Retrieve(word, index)) {
for (auto i : index.idList)
{
for (int j=0;j<m;j++)
{
//do stuff
}
}
}
}
我相信在 AVL 树中检索是 O(logN(,我的循环是 O(N(,然后我的内部循环是 O(M(,但作为一个整体,我将如何编写该搜索函数的时间复杂度。
注意:我们可以假设我的AVL树中有N个键
第一个 for 循环运行(m-1)
次,因此具有时间复杂度 O(m(。
第二个函数运行一次AVL_Retrieve
函数,并且针对 index.idList 的每个循环计数运行一次,给出复杂性O(log (number of nodes in tree))+O((count of index.idList)*m)
相关文章:
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 如何在动态数组上使用搜索函数
- C++二叉搜索树模板从函数返回节点
- 在对象数组中搜索字符串并返回相应值的函数
- 基于函数而不是集合的二分搜索或迭代器?
- 如何使用 binary_search STL 函数在嵌套类中搜索整数?
- 查找存储在二叉搜索树的所有非叶子中的数据总和?(返回整数的独立递归函数
- 二叉搜索树 - 实现"search"函数
- 如何计算函数的搜索复杂度
- 返回二叉搜索树特定级别的节点数的函数
- 为什么二叉搜索函数会抛出错误?
- 超过了三次函数根平分搜索时间限制
- 二进制搜索树没有匹配的函数调用
- 函数来搜索目录中的文件名
- 在C++目录中搜索文件的函数输出中出错
- 这是在传递 int num 时创建搜索函数的正确方法吗?使用链表库
- 如何在C ++代码中搜索所有构造函数?
- 尝试在别人的代码中C++创建函数(A* 搜索)
- 如何使用C++中的strrchr库函数搜索正斜杠
- 在函数搜索模式中引用二维数组时出错