Page 1 of 1

Instructions: Submit a single file with your answers via Canvas submission system. No other mean of submission (e.g., em

Posted: Sun Jul 10, 2022 11:23 am
by answerhappygod
Instructions Submit A Single File With Your Answers Via Canvas Submission System No Other Mean Of Submission E G Em 1
Instructions Submit A Single File With Your Answers Via Canvas Submission System No Other Mean Of Submission E G Em 1 (54.68 KiB) Viewed 43 times
Instructions Submit A Single File With Your Answers Via Canvas Submission System No Other Mean Of Submission E G Em 2
Instructions Submit A Single File With Your Answers Via Canvas Submission System No Other Mean Of Submission E G Em 2 (57.68 KiB) Viewed 43 times
Instructions: Submit a single file with your answers via Canvas submission system. No other mean of submission (e.g., email, printouts, etc.) is accepted. Acceptable formats include Word and pdf. If you need to use ELC's, mark that at the top of your submission. Exercise I For each of the following two code snippets (C++ or Python): a. Calculate the theoretical time complexity by counting the number of basic operations. Multiplications and division are considered here as basic operations. What do you think is the Big-Oh for the complexity? Prove how did you get the big-Oh only for Code Snippet 1. b. Implement the code in the language of your choice, and find the running time for several values of n (for instance, for n=1000, 2000, 3000....10000) and plot a graph of the results. (make sure not to have other applications running in the background. You can use different values for n as you see fit). Submit the full code as an appendix to your assignment. c. Use any tool, such as excel or MATLAB or ... (or by hand) to plot a graph of the theoretical time complexity. d. Using the two plotted graphs, comment on the growth rate of the theoretical time complexity in comparison with the actual (experimental) running times. Code Snippet 1. C++ result = 0; for (i } CH 111 < nz i++) { result - i result result result result result Part Snippet 2. result for ( result 0: for (i=1;i<nzi++) result 2 1 result result 1 < 2/11 result: case Python result - 0 for i in range(1, n+13: result result - i result 500) result - 17 result 2 / 321 result result result 2/1 result Python result - 0 for i in range (1, n): result result 21 for in zange (1, 1+11: result result 3 result result 2/3 Exercise II Consider the following pseudocode for a reduce-and-conquer recursive SumDigit (num) algorithm that finds the sum of all digits in a number. Example calling SumDigit (1936) should return 19 (which is 6+3+9+1) integer SumDigit (num) input: an integer number, num output: sum of all the digits in num if num is a one-digit number //base
Exercise II Consider the following pseudocode for a reduce-and-conquer recursive SumDigit (num) algorithm that finds the sum of all digits in a number. Example calling SumDigit (1936) should return 19 (which is 6+3+9+1) integer SumDigit (num) input: an integer number, num output: sum of all the digits in num if num is a one-digit number //base - then the sum of all the digits in num is, num // example if num-7, then SumDigit (num), should return 7 otherwise case // general case: num has multiple digits in it - break num into 2 parts - One part, part 1, has the rightmost digit (use modulo operation to do that). Ex. 1936 10 -> 6 - The other part, part 2, has all the digits of num, except the rightmost digit. (use regular division to do this. Ex. 1936/10 -> 193 - Call the function SumDigit() itself on part 2, and get the result of the sum of all the digits in part 2.. Add the result from SumDigit (part 2) to part 1, and return it a. Write the corresponding C++ or Python code for the pseudocode. Submit only the code for the function SumDigit() and not the whole program. b. Using the modulo operation "%", addition operation "+", and division operation "/" as basic operations, set up and solve a recurrence relation for the number of basic operations the algorithm executes. c. Modify the code to create a new recursive function CountDigits(num) that counts the number of digits in a number num. Example: a call to the function CountDigits(1587) would return the value 4. Submit only the code for the function CountDigits(num). d. Using the modulo operation "%", addition operation "+", and division operation "/" as basic operations, set up and solve a recurrence relation for the number of basic operations for CountDigits(num).