Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Single-Threaded CPU
Bookmark
Brute Force
Sort + Min-Heap
Input
Example 1
Same Enqueue
Example 3
Custom
enqueueTimes
=
[1, 2, 3, 4]
,
processingTimes
=
[2, 4, 2, 1]
,
tasks
=
[[1,2], [2,4], [3,2], [4,1]]
T0
[1,2]
T1
[2,4]
T2
[3,2]
T3
[4,1]
0
2
4
6
8
10
always run the ready task with the shortest processing time
T0
[1,2]
T1
[2,4]
T2
[3,2]
T3
[4,1]
0
2
4
6
8
10
always run the ready task with the shortest processing time
t =
0
done =
0
/ 4
T0
[1,2]
T1
[2,4]
T2
[3,2]
T3
[4,1]
0
2
4
6
8
10
check
T1
, best so far
none
t =
0
done =
0
/ 4
T0
[1,2]
T1
[2,4]
T2
[3,2]
T3
[4,1]
0
2
4
6
8
10
rescan at t =
0
, best is
T0
t =
3
done =
1
/ 4
T0
[1,2]
1
T1
[2,4]
T2
[3,2]
T3
[4,1]
available now:
T2:2
T1:4
0
2
4
6
8
10
idle
T0
order:
0
check
T0
, best so far
none
t =
3
done =
1
/ 4
T0
[1,2]
1
T1
[2,4]
T2
[3,2]
T3
[4,1]
available now:
T2:2
T1:4
0
2
4
6
8
10
idle
T0
order:
0
check
T2
, best so far
T2
t =
5
done =
2
/ 4
T0
[1,2]
1
T1
[2,4]
T2
[3,2]
2
T3
[4,1]
available now:
T3:1
T1:4
0
2
4
6
8
10
idle
T0
T2
order:
0
2
check
T0
, best so far
none
t =
5
done =
2
/ 4
T0
[1,2]
1
T1
[2,4]
T2
[3,2]
2
T3
[4,1]
available now:
T3:1
T1:4
0
2
4
6
8
10
idle
T0
T2
order:
0
2
check
T2
, best so far
T1
t =
6
done =
3
/ 4
T0
[1,2]
1
T1
[2,4]
T2
[3,2]
2
T3
[4,1]
3
available now:
T1:4
0
2
4
6
8
10
idle
T0
T2
T3
order:
0
2
3
scan every task for the best one at t =
6
t =
6
done =
3
/ 4
T0
[1,2]
1
T1
[2,4]
T2
[3,2]
2
T3
[4,1]
3
available now:
T1:4
0
2
4
6
8
10
idle
T0
T2
T3
order:
0
2
3
check
T2
, best so far
T1
t =
10
done =
4
/ 4
T0
[1,2]
1
T1
[2,4]
4
T2
[3,2]
2
T3
[4,1]
3
0
2
4
6
8
10
idle
T0
T2
T3
T1
order:
0
2
3
1
order = [0, 2, 3, 1]
algo
master
.
io
Step:
Start: 4 tasks, t = 0, nothing processed
0 / 48
Input
Example 1
Same Enqueue
Example 3
Custom
enqueueTimes
=
[1, 2, 3, 4]
,
processingTimes
=
[2, 4, 2, 1]
,
tasks
=
[[1,2], [2,4], [3,2], [4,1]]
0 / 48
algo
master
.
io
Step:
Start: 4 tasks, t = 0, nothing processed