0% found this document useful (0 votes)
5 views2 pages

SJF BubbleSort Algorithm

The document outlines an algorithm for Shortest Job First (SJF) scheduling using Bubble Sort. It details the steps for inputting process data, sorting by burst time, calculating waiting and turnaround times, and displaying the results. The algorithm emphasizes ensuring that the shortest jobs are scheduled first and includes calculations for average times.

Uploaded by

tl23btcs0369
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

SJF BubbleSort Algorithm

The document outlines an algorithm for Shortest Job First (SJF) scheduling using Bubble Sort. It details the steps for inputting process data, sorting by burst time, calculating waiting and turnaround times, and displaying the results. The algorithm emphasizes ensuring that the shortest jobs are scheduled first and includes calculations for average times.

Uploaded by

tl23btcs0369
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SJF Scheduling using Bubble Sort - Algorithm

Algorithm (Structured with Explanation):

1. Start the program.

2. Input the number of processes

-> Let n be the number of processes.

3. Input the burst time for each process

-> For each process i from 0 to n - 1:

- Read burst time bt[i]

- Assign process ID p[i] = i + 1

4. Sort the processes by burst time using Bubble Sort

-> This ensures that the shortest jobs are scheduled first.

-> For i = 0 to n - 2:

- For j = 0 to n - i - 2:

- If bt[j] > bt[j+1]:

- Swap bt[j] and bt[j+1]

- Swap p[j] and p[j+1] (to keep IDs in sync)

5. Calculate Waiting Time (WT) for each process

-> The first process has 0 waiting time: wt[0] = 0

-> For each process i = 1 to n - 1:

- Set wt[i] = wt[i-1] + bt[i-1]


SJF Scheduling using Bubble Sort - Algorithm

6. Calculate Turnaround Time (TAT) for each process

-> For each process i = 0 to n - 1:

- Set tat[i] = wt[i] + bt[i]

7. Calculate the average waiting time and turnaround time

-> Sum all wt[i] and divide by n for average waiting time

-> Sum all tat[i] and divide by n for average turnaround time

8. Display the results

-> Print the process ID, burst time, waiting time, and turnaround time for each process

-> Also print average waiting time and average turnaround time

9. End the program.

You might also like