Computers and Technology
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?

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:00, QueenKy9576
Wich technology can a website use to allow you to listen to a concert live over the internet?
Answers: 3
image
Computers and Technology, 23.06.2019 01:00, lusciousl
Petrică, tânăr licean în clasa a ix-a, a primit în dar de la părinţii săi un cont bancar pentru micile sale cheltuieli curente. el este pasionat de internet banking şi îşi verifică cu grijă toate tranzacţiile efectuate. pentru creşterea securităţii tranzacţiilor online, banca îi furnizează lui petrică un număr pe care el va trebui să îl modifice, obţinând un număr tan – număr de autentificare a tranzacţiei (transaction authentication number). regula de obţinere a numărului tan este următoarea: se formează cel mai mic număr par din toate cifrele numărului furnizat de bancă. cerinţă cunoscând numărul n furnizat de bancă, să se determine numărul tan obţinut de petrică. date de intrare fişierul tan. in conţine pe prima linie numărul natural n cu semnificaţia din enunţ. date de ieşire fişierul de ieşire tan. out va conţine o singură linie pe care va fi scris numărul tan cerut. restricţii • 0 < n < 18*1018 • n are cel puţin o cifră pară • numărul tan obţinut nu poate conţine zerouri nesemnificative
Answers: 2
image
Computers and Technology, 23.06.2019 11:30, leapfroggiez
Auser is given read permission to a file stored on an ntfs-formatted volume. the file is then copied to a folder on the same ntfs-formatted volume where the user has been given full control permission for that folder. when the user logs on to the computer holding the file and accesses its new location via a drive letter, what is the user's effective permission to the file? a. read b. full control c. no access d. modify e. none of the above
Answers: 1
image
Computers and Technology, 23.06.2019 21:20, nicki76
In microsoft word, when you highlight existing text you want to replace, you're in              a.  advanced mode.    b.  automatic mode.    c.  basic mode.    d.  typeover mode
Answers: 1
Do you know the correct answer?
Question 1: You are given 2 implementations for a recursive algorithm that calculates the sum of all...

Questions in other subjects: