Skip to content
Advertisement

What will the time complexity of this python program in Big O notation?

I find it difficult to calculate the time complexity of this program as it involves a lot of built-in methods. Could anyone please help? Basically the question is to find topper of each subject and 3 overall best performers!

JavaScript

Input csv file looks something like this:

JavaScript

Output:

JavaScript

Advertisement

Answer

  1. Your for loop goes over all columns for each row => O(row * col) complexity.

  2. Calculation of totals does the same => O(row * col)

  3. The sort_values sorts all values in one column, and usually, sort functions are O(nLog(n)) in theory, so this gives us O(row * Log(row))

All in all, we have O(row * col) + O(row * col) + O(row * log(row) => O(row * col)

So the answer is O(row * col)

Edit

If col << row, you might actually get O(rowlog(row)). So if the number of columns is finite, it is actually O(rowlog(row))

Advertisement