A program consists of an O(n) loop followed by another O(n) loop. What is the Big O of the program?

  • A: O(n) + O(n)
  • B: 2 O(n)
  • C: O(2 n)
  • D: O(n)
  • E: O(n2)

    Answer: D

    If there is a section of sequential code:

    {   s1;

    the Big O is the max of the Big O of the statements.

    Constants are not included in Big O, which means answers A, B, C should be reduced to O(n).

    Next    Page+10    Index