Big O Efficiency for Multiple Variables

I am trying to evaluate the effectiveness of a function where the input is an array of strings. The algorithm always iterates through each element of this array. These strings contained in this array are of variable length. In this initial loop, the character invocation function is called for each line. I believe that the replacement function itself will be O (n), where n is the length of the string.

So, I am confused how to evaluate the great efficiency here. If n is the size of the array, I know that it will be at least O (n). But with variable string lengths, how would you rate overall efficiency when replacing a string? Would you say that n is the size of the array and the use of other variables to represent the different sizes of each row?

+5
source share
2 answers

I see two ways to say this (out of many possible).

Firstly, this O(N)is where Nis the total number of characters.

Another thing you could say is O(N*M)where Nis the number of lines and Mis the average number of characters per line. Please note that this is actually the same as my answer above. You could say M = k/N, so you get O(N*k/N)or O(k), where k are common characters in all lines.

+7
source

( ). , t , O(t). t .

+9

All Articles