这里是该函数的每个部分中的最坏的情况下:优化这个小功能,这将在运行C的倍数量庞大
- 的
while
循环运行53402倍时size
等于9 - 这意味着
find_square()
每个呼叫调用find_square()
本身53402次,直到row == size
,在此情况下是9
所以呼叫到find_square()
总数为因此(53,402)^ 10 = 188 quattuordecillion。
这甚至不是最终功能的全部,但如果它已经很慢了,我想先解决它。显然这是一个可笑的数量的电话,但我真的不能看到它的方式。我愿意接受任何想法,这里的任何帮助都会很棒,谢谢!
void find_square(char*** hashed_dict, char*** grouped_dict, char** square, int size, int row) {
if (row == size) {
return;
}
int i = 0;
while (grouped_dict[size - 1][i] != NULL) {
fill_row(square, row, size, grouped_dict[size - 1][i]);
find_square(hashed_dict, grouped_dict, square, size, row + 1);
i++;
}
}
void fill_row(char** square, int row, int size, char* word) {
for (int i = 0; i < size; i++) {
square[row][i] = word[i];
}
}
没有足够的上下文。谈论性能和手动优化,没有考虑到特定的系统,并不是真正有意义的。 – Lundin
你想要什么样的环境? – numberjak
您是否考虑过“动态编程”方法? – babon