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.