subject

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: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 20:30
How is energy expended in active transport
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
Suppose a router has built up the routing table shown in the table. subnet number 128.96.39.00 28.96.39.128 128.96.40.00 192.4.153.0 default) subnet mask 255.255.255.128 255.255.255.128 255.255.255.128 255.255.255.192 nexthop interface 0 interface 1 r2 r3 r4. the router can deliver packets directly over interfaces 0 and 1, or it can forward packets to routers r2, r3, or r4. describe what the router does with a packet addressed to each of the following destinations: (a) 128.96.39.10 (b) 128.96.40.12 (c) 128.96.40.151 (d) 192.4.153.17 (e) 192.4.153.90
Answers: 3
question
Computers and Technology, 25.06.2019 07:20
Acompany's intranet is set up on this type of server. application communication print web
Answers: 1
question
Computers and Technology, 25.06.2019 08:00
In researching his history report about the civil war, why is ariq most likely to use secondary data than primary data? secondary data provides a starting point to find primary data. secondary data is easier and less time consuming to find. secondary data is always more reliable and credible. secondary data eliminates the need for other research.
Answers: 1
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, 02.11.2020 20:10
question
Mathematics, 02.11.2020 20:10
question
Mathematics, 02.11.2020 20:10
question
Mathematics, 02.11.2020 20:10
question
Mathematics, 02.11.2020 20:10
question
Computers and Technology, 02.11.2020 20:10
Questions on the website: 13722363