Thursday, 15 January 2015

Algorithm complexity -


I am trying to calculate the complexity of the following algorithms

  Private static list & Lt; Int & gt; GetIndexes (string stripped text, string search text) {list & lt; Int & gt; Count = new list & lt; Int & gt; (); Int index = 0; While (strippedText.Length & gt; = Index & amp; amp; Index! = -1) {index = strippedText.IndexOf (searchText.Trim (), Index, String Compiler, Ordinal Ignor Sees); If (index! = -1) {count.Add (index); Index ++; } And continue; } Calculation of return; }  

I know that there is a complexity of O (n) in the loop, if every move has increased by 1, but the wage increases with the index is. On each walk it is 1 or strippedText.lenght () .

Anyone can raise thoughts?

However, the worst position is O (N).


No comments:

Post a Comment