Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This was a question that I got wrong on our test. I put that the big O was O(n^6

ID: 3597537 • Letter: T

Question

This was a question that I got wrong on our test. I put that the big O was O(n^6). Could you please walk me through this?

Consider the following code that I wrote in my youth. The problem was to sort data by date and time.

for (y = 1970; y <= 1977; y++)

for(m = 1; m <= 12; m++)

      for( d = 1; d <= 12; d++

for{ h = 1; h <= 24; h++)

              for(min = 1; min <= 60; min++)

         for( s = 1; s<= 60; s ++)

                  if (r. year == y && rmonth == m && r.day == d && r.hour = h && r.min = min && r.s = s )

                                  copy record r to tape

When I showed this to my supervisor at the time he remained unimpressed.

So, what would be the big Oh value for this code?

Explanation / Answer

The time complexity would be approximately (n^6*time taken to copy record r) if the copy takes time as a function of n also it will also change the time complexity.

Hope this clears your doubt.

Please do give a thumbs up to the answer.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote