Programming and data structure miscellaneous
- Consider the following segment of C-code
int j, n;
j = 1;
while (j < = n)
j = j*2;
The number of comparisons made in the execution of the loop for any n > 0 is
-
View Hint View Answer Discuss in Forum
From the statement j = j*2 in the code we get to know that j increases in power of 2’s. Let us say that this statement execute x times then, according to the question for while loop
2^x < = n
Therefore, x < = log2 n
And also for termination of while loop there will be an extra comparison required. Thus, total number of comparisons = x + 1Correct Option: D
From the statement j = j*2 in the code we get to know that j increases in power of 2’s. Let us say that this statement execute x times then, according to the question for while loop
2^x < = n
Therefore, x < = log2 n
And also for termination of while loop there will be an extra comparison required. Thus, total number of comparisons = x + 1
- Which of the following are true ?
1. A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursive can be implemented with static storage allocation
2. Multi-level access link (or display) arrangement is needed to arrange activation records only, if the programming language being implemented has nesting of procedures/functions.
3. Recursion in programming languages cannot be implemented with dynamic storage allocation
4. Nesting of procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records.
5. Programming languages which permit a function to
return a function as its result cannot be implemented with a stack based storage allocation scheme for activation records
-
View Hint View Answer Discuss in Forum
1. Statement is false since global variables are required for recursions with static storage. This is due to unavailability of stack in static storage.
2. This is true
3. In dynamic allocation heap structure is used, so it is false.
4. False since recursion can be implemented. 5. Statement is completely true. So only 2 & 5 are true. Hence (a) is correct option.Correct Option: A
1. Statement is false since global variables are required for recursions with static storage. This is due to unavailability of stack in static storage.
2. This is true
3. In dynamic allocation heap structure is used, so it is false.
4. False since recursion can be implemented. 5. Statement is completely true. So only 2 & 5 are true. Hence (a) is correct option.