Hi i am trying to calculate the complexity of the following algorithm
private static List<int> GetIndexes(string strippedText, string searchText)
{
List<int> count = new List<int>();
int index = 0;
while (strippedText.Length >= index && index != -1)
{
index = strippedText.IndexOf(searchText.Trim(), index,
StringComparison.OrdinalIgnoreCase);
if (index != -1)
{
count.Add(index);
index++;
}
else continue;
}
return count;
}
I know that the loop has a complexity of O(n)
if count increments by 1 on each iteration but, the increments depends from the indexes found. on each iteration it could increment 1 or strippedText.lenght()
.
Any idea?
Thanks