Current Affairs

Assignment Question - PGDCA

Read the important current affairs of 15 July 2026 for SSC, Banking, UPSC, Railway and all competitive exams.

22 Oct 2024 5 Min Read Quizer Team 60 Views

22

October 2024

Questions-1.  Consider the following set of processes, with the length of the CPU burst time given in milliseconds.

ProcessBurst TimePriority
P185
P233
P314
P447
P526


The processes are assumed to have arrived in the order P1, P2, P3, P4 and P5 and all of them have arrived at time 0.

a. Draw corresponding Gantt charts illustrating the execution of these processes using FCFS, SJF, SRTN, Priority based scheduling/even-driven scheduling and Round Robin (quantum=2) scheduling algorithms.

b. What is the turnaround time of each process for each of the scheduling algorithm in (a)?

c. What is the waiting time of each process for each of the scheduling algorithm in (a)?

d. Which of the schedules in (a) results in minimal average waiting time (overall processes)?


Answer :

Process Information

ProcessBurst TimePriority
P185
P233
P314
P447
P526

(a) Gantt Charts

1. First Come First Serve (FCFS) Scheduling

In FCFS, processes are scheduled in the order they arrive.

  • Gantt Chart:
Time0 - 88 - 1111 - 1212 - 1616 - 18

P1P2P3P4P5

2. Shortest Job First (SJF) Scheduling

In SJF, the process with the shortest burst time is executed next. All processes arrive at time 0, so we sort them by burst time.

  • Order of Execution: <math xmlns="http://www.w3.org/1998/Math/MathML">P3→P5→P2→P4→P1P3 \rightarrow P5 \rightarrow P2 \rightarrow P4 \rightarrow P1</math>

  • Gantt Chart:

Time0 - 11 - 33 - 66 - 1010 - 18

P3P5P2P4P1

3. Shortest Remaining Time Next (SRTN) Scheduling

SRTN is a preemptive version of SJF. Whenever a new process arrives, it can preempt the running process if it has a shorter remaining time.

  • Execution: <math xmlns="http://www.w3.org/1998/Math/MathML">P3→P5→P2→P4→P1P3 \rightarrow P5 \rightarrow P2 \rightarrow P4 \rightarrow P1</math>

    • P3 (executes fully)
    • P5 (executes fully)
    • P2 (executes fully)
    • P4 (executes fully)
    • P1 (executes fully)
  • Gantt Chart:

Time0 - 11 - 33 - 66 - 1010 - 18

P3P5P2P4P1

4. Priority-Based Scheduling

In priority scheduling, the process with the highest priority (lowest number) is selected first.

  • Order of Execution (based on priority): <math xmlns="http://www.w3.org/1998/Math/MathML">P2→P3→P5→P1→P4P2 \rightarrow P3 \rightarrow P5 \rightarrow P1 \rightarrow P4</math>

  • Gantt Chart:

Time0 - 33 - 44 - 66 - 1414 - 18

P2P3P5P1P4

5. Round Robin Scheduling (Quantum = 2)

In Round Robin, processes are given a fixed time quantum (2 ms here). If a process isn't finished within that quantum, it's moved to the back of the queue.

  • Order of Execution (Rotating based on time quantum of 2):
Time0 - 22 - 44 - 55 - 77 - 99 - 1010 - 1212 - 1414 - 1616 - 18

P1P2P3P4P5P1P2P4P1P1

(b) Turnaround Time (TAT)

Turnaround time is calculated as:

<math xmlns="http://www.w3.org/1998/Math/MathML">Turnaround Time=Completion Time−Arrival Time\text{Turnaround Time} = \text{Completion Time} - \text{Arrival Time}</math>

  • For each scheduling algorithm, calculate when each process finishes.

1. FCFS:

ProcessCompletion TimeTurnaround Time
P188
P21111
P31212
P41616
P51818

2. SJF:

ProcessCompletion TimeTurnaround Time
P11818
P266
P311
P41010
P533

3. SRTN:

ProcessCompletion TimeTurnaround Time
P11818
P266
P311
P41010
P533

4. Priority-Based:

ProcessCompletion TimeTurnaround Time
P11414
P233
P344
P41818
P566

5. Round Robin (Quantum = 2):

ProcessCompletion TimeTurnaround Time
P11818
P21212
P355
P41414
P599

(c) Waiting Time (WT)

Waiting time is calculated as:

<math xmlns="http://www.w3.org/1998/Math/MathML">Waiting Time=Turnaround Time−Burst Time\text{Waiting Time} = \text{Turnaround Time} - \text{Burst Time}</math>

1. FCFS:

ProcessBurst TimeTurnaround TimeWaiting Time
P1880
P23118
P311211
P441612
P521816

2. SJF:

ProcessBurst TimeTurnaround TimeWaiting Time
P181810
P2363
P3110
P44106
P5231

3. SRTN:

ProcessBurst TimeTurnaround TimeWaiting Time
P181810
P2363
P3110
P44106
P5231

