/// <summary>
        /// NFA building functions, build a NFA to find all words within given levenshtein distance from given word.
        /// </summary>
        /// <param name="str">The input word</param>
        /// <param name="maxDist">The max levenshtein distance from input word</param>
        /// <returns></returns>
        public static LenvstnNFA BuildNFA(String str, int maxDist)
        {
            int width  = str.Length + 1;
            int height = maxDist + 1;
            int size   = width * height;

            Set <state> final = new Set <state>();

            for (int i = 1; i <= height; ++i)
            {
                final.Add(i * width - 1);
            }
            LenvstnNFA nfa = new LenvstnNFA(size, 0, final);

            //Every state except those in right most coulmn in the matrix
            for (int e = 0; e < height; ++e)
            {
                for (int i = 0; i < width - 1; ++i)
                {
                    //trans to right
                    nfa.AddTrans(e * width + i, e * width + i + 1, str[i]);
                    if (e < (height - 1))
                    {
                        //trans to upper
                        nfa.AddTrans(e * width + i, (e + 1) * width + i, (char)Constants.Any);
                        //trans to diagonal upper
                        nfa.AddTrans(e * width + i, (e + 1) * width + i + 1, (char)Constants.EpsilonAny);
                    }
                }
            }

            //right most column
            for (int k = 1; k < height; ++k)
            {
                //trans to upper
                nfa.AddTrans(k * width - 1, (k + 1) * width - 1, (char)Constants.Any);
            }
            return(nfa);
        }