# To find perfect matches, We need to traverse complete list of words....

Part1:

To find perfect matches, We need to traverse complete list of words.  And We need to matched particular words with each words present in list. To achieve this, We need two inner loop, One loop will match each characters of matched word with words present in list. When all characters are matched then we will add particular words into list.

Time complexity of algorithm will depend on number of words present in list and length of word. Let suppose if list has n words and length of word is  m. then we complexity of algorithm will be:

T(n) = n*m*m

=  O(n*m*m)

=  O(n)    where m will be constant and will be small number.

So, Complexity of below algorithm will be O(n).

for (String w : wordList) {

if (w.length() == word.length()) {

int count = 0;

int i;

char[] wArrray= w.toCharArray();

for ( i = 0; i < w.length(); i++) {

for (int j = 0; j < word.length(); j++) {

if (word.charAt(i) == wArrray[j]) {

count++;

wArrray[j]=' ';

break;

}

}

}

if (count == w.length()) {