4. Priority-Based:

ProcessBurst TimeTurnaround TimeWaiting Time
P18146
P2330
P3143
P441814
P5264

5. Round Robin (Quantum = 2):

ProcessBurst TimeTurnaround TimeWaiting Time
P181810
P23129
P3154
P441410
P5297

(d) Minimal Average Waiting Time

  • To find the minimal average waiting time, we compute the average for each algorithm:

1. FCFS:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">Average Waiting Time=0+8+11+12+165=9.4 ms\text{Average Waiting Time} = \frac{0 + 8 + 11 + 12 + 16}{5} = 9.4 \text{ ms}</math>

2. SJF:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">Average Waiting Time=10+3+0+6+15=4 ms\text{Average Waiting Time} = \frac{10 + 3 + 0 + 6 + 1}{5} = 4 \text{ ms}</math>

3. SRTN:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">Average Waiting Time=10+3+0+6+15=4 ms\text{Average Waiting Time} = \frac{10 + 3 + 0 + 6 + 1}{5} = 4 \text{ ms}</math>

4. Priority-Based:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">Average Waiting Time=6+0+3+14+45=5.4 ms\text{Average Waiting Time} = \frac{6 + 0 + 3 + 14 + 4}{5} = 5.4 \text{ ms}</math>

5. Round Robin:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">Average Waiting Time=10+9+4+10+75=8 ms\text{Average Waiting Time} = \frac{10 + 9 + 4 + 10 + 7}{5} = 8 \text{ ms}</math>




Questions -2. Consider the following page-reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6 

How many page faults would occur for the following replacement algorithms, assuming three frames? Remember all frames are initially empty. a. FIFO replacement b. LRU replacement c. Optimal Mention the merits and demerits of each of the above algorithms.


Answer :

To determine the number of page faults for the given page-reference string using three different page replacement algorithms (FIFO, LRU, and Optimal), let's analyze each algorithm step by step.

Page-Reference String

1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6

a. FIFO (First-In, First-Out) Replacement

In FIFO, the oldest page is replaced first.

  • Frames: Initially empty: []
  • Step by Step:
    1. Page 1: Fault → [1]
    2. Page 2: Fault → [1, 2]
    3. Page 3: Fault → [1, 2, 3]
    4. Page 4: Fault → [2, 3, 4] (1 replaced)
    5. Page 2: Hit → [2, 3, 4]
    6. Page 1: Fault → [3, 4, 1] (2 replaced)
    7. Page 5: Fault → [4, 1, 5] (3 replaced)
    8. Page 6: Fault → [1, 5, 6] (4 replaced)
    9. Page 2: Fault → [5, 6, 2] (1 replaced)
    10. Page 1: Fault → [6, 2, 1] (5 replaced)
    11. Page 2: Hit → [6, 2, 1]
    12. Page 3: Fault → [2, 1, 3] (6 replaced)
    13. Page 7: Fault → [1, 3, 7] (2 replaced)
    14. Page 6: Fault → [3, 7, 6] (1 replaced)
    15. Page 3: Hit → [3, 7, 6]
    16. Page 2: Fault → [7, 6, 2] (3 replaced)
    17. Page 1: Fault → [6, 2, 1] (7 replaced)
    18. Page 2: Hit → [6, 2, 1]
    19. Page 3: Fault → [2, 1, 3] (6 replaced)
    20. Page 6: Fault → [1, 3, 6] (2 replaced)

Total Page Faults (FIFO): 12

b. LRU (Least Recently Used) Replacement

In LRU, the least recently used page is replaced.

  • Frames: Initially empty: []
  • Step by Step:
    1. Page 1: Fault → [1]
    2. Page 2: Fault → [1, 2]
    3. Page 3: Fault → [1, 2, 3]
    4. Page 4: Fault → [2, 3, 4] (1 replaced)
    5. Page 2: Hit → [2, 3, 4]
    6. Page 1: Fault → [3, 4, 1] (2 replaced)
    7. Page 5: Fault → [4, 1, 5] (3 replaced)
    8. Page 6: Fault → [1, 5, 6] (4 replaced)
    9. Page 2: Fault → [5, 6, 2] (1 replaced)
    10. Page 1: Fault → [6, 2, 1] (5 replaced)
    11. Page 2: Hit → [6, 2, 1]
    12. Page 3: Fault → [2, 1, 3] (6 replaced)
    13. Page 7: Fault → [1, 3, 7] (2 replaced)
    14. Page 6: Fault → [3, 7, 6] (1 replaced)
    15. Page 3: Hit → [3, 7, 6]
    16. Page 2: Fault → [7, 6, 2] (3 replaced)
    17. Page 1: Fault → [6, 2, 1] (7 replaced)
    18. Page 2: Hit → [6, 2, 1]
    19. Page 3: Fault → [2, 1, 3] (6 replaced)
    20. Page 6: Fault → [1, 3, 6] (2 replaced)

Total Page Faults (LRU): 12

c. Optimal Replacement

In Optimal, the page that will not be used for the longest time in the future is replaced.

  • Frames: Initially empty: []
  • Step by Step:
    1. Page 1: Fault → [1]
    2. Page 2: Fault → [1, 2]
    3. Page 3: Fault → [1, 2, 3]
    4. Page 4: Fault → [2, 3, 4] (1 replaced; will not be used again)
    5. Page 2: Hit → [2, 3, 4]
    6. Page 1: Fault → [3, 4, 1] (2 replaced; used in future)
    7. Page 5: Fault → [4, 1, 5] (3 replaced; used in future)
    8. Page 6: Fault → [1, 5, 6] (4 replaced)
    9. Page 2: Fault → [5, 6, 2] (1 replaced; used in future)
    10. Page 1: Fault → [6, 2, 1] (5 replaced)
    11. Page 2: Hit → [6, 2, 1]
    12. Page 3: Fault → [2, 1, 3] (6 replaced)
    13. Page 7: Fault → [1, 3, 7] (2 replaced)
    14. Page 6: Fault → [3, 7, 6] (1 replaced)
    15. Page 3: Hit → [3, 7, 6]
    16. Page 2: Fault → [7, 6, 2] (3 replaced)
    17. Page 1: Fault → [6, 2, 1] (7 replaced)
    18. Page 2: Hit → [6, 2, 1]
    19. Page 3: Fault → [2, 1, 3] (6 replaced)
    20. Page 6: Fault → [1, 3, 6] (2 replaced)

Total Page Faults (Optimal): 9

Summary of Page Faults

  • FIFO: 12 faults
  • LRU: 12 faults
  • Optimal: 9 faults

Merits and Demerits

FIFO (First-In, First-Out)

  • Merits:
    • Simple to implement and understand.
    • No need for future knowledge of references.
  • Demerits:
    • Can lead to Belady's anomaly (more frames can cause more faults).
    • Does not consider page usage frequency.

LRU (Least Recently Used)

  • Merits:
    • Better performance than FIFO in many cases.
    • Intuitive, as it considers the recent usage pattern.
  • Demerits:
    • More complex to implement, requiring tracking of page usage.
    • High overhead due to the need to maintain usage order.

Optimal

  • Merits:
    • Provides the best possible performance (fewest page faults).
    • Useful as a benchmark for evaluating other algorithms.
  • Demerits:
    • Requires future knowledge of reference strings, which is impractical in real systems.
    • Not implementable in a standard operating environment.


Questions-4.  Write a program in C to implement Banker’s Algorithm to avoid Deadlock. Also explain the code briefly.


<!--[if gte mso 9]><xml> </xml><![endif]--><!--[if gte mso 9]><xml> Normal 0 false false false EN-US X-NONE X-NONE </xml><![endif]--><!--[if gte mso 9]><xml> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0in; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style> <![endif]-->

Program to Implement Banker’s Algorithm in C

The Banker's Algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra. It tests whether a safe sequence exists when a process requests a resource, thereby preventing deadlock.

Here is the code for implementing the Banker's Algorithm:

#include

 

void
calculateNeed(int need[][10], int max[][10], int allot[][10], int P, int R) {
    // Calculate the need matrix
    for (int i = 0; i < P>
        for (int j = 0; j < R>
            need[i][j] = max[i][j] -
allot[i][j];
        }
    }
}
 
int
checkSafe(int processes[], int avail[], int max[][10], int allot[][10], int P,
int R) {
    int need[10][10];
    calculateNeed(need, max, allot, P, R);
 
    int finish[10] = {0}; 

    int safeSeq[10];  

    int work[10];
 
  

    for (int i = 0; i < R>
        work[i] = avail[i];
    }
 
    int count = 0;
    while (count < P>
        int found = 0;
        for (int p = 0; p < P>
           

            if (finish[p] == 0) {
                int j;
                for (j = 0; j < R>

    
			


			



 
   


Why This Content Matters

This content is prepared to help students and competitive-exam aspirants understand important topics, revise key information, and strengthen their exam preparation.

  • Quickly revise important facts and concepts
  • Improve General Knowledge and exam awareness
  • Support preparation for competitive and government exams
  • Build a consistent and effective study routine
Quizer Team
About the Author

Quizer Team

The Quizer Team creates exam-focused educational content, current affairs, general knowledge, study notes, and preparation resources to help students and competitive-exam aspirants learn, practice, and stay updated.

Educational Content Exam Focused Learning Resources

📢 Join Our WhatsApp Channel

Get Daily GK, Current Affairs, Amazing Facts & Quiz Updates.

🚀 Join Now

Join Monthly Challenge

Compete, Learn & Win exciting prizes.

  • Cash Rewards
  • E-Certificates
  • Leaderboard Ranking
  • Daily Practice
Join Now

Related Post

Current Affairs
24 Sep 2026 364
Read More
Current Affairs
3 Sep 2026 389
Read More
Current Affairs
27 Aug 2026 835
Read More