Priority Scheduling
Schedules processes based on priority. Higher priority executes first. Can be preemptive or non-preemptive.
Visualization
Interactive visualization for Priority Scheduling
Priority Scheduling:
- • Schedule by priority value
- • Lower number = higher priority
Interactive visualization with step-by-step execution
Implementation
1function priorityScheduling(processes: {id: number; burstTime: number; priority: number}[]): {avgWaitTime: number} {
2 processes.sort((a, b) => b.priority - a.priority);
3 let currentTime = 0, totalWait = 0;
4
5 for (const p of processes) {
6 totalWait += currentTime;
7 currentTime += p.burstTime;
8 }
9
10 return {avgWaitTime: totalWait / processes.length};
11}Deep Dive
Theoretical Foundation
Each process assigned priority. Scheduler selects highest priority from ready queue. Preemptive: can interrupt running process. Non-preemptive: runs to completion. Aging prevents starvation.
Complexity
Time
O(n log n)
O(n log n)
O(n log n)
Space
O(1)
Applications
Industry Use
Real-time operating systems (RTOS)
System process scheduling (kernel vs user processes)
Emergency response systems
Network packet scheduling with QoS
Database transaction scheduling
Interrupt handling in embedded systems
Use Cases
Related Algorithms
First Come First Serve (FCFS)
Non-preemptive scheduling executing processes in arrival order. Simple queue-based scheduling algorithm that serves as the foundation for understanding CPU scheduling. Despite its simplicity, FCFS can suffer from the convoy effect where short processes are delayed by long-running processes ahead of them in the queue.
Shortest Job First (SJF)
Schedules process with shortest burst time first. Minimizes average waiting time (optimal).
Round Robin Scheduling
Preemptive scheduling with fixed time quantum. Each process gets equal CPU time slices.
Quicksort
A highly efficient, in-place sorting algorithm that uses divide-and-conquer strategy. Invented by Tony Hoare in 1959, it remains one of the most widely used sorting algorithms due to its excellent average-case performance and cache efficiency.