Can the performance of this sequential search algorithm (taken from The Practice of Programming) be improved using any of C’s native utilities, e.g. if I set the i variable to be a register variable ?
int lookup(char *word, char*array[]) { int i for (i = 0; array[i] != NULL; i++) if (strcmp(word, array[i]) == 0) return i; return -1; }
Yes, but only very slightly. A much bigger performance improvement can be achieved by using better algorithms (for example keeping the list sorted and doing a binary search).
In general optimizing a given algorithm only gets you so far. Choosing a better algorithm (even if it’s not completely optimized) can give you a considerable (order of magnitude) performance improvement.