-
Consider these two functions and two statements S1 and S2 about them.
S1 : The transformation form work1 to work2 is valid, i.e., for any program state and input arguments, work2 will compute the same output and have the same effect on program state as work 1.
S2 : All the transformations applied to work1 to get work2 will always improve the performance (i.e., reduce CPU time) of work2 compared to work1
-
- S1 is false and S2 is false
- S1 is false and S2 is true
- S1 is true and S2 is false
- S1 is true and S2 is true
- S1 is false and S2 is false
Correct Option: D
Both functions work1 & work 2 performs the same task, therefore S1 is true.
In S2 it is asking about improvement in performance i.e. reduction in CPU time. When compared work2 will reduce the CPU time, because in work1 a[i+2] is computed twice but in work2 a[i+2] is computed once and stored in t2, and then t2 is used. When we consider the performance in terms of reduction in CPU time, S2 is correct.