Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Exclusive Time of Functions
Bookmark
Input
Example 1
Recursive
Sequential
Custom
n
=
2
,
logs
=
[0:start:0, 1:start:2, 1:end:5, 0:end:6]
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 0
fn 1
= 0
stack
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 0
fn 1
= 0
stack
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 0
fn 1
= 0
prevTime
stack
0
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 0
fn 1
= 0
prevTime
stack
0
1:start:2
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 2
fn 1
= 0
+2
prevTime
stack
0
1
push
fn 1
onto the call stack
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 2
fn 1
= 0
prevTime
stack
0
1
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 2
fn 1
= 4
+4
prevTime
stack
0
1
result[fn 1] +=
4
(inclusive of the end tick)
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 2
fn 1
= 4
+4
prevTime
stack
0
the function returned, pop it off the stack
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 2
fn 1
= 4
prevTime
stack
0
0:end:6
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 3
fn 1
= 4
+1
prevTime
stack
0
result[fn 0] +=
1
(inclusive of the end tick)
logs
0:start:0
1:start:2
1:end:5
0:end:6
0
1
2
3
4
5
6
7
time
fn 0
= 3
fn 1
= 4
stack
return
[3, 4]
algo
master
.
io
Step:
Single-threaded CPU: each log credits time to the function on top of the stack.
0 / 14
Input
Example 1
Recursive
Sequential
Custom
n
=
2
,
logs
=
[0:start:0, 1:start:2, 1:end:5, 0:end:6]
0 / 14
algo
master
.
io
Step:
Single-threaded CPU: each log credits time to the function on top of the stack.