Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def shortest _ Job _ First ( processes ) : GanttChart = [ ] temp = 0 ready _ queue = [ ] waiting _
def shortestJobFirstprocesses:
GanttChart
temp
readyqueue
waitingqueue
currentnTime
Timer
GanttChart.appendprocessesnum, currentnTime, currentnTime processesBursttime
currentnTime processesBursttime
processes.sortkeylambda y: yBursttime
while Timer :
for process in processes:
if Timer :
if currentnTime process.Bursttime :
if waitingqueue:
foundwaiting False
for waitingprocess in waitingqueue:
if temp waitingprocess.Comesbackafter:
readyqueue.appendwaitingprocess
waitingqueue.removewaitingprocess
foundwaiting True
break
else:
break
if not foundwaiting:
readyqueue.appendprocess
runningprocess readyqueue.pop
GanttChart.appendprocessnum, currentnTime, currentnTime process.Bursttime
waitingqueue.appendrunningprocess
temp process.Bursttime
process.waitingtime max currentnTime process.Arrivaltime
process.turnaroundtime process.waitingtime process.Bursttime
currentnTime process.Bursttime
currentnTime process.Bursttime
Timer currentnTime
else:
runningprocess readyqueue.pop
GanttChart.appendrunningprocess.num, currentnTime, currentnTime runningprocess.Bursttime
waitingqueue.appendrunningprocess
temp runningprocess.Bursttime
process.waitingtime max currentnTime process.Arrivaltime
process.turnaroundtime process.waitingtime process.Bursttime
currentnTime runningprocess.Bursttime
Timer currentnTime
else:
readyqueue.appendprocess
runningprocess readyqueue.pop
GanttChart.appendprocessnum, currentnTime, currentnTime process.Bursttime
process.waitingtime max currentnTime process.Arrivaltime
process.turnaroundtime process.waitingtime process.Bursttime
currentnTime process.Bursttime
waitingqueue.appendrunningprocess
currentnTime process.Bursttime
Timer currentnTime
# Calculate average waiting time and average turnaround time
avgwaitingtime calculateaveragewaitingtimeprocesses
avgturnaroundtime calculateaverageturnaroundtimeprocesses
return GanttChart, avgwaitingtime, avgturnaroundtime edit it to give me this output Shortest Job First:
GANTT CHART:
P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P
Average waiting time
Average turnaround time
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started