Question

In: Computer Science

Would the following function work correctly if statically allocated activation records are used for implementation? Explain...

Would the following function work correctly if statically allocated activation records are used for implementation? Explain why it would work or not.

                   fun fact x = if x <= 0 then 1 else x * fact(x - 1);

Solutions

Expert Solution

Answer:-

No, the following function will not work if statically allocated activation records are used for implementation because the problem is that each recursive call needs to remember the value of its argument and return address, i.e., we need two storage locations for each active call to fact(). for example, while executing fact(4), we need to call fact(3), fact(2), fact(1)  and finally get to call fact(0) there are five nested active calls, so we’ll need 5*2 = 10 storage locations. In fact, the amount of storage needed varies with the depth of the recursion that is how many recursions we are doing. That's why we can’t use statically allocated activation record to hold all the values we need to save during this execution

.

so, we can’t statically allocate a single block of storage for this function as recursive calls means that we’ll have many active calls to that procedure at points during the execution.


Related Solutions

Limit your answers to one paragraph or less. 1. Explain the difference between a statically allocated...
Limit your answers to one paragraph or less. 1. Explain the difference between a statically allocated array, a dynamically allocated array, and a linked list. 2. Linked lists have terrible performance for random access or searching of internal entries. Why? 3. Explain the advantages of adding a tail pointer to a linked list, and of doubly-linked over singlylinked lists.
Which of the following is a challenge in the implementation of electronic health records? A. lack...
Which of the following is a challenge in the implementation of electronic health records? A. lack of standardization B. employee resistance C. multiple end-user needs D. all of the above
Explain why the implementation of the electronic health records (EHR) brings value to quality and patient...
Explain why the implementation of the electronic health records (EHR) brings value to quality and patient safety.
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order: An array of integer values (array1). An integer representing the size of array1 (size1). An array of integer values (array2). An integer representing the size of array2 (size). The function creates a dynamic array of integers of size size1+size2 to store all the values in array1, followed by all the values in array2. The function returns the pointer used to create the dynamic...
What tools are used currently to justify innovation projects? Is the finance function responsible for implementation...
What tools are used currently to justify innovation projects? Is the finance function responsible for implementation of these tools?
21. Which of the following mechanisms is used by cells to insure that proteins are correctly...
21. Which of the following mechanisms is used by cells to insure that proteins are correctly localized to specific organelles, integrated into the plasma membrane or secreted? a. Proteins become glycosylated in the rough ER and Golgi and only proteins with sugar modifications are transported to their correct sub cellular location. b. Proteins encode a sequence that acts as a signal, such as a nuclear localization signal (NLS), to target them appropriately. c. Any protein being synthesized is immediately inserted...
Why are debit cards called debit cards? Is the accounting term used correctly? What would the...
Why are debit cards called debit cards? Is the accounting term used correctly? What would the accounting entry be to record an ATM withdrawal on the bank’s books? What would the accounting entry be on your books if you use your company debit to purchase office supplies? Does it make sense?
One of the steps in the System Development Life Cycle is Implementation. (a)Explain what work has...
One of the steps in the System Development Life Cycle is Implementation. (a)Explain what work has already been completed before the start of Implementation. (b)Describe what work is done during Implementation and explain why it is important. (c) Explain why more time spent during earlier software development phases (e.g. analysis and design) can contribute to reducing overall software development costs. Provide an illustrating example to support your arguments.
1) Which one of the following would most likely be allocated to products using ABC by...
1) Which one of the following would most likely be allocated to products using ABC by McDonald's? A) Cost of plastic gloves worn by the burger cooks B) Cost of employees who chop lettuce C) Cost of tomatoes added to burgers D) Cost of cups for soft drinks 2) Fixed costs..... A) increase per unit as total production decreases B) increase in total as total production increases C) decrease in total as total production decreases D) decrease per unit as...
Using a flow chart diagram EXPLAIN in detail the various proformas used for preparation and implementation...
Using a flow chart diagram EXPLAIN in detail the various proformas used for preparation and implementation of development schemes. All the proformas should be in proper sequence and with sufficient details showing purpose and requirements of each proforma. The flow chart diagram can be drawn on a paper or any computer tool can be utilized for this purpose. The diagram should be sufficiently detailed and shouldn't be a copy of already available figures.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT