Vous êtes sur la page 1sur 2

Data Structures and Algorithms Home Work 04

D a t a S t r u c t u r e s a n d A l g o r i t h m s
Home Work 04 Marks 10
Instructions
Work on this home work individually. Absolutely NO collaboration is allowed. Any traces of plagiarism would result in a ZERO marks
in this homework and possible disciplinary action.

Due Date
Paste the solution(s) folder of the problems (source code .cpp files only) labeled with your complete roll number in SEM – HW 04,
SEA – HW 04 and CSM – HW 04 folders for SE Morning, SE Afternoon and CS Morning sections respectively till Tuesday, April 15,
2018 before 05:00 PM. These folders are available at \\printsrv\Teacher Data\Umair Babar\Students.

ROUND ROBIN SCHEDULING ALGORITHM


The Round Robin Scheduling Algorithm is designed especially for the time sharing systems. A small unit of time called a time
quantum is defined. A time quantum is generally from ten to hundred milliseconds. The ready queue is treated as a circular queue.
The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to one time quantum.

To implement the round robin scheduling, we keep the ready queue as a FIFO queue of the processes. New processes are added to
the tail of the ready queue. The CPU scheduler picks the first process from the ready queue, sets a timer to interrupt after one time
quantum in a row.

What you have to do


1. Create an ADT to represent process details.
2. Get the number of processes, process attributes (name, arrival time, service time) and time slice (quantum) as input from
a file (input.txt).
3. Sort the circular linked list nodes based on the arrival time in increasing order. If the arrival times of the processes are
same then sort it based in its service time of the processes in increasing order. Assume that no two processes with the
same arrival time can have the same service time.
4. Calculate the other process attributes such as starting time, finish time, turn-around-time and waiting time.
5. We allocate the CPU towards to the process on the first node of the linked list.
6. If the arrival time of a new process (A) and the time of taking away the CPU from a running process (B) is same then their
order in the queue will be (A) followed by (B).

7. Up to the time interval (quantum) switch the CPU towards next process and reduce the previous process service time by
time slice (hint: use loop). If the service time is found to be less than or equal to zero print the process attributes and delete
the node from the linked lists.
8. Repeat the step 7 until the linked list is empty.
Formulas to calculate the waiting time and the turnaround time for a process.

Turnaround Time for one Job = Finish Time – Arrival Time


Waiting Time for one Job = Turnaround Time for one Job – Service Time

At the end your program should output the average waiting time and the average turnaround time for all the processes.

The input file (input.txt) is exactly in the following format:


Number of processes
Time Slice
Process-Name Arrival-time Service-Time
Process-Name Arrival-time Service-Time
Process-Name Arrival-time Service-Time
Process-Name Arrival-time Service-Time


Sample Run

Umair Babar, PUCIT – PU. Lahore. Page 1 of 2


Data Structures and Algorithms Home Work 04
Required input: Process name, Arrival time, Service time and Time slice
Expected output: Process name, Arrival time, Service time, Finish time, Turnaround time and Waiting time

Input.txt
5
1
A 0 3
B 0 4
C 1 5
D 3 6
E 5 6

Output
Process Name Arrival Time Service Time Finish Time Turn-around-time Waiting Time
A 0 3 8 8 5
B 0 4 14 14 10
C 1 5 19 18 13
D 3 6 23 20 14
E 5 6 24 19 13

NOTE: - No submission will be accepted after the DUE DATE and TIME.
B E S T O F L U C K

Umair Babar, PUCIT – PU. Lahore. Page 2 of 2

Vous aimerez peut-être aussi