简体   繁体   中英

Nested for loop complexity when number of elements differ

Say I had a set containing n entries, and a set containing m entries, and the following nested for loop structure:

for 1 to n

  for 1 to n

    for 1 to m

What would the time complexity be? I want to say O(mn^2) but can this be simplified anymore so we just have a single variable?

Thanks.

Given your case,the answer seems obvious that the complexity would be O(mn^2)...

But,as you mentioned that n and m represent number of vertices and edges respectively,then also, there doesn't exist any direct relationship between no. of edges no. of edges and no. of vertices no. of vertices for a general graph.

So,then also,the complexity would be O(mn^2)...

如果n是图形中的顶点数,并且m是该图形中的边数,则m为O( n ^ 2),因此您的算法将为O( n ^ 4)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM