subject
Computers and Technology, 27.03.2020 01:51 guko

Question 1: You are given 2 implementations for a recursive algorithm that calculates the sum of all the elements in a list (of integers): def sum_lst1(lst): if (len(lst) == 1): return lst[0] else: rest = sum_lst1(lst[1:]) sum = lst[0] + rest return sum def sum_lst2(lst, low, high): if (low == high): return lst[low] else: rest = sum_lst2(lst, low + 1, high) sum = lst[low] + rest return sum Note: The implementations differ in the parameters we pass to these functions: • In the first version we pass only the list (all the elements in the list have to be taken in to account for the result). • In the second version, in addition to the list, we pass two indices: low and high (low ≤ high), which indicate the range of indices of the elements that should to be considered. The initial values (for the first call) passed to low and high would represent the range of the entire list. 1) Make sure you understand the recursive idea of each implementation. 2) Analyze the running time of the implementations above. For each version: i) Draw the recursion tree that represents the execution process of the function, and the local-cost of each call. ii) Conclude the total (asymptotic) running time of the function. 3) Which version is asymptotically faster?

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 00:00
Which is the correct sequence of steps to set up a document in landscape orientation? a. select page setup from the file menu. then click the margins tab and select landscape. b. select page setup from the edit menu. then click the margins tab and select landscape. c. select page setup from the insert menu. then click the margins tab and select landscape. d. select page setup from the format menu. then click the margins tab and select landscape
Answers: 1
question
Computers and Technology, 23.06.2019 04:20
Which network media uses different regions of the electromagnetic spectrum to transmit signals through air? uses different regions of the electromagnetic spectrum to transmit signals through air.
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Which of the following tasks is an audio technician most likely to perform while working on a nature documentary? (select all that apply). eliminating potentially distracting background noise adding sound effects making sure the lighting is adequate for a particular scene changing the narration to better match the mood of the documentary
Answers: 3
question
Computers and Technology, 23.06.2019 20:50
3.11.3 quiz: comparing and analyzing function typesquestion 4 of 102 pointswhat can you say about the y-values of the two functions f(x) = 3x2-3 andg(x)=2* - 3?
Answers: 2
You know the right answer?
Question 1: You are given 2 implementations for a recursive algorithm that calculates the sum of all...
Questions
question
Mathematics, 08.10.2021 22:30
question
Mathematics, 08.10.2021 22:30
question
Biology, 08.10.2021 22:30
question
History, 08.10.2021 22:30
question
Mathematics, 08.10.2021 22:30
question
Mathematics, 08.10.2021 22:30
question
Mathematics, 08.10.2021 22:30
question
Mathematics, 08.10.2021 22:30
Questions on the website: 13722360