You are on page 1of 2

Data Structures and Algorithms

Home Work 04

Da t a
Home Work 04 Instructions

S t r u c tu r e s

A n d

A l g o r i th m s
Marks 100

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 DSAM HW 04 and DSAA HW 04 folders for morning and afternoon sections respectively on Wednesday, June 06, 2012 before 06: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. 2. 3. Create an ADT to represent process details. Get the number of processes, process attributes (name, arrival time, service time) and time slice (quantum) as input from a file (input.txt). 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. Calculate the other process attributes such as starting time, finish time, turn-around-time and waiting time. We allocate the CPU towards to the process on the first node of the linked list. 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). 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. Repeat the step 7 until the linked list is empty.

4. 5. 6.

7.

8.

Formulas to calculate the waiting time and the turnaround time for a process. Turnaround Time for one Job = Waiting Time for one Job = Finish Time Arrival Time 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 Process-Name Arrival-time Process-Name Arrival-time Process-Name Arrival-time

Service-Time Service-Time Service-Time Service-Time

Umair Babar, PUCIT PU. Lahore.

Page 1 of 2

Data Structures and Algorithms

Home Work 04

Sample Run 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 B C D E

0 0 1 3 5

3 4 5 6 6

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

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

You might also like