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
processeswaitingtime max currentnTime processesArrivaltime
processesturnaroundtime processeswaitingtime 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
currentnTime process.Bursttime
process.waitingtime max currentnTime process.Arrivaltime
process.turnaroundtime process.waitingtime process.Bursttime
Timer currentnTime
else:
runningprocess readyqueue.pop
GanttChart.appendrunningprocess.num, currentnTime, currentnTime runningprocess.Bursttime
waitingqueue.appendrunningprocess
temp runningprocess.Bursttime
currentnTime runningprocess.Bursttime
process.waitingtime max currentnTime process.Arrivaltime
process.turnaroundtime process.waitingtime process.Bursttime
Timer currentnTime
else:
readyqueue.appendprocess
runningprocess readyqueue.pop
GanttChart.appendprocessnum, currentnTime, currentnTime process.Bursttime
waitingqueue.appendrunningprocess
currentnTime process.Bursttime
Timer currentnTime
else:
currentnTime
Timer currentnTime
# Calculate average waiting time and average turnaround time
avgwaitingtime calculateaveragewaitingtimeprocesses
avgturnaroundtime calculateaverageturnaroundtimeprocesses
return GanttChart, avgwaitingtime, avgturnaroundtime the algorithm true but the avg waiting tima and around time false it should to be Average waiting time
Average turnaround time please fix the code to get this results
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