Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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
    1. S1 is false and S2 is false
    2. S1 is false and S2 is true
    3. S1 is true and S2 is false
    4. S1 is true and S2 is true
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.



Your comments will be displayed only after manual approval.