THINK FIRST·CODE LATER

← All labs

Choosing the time slice: efficiency vs. response time

Problem

Help the EdgeCampus operations team choose a time slice for an interactive server.

Input: first line n s maxWait — the number of processes taking turns, the context-switch cost in ms and the maximum acceptable wait (ms) before a process runs again. Second line: candidate time slices q (ms).

For each q print q=Q efficiency=E% worstWait=W ms + OK or TOO SLOW, where efficiency = q/(q+s) (two decimals) and worstWait = (n − 1)(q + s) (one decimal); OK means worstWait ≤ maxWait.

Then print Best q: Q (efficiency E%) — the OK candidate with the highest efficiency (the largest OK q) — or Best q: none, and Largest possible q: X ms = maxWait / (n − 1) − s (two decimals; if n = 1 print Largest possible q: unlimited; if the value is ≤ 0 print Largest possible q: impossible).

Input:

12 0.2 100
1 2 5 8 10 20

Output:

q=1 efficiency=83.33% worstWait=13.2 ms OK
q=2 efficiency=90.91% worstWait=24.2 ms OK
q=5 efficiency=96.15% worstWait=57.2 ms OK
q=8 efficiency=97.56% worstWait=90.2 ms OK
q=10 efficiency=98.04% worstWait=112.2 ms TOO SLOW
q=20 efficiency=99.01% worstWait=222.2 ms TOO SLOW
Best q: 8 (efficiency 97.56%)
Largest possible q: 8.89 ms

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os3-3-data-1.txt

12 0.2 100
1 2 5 8 10 20
What your program must print for os3-3-data-1.txt
q=1 efficiency=83.33% worstWait=13.2 ms OK
q=2 efficiency=90.91% worstWait=24.2 ms OK
q=5 efficiency=96.15% worstWait=57.2 ms OK
q=8 efficiency=97.56% worstWait=90.2 ms OK
q=10 efficiency=98.04% worstWait=112.2 ms TOO SLOW
q=20 efficiency=99.01% worstWait=222.2 ms TOO SLOW
Best q: 8 (efficiency 97.56%)
Largest possible q: 8.89 ms

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os3-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content os3-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.