Professional Documents
Culture Documents
The running-time of 8
exponential 6
.
.
5
.
.
5
.
.
4
.
.
numbers. 3 2 2 1
2 1 1 0 1 0
1 0
TIE-20106 5
M EM -F IB -R ECURS(i)
1 if F [i] < 0 then (if the result hasnt been calculated)
2 F [i] := M EM -F IB -R ECURS(i 1) + M EM -F IB -R ECURS(i 2)
3 return F [i]
TIE-20106 7
this is how most of you would have solved this in the first
place!
the running-time of the algorithm is still (n), but the
memory consumption is only (1)
TIE-20106 19
the algorithm:
G REEDY-ACTIVITY-S ELECTOR(S, f ) (uses a queue Q)
1 . sort the reservations so that f1 f2 . . . fn
2 n := S .length
3 Q.push(1 ) (push the first event into the queue)
4 j := 1
5 for i := 2 to n do (on each step add the event which,)
6 if si fj then (starts as early as possible)
7 Q.push(i )
8 j := i
9 return Q
the running-time
sorting O(n lg n)
G REEDY-ACTIVITY-S ELECTOR (n), sill Q.Push() on (1).
quite efficient
TIE-20106 21