(Solved) : Read Code Odd Assume Numberlist Contains Entries 0 1 2 3 4 Duplicates Allowed Answer Quest Q42787159 . . .

Read over the code for has odd. Assume that number_list contains entries from {0, 1,2,3,4}, with duplicates allowed. Answer t

Read over the code for has odd. Assume that number_list contains entries from {0, 1,2,3,4}, with duplicates allowed. Answer the questions below, assuming that n = len(number list) i def has_odd(number_list) -> bool: for i in range (len (number_list)): if number_list[i] % 2 == 1: return True return false (a) [3 marks] Find a good upper bound, U(n), for W Chas_odd(n). Prove that your upper bound is correct. (b) [3 marks] Find a lower bound, L(n), for W Chas_odd(n) that is in the same asymptotic complexity class as U(n) (that’s what I mean by “good” in the previous part). Prove that your lower bound is correct, then state and justify a simple big-Theta complexity class for W Chas.odd(n) (c) [3 marks) If has odd returns True after examining k entries in number_list, count this as k steps. If an has_odd examines all n entries in number_list and proceeds to return False count this as n + 1 steps. Using these assumptions, show how to calculate the average number of steps for all inputs to has odd of length 2. (d) [3 marks] Use the step-counting assumptions in the previous part to devise a formula for the average number of steps for all inputs to has_odd of length n. You may find it useful to recall (where r is some positive real number) non rpnt1 i=n- 1 = -1+ (n − 1)2 Show your work. Show transcribed image text Read over the code for has odd. Assume that number_list contains entries from {0, 1,2,3,4}, with duplicates allowed. Answer the questions below, assuming that n = len(number list) i def has_odd(number_list) -> bool: for i in range (len (number_list)): if number_list[i] % 2 == 1: return True return false (a) [3 marks] Find a good upper bound, U(n), for W Chas_odd(n). Prove that your upper bound is correct. (b) [3 marks] Find a lower bound, L(n), for W Chas_odd(n) that is in the same asymptotic complexity class as U(n) (that’s what I mean by “good” in the previous part). Prove that your lower bound is correct, then state and justify a simple big-Theta complexity class for W Chas.odd(n) (c) [3 marks) If has odd returns True after examining k entries in number_list, count this as k steps. If an has_odd examines all n entries in number_list and proceeds to return False count this as n + 1 steps. Using these assumptions, show how to calculate the average number of steps for all inputs to has odd of length 2. (d) [3 marks] Use the step-counting assumptions in the previous part to devise a formula for the average number of steps for all inputs to has_odd of length n. You may find it useful to recall (where r is some positive real number) non rpnt1 i=n- 1 = -1+ (n − 1)2 Show your work.

Expert Answer


Answer to Read over the code for has odd. Assume that number_list contains entries from {0, 1,2,3,4}, with duplicates allowed. Ans…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us