CPU scheduling such as SJF (shortest job first) is based on the precise predicti
ID: 3573447 • Letter: C
Question
CPU scheduling such as SJF (shortest job first) is based on the precise prediction of CPU burst times. One of the algorithm is exponential averaging. Check out the following implementation and answer to questions
float square(float n){
return n*n;
}
float eval_error(float *pred, float *actual, int size){
float err = 0;
int i;
for (i=0;i<size;i++){
// add each error value
err += square(pred[i] - actual[i]);
}
return err/size;
}
int main() {
float predicted_burst[]={10,10,10,10};
float actual_burst[]={20, 8, 7};
float alpha = 0.8;
int num_burst = 3;
int i;
for(i=0; i<num_burst; i++){
predicted_burst[i+1] = alpha * actual_burst[i] + (1-alpha) * predicted_burst[i];
printf("predicted_burst[%d] = %f ", i+1, predicted_burst[i+1]); // Line P
}
printf("error = %f ", eval_error(predicted_burst, actual_burst, num_burst)); // Line X
}
(a) What output will be displayed to the screen by Line P? Exact output is required.
(b) What output will be displayed to the screen by Line X? Exact output is required.
Explanation / Answer
a)
//The output displayed by Line P
output:
predicted_burst[1] = 18.000000
predicted_burst[2] = 10.000000
predicted_burst[3] = 7.600000
b)
//the output displayed by Line X
ouput:-
error = 69.666664