Machine-translated by Google. Questions are authored in English.
Top

Discussion

An algorithm is made up of 2 modules M1 and M2 . If time complexity of modules M1 and M2 are h(n) and g(n) respectively, the time complexity of the algorithm is

  • A.min (h(n), g(n))
  • B.max (h(n), g(n))
  • C.h(n) + g(n)
  • D.h(n) * g(n)

Answer: B

The time complexity is the maximum of h(n) and g(n). When an algorithm is made of two modules run one after the other, its running time is the sum h(n) + g(n), and for the order of growth the sum is dominated by the larger term, so it is of the order of max(h(n), g(n)). The minimum would ignore the slower module and the product would apply only if one module were run inside the other, so those are wrong.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.