Big-O of while loop with nested-if

牧云@^-^@ 提交于 2019-12-11 12:56:54

问题


I have this algorithm, and I am trying to calculate its complexity.

A = {{B_1}, {B_2}, {B_3}, ..., {B_n}}
t_n = 0   //for every set in A
while A != empty
   Calculate f(t_n) for each element in A using t_n. 
   n' = argmin(A)  //n' is the element (set) in A with smallest f(t_n)
   t_n' = t_n' + 1
   if (t_n' == Constant)
       B_n' = B_n' - {k}     //k is an element in B_n'
       if(B_n' == empty)
           A = A - {B_n'}

A is a set, and if the condition (t_n' == Constant) and if(B_n' == empty) are true, we remove an element (set) from the set A until A is empty. Assume calculating f(t_n) takes a constant time.

If every element (set) in A has the same size, can we say that the complexity is O(|A|*|B_n|)? How about if elements (sets) in A have different sizes?

来源:https://stackoverflow.com/questions/54375304/big-o-of-while-loop-with-nested-if

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!