Note: This assignment is worth 9% of the course grade. It is due in class on April 12, since sketches of the solutions will be handed out on that day. Algorithm analysis and development in the wild (outside of textbooks).
int strcmp(char* p, char* q){ while(*p != 0 && *q != 0 && *p == *q) ++p, ++q; if (*p < *q) return -1; else if (*p == *q) return 0; // they are both 0 - eos. else return 1; }Simply put, the number of character comparisons used by by strcmp is about a 3 times (constant multiple of) the number of initial matching characters in the two strings. The number of character comparisons used by comlen is about 2 times the number of initial matching characters in the two strings (which is also the value returned).
Comment (not meant to affect your homework): I think the while loop in comlen would be faster and still correct if written as
while (*p == *q && *p) p++, q++, i++;
On the due date, implementations must be submitted by email. They will be run on some test cases. If they pass an initial correctness screening they will be candidates for timed runs in class. This way we will see whose modifications have had the most success in speedup.