Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

What are some tell-tales in code that has a time complexity of \( O(n^a) , \ \ \ a \geq 2\)? For example, nested for loops that go like for i = 1 to n, for j = 1 to n are definitely \( O(n^2) \) but what about chaining C's default strcat function that goes like (assuming s is big enough): while (*s) s++; // Look for the NUL character in the source string, and point there. while (*s++ = *t++) // Append the target string to the source string.

OpenStudy (anonymous):

forgot a semicolon :-P the strcat implementation up there seems to have a linear running time, but if you chain it up like below: strcat(dnastring, moredna); strcat(dnastring, evenmoredna); . . etc... you end up moving through the entire original dnastring over again like reverse selection sort!

OpenStudy (shadowfiend):

Yep. In these cases it's best to use strncat or somesuch that specifies the lengths that you'll be working with. It's actually safer to do this anyway. Unless you know the implementation details, it's hard to tell. Most library functions like that often tell you their running time in their documentation. Other times, you don't find out until you get hosed :/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!