1. (4pt) Review Questions a. (2pt)Implement char *CopyString (char *s); that cop
ID: 3717660 • Letter: 1
Question
1. (4pt) Review Questions a. (2pt)Implement char *CopyString (char *s); that copiesthe strings into a dynamically allocated storage and returns the address of the new string. Suppose string.h is included, so you can use the standard string functions if needed. char *CopyString (char *S) b. (2pt) In the following loops, first count the number of operations (i.e., find how many lines will be printed out) when N is 32. Then give the computational complexity using big-O notation for any value of N Number of lines printed big-O notation when N-32 int i, j, N-32: for any N for (1-2; ¡Explanation / Answer
a)
char *CopyString(char *s) {
int len = strlen(s);
char *copy = (char *)malloc(len*sizeof(char));
strcpy(copy, s);
return copy;
}
b)
First FOR loop:
it will executes for i = 2, 4, 8, 16, 35
means 5 times
Big-O = O(logN)
Second FOR loop:
Outer for loop executes 5 times i = 2, 4, 8, 16, 35
for each i, inner FOR loop executes: N times
So, total number of operation: 5*32 = 160
Big-O = O(NlogN)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.