Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 points) 12 points) Run each er laptop. DO NOT Use and ints) Run each piece of code below and record the actual time le

image text in transcribed
image text in transcribed
image text in transcribed
3 points) 12 points) Run each er laptop. DO NOT Use and ints) Run each piece of code below and record the actual time le seconds) it takes. Use a desktop DO NOT use an online complier. Pay attention and draw your own conclusions) to the following You do NOT need to write down your condusians 1 runtime print has the same code as runtime increment except that instruction 'res - res+1' was replaced with 'printinstruction Notice how this affects the time the code takes to run. 2. After you record the time for runtimeIncrement pay attention to how the performance gets worse as Ngets larger. 3. After you record the time for runtime powrote how much faster the performance deteriorates et takes too long to run even for small values of Nuch as 201 Comoure that with the other 2 functions (compare both the actual time, and the time complexity In the table below the code fill in the time complexity las and the approximate "clock time each function takes to run. You do NOT need to show your derivations for computing. You also do not need to report the exact time. You can say: " #include #include void runtime_rec (int n, char str) it ( 0) //printf(" ", str); return; str(N-1) - 'L': runtime_rec (N-1, str); str(N-1] - 'R'; runtime_rec (N-1, str); int main(int argc, char** argv)! int N = 0; char ch; char str(100); printf("run for: N scanf("id", &N); "); strIN - '\0'; //to use it as a string of length N. printf("runtime_rec (d) ", N); runtime_rec (N, str); (11 points) The program implements an add function for a flexible array that grows needed as discussed in class. It has 2 ways to compute the new site (double or 1 and 2 way to reallocate memory and copy using realloc or malloc and manual copy with loool. That produce variations in the implementation. You can choose which version you run, based on what you give a Input for the 2 parameters. (It will become clear when you look at the code and run it, it will numbers from the user.) Compare program performance for all 4 implementations for different values on N. In particular, powers of 10 for N . 1000, 10000 100000). For each value of Nun it with all combination of parameters for resizing and reallocation: (1 1). 10).10 1). 10 j. a) 4 points) Find the first value of N for which is very low, 11). [1 and for very fast. For example, on my machine I got that for N = 10 Value of N Parameter used for resire Parameter used for real location Time it takes to type (1 or 0, where: type (1 or where: Uses csec, few seconds 1 -> double 1 => realloc few minutes, more than 0 15 O malloc and user copy 15 minutes b) On my machine, for N 10 the program took about a second or less with combinations (1 1). (10) ( 01), but it took more than 20 minutes (I did not wait for it to finish) with (00). Running with (11) uses the most efficient implementation (doubles the size and uses realloc) Running with (10) doubles the stre and so the time complexity should be DIN) and so should still be fast. Running with (01) does not double the size. This should have DIN) but it runs in a few seconds while 100) took more than 20 minutes. That implies a difference of order of magnitude between them, but they should both be ON"). (7 points) How do you explain this behavior that the theoretical analysis does not match the actual behavior)? Hint: check the statistics about realloc that the program prints at the end of its run. Give a brief and clear answer in your answer underline the 3 most meaningful/relevant words. Out of the points, 3 will be for the clarity quality of the

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions