title: Given a word and a text, we need to return the occurrences of anagrams.. Is my approach correct?
body: <p>Basically Im trying to work out a solution to the problem <a href="https://stackoverflow.com/questions/18811511/given-a-word-and-a-text-we-need-to-return-the-occurrences-of-anagrams">Given a word and a text, we need to return the occurrences of anagrams</a> . However, I wasnt able to quite understand some of the solutions posted there. So, I tried to convert the problem into the problem of finding permutations of a given text.  Here's my algorithm (pseudocode), Id like some insight to see if its right and also some insight into finding its complexity.</p>
  
  <pre><code>int findAnagramOccurencesinText(String input,String find)
  
  //generate a list of all possible permutations of the letters in find and store in a list
  // eg/ if find ="dog"  then list =["god","odg","dog","gdo","ogd","dgo"]
  
  int occurances=0;
  for String (perm:list)
  {
       index=-1;
       while(index&lt;input.length)
        {
            index=input.indexOf(perm,index);
            if(index!=-1)
               occurances++;
            index+=1;
  
        }
  }
  return occurances;
  }
  </code></pre>
  
  <p>Also is the complexity O(#inputlength)? Any insight on how to find the complexity of this particular algorithm(if its correct) would be appreciated.</p>
  
  <p><strong>EDIT : I understand this is a O(n!) solution. Is there any modification I can make to it, to make it more efficient?</strong> (Other than scrapping the entire approach and moving to the O(n) approach mentioned in the linked question)</p>