Question: So far we assumed that parameter passing during procedure calls takes constant time, even if an N-element array or sequence is being passed. This assumption


So far we assumed that parameter passing during procedure calls takes constant time, even if an N-element array or sequence is being passed. This assumption is usually valid as most systems pass a pointer to the array not the array itself, which is called call by reference. However, some settings, problems, or systems, may require call by value semantics. Let's consider the 3 following ways to pass array to a function in the code considered thus far: (a) Call by reference: a pointer is passed. Time =(1). (b) Call by value: copying the entire array. Time =(N), where N is the number of elements in the array. (c) Call by a partial value: arrays are passed by copying only the subrange that might be accessed by the called procedure. Time =(n) if the subarray contains n elements. Consider the following 2 algorithms we have already worked with in Homework 1 and in the lectures: def binary_search(sequence, start, end, key): if end &= start: return False middle = (end + start) //2 if sequence[middle] == key: return True elif sequence[middle] > key: return binack_search(sequence, start, middle 1, key) 7 else: return binacx seserch { sequence, middle +1, end, key) (b) Merge sort Give 6 recurrences for the worst-case running times of each of the two algorithms above when arrays are passed using each of the three parameterpassing strategies above. Solve your recurrences giving tight asymptotic bounds
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
