I have this code,
void Generate(List<string> comb, string prefix, string remaining)
{
int currentDigit = Int32.Parse(remaining.Substring(0, 1));
if (remaining.Length == 1)
{
for (int i = 0; i < dictionary[currentDigit].Length; i++)
{
comb.Add(prefix + dictionary[currentDigit][i]);
}
}
else
{
for (int i = 0; i < dictionary[currentDigit].Length; i++)
{
Generate(comb, prefix + dictionary[currentDigit][i], remaining.Substring(1));
}
}
}
What is the time complexity of the above code?
Is it Generate is O(n) and that itself is being executed n times so O(n^2)?
dictionary is len = 10 and has phone keypads stored it in. 2 = "abc" etc.
The initial call to this code will be like
Generate(new List(), "", "12345");
Thanks.
dictionary[currentDigit], not posted.n? is remaining initial size? I guess your dictionary size is 10 at most.