This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OPT[0] = 0 | |
for j = 1 to n: | |
for i = 1 to j: | |
compute e(i, j) for the segment pi, pi+1, ..., pj | |
for j = 1 to n: | |
OPT(j) = min((e(i,j) + C + OPT[i-1]) forall 1 ≤ i ≤ j) | |
return OPT[n] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OPT(j): | |
if j == 0: | |
return 0 | |
return max(wj + OPT(p(j)), OPT(j-1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let R be the set of all requests | |
Let d = 0 be the number of resources | |
while !R.empty(): | |
Choose a request i ∈ R that has the earliest start time | |
if i can be assigned to some resource k <= d: | |
assign request i to resource k | |
else: | |
allocate a new resource d+1 | |
assign request i to resource d+1 | |
d = d + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort the n requests in order of start time | |
d = 1 | |
assign request 1 to resource 1 | |
min_pq.insert(1, f(i)) | |
for i = 2 to n: | |
j = min_pq.minIndex() | |
if s(i) >= min_pq.keyOf(j): | |
assign request i to resource j | |
min_pq.increaseKey(j, f(i)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let R be the set of all requests | |
schedule = {} | |
while !R.empty(): | |
Choose a request i ∈ R that has the smallest finish time | |
Add i to schedule | |
Delete all requests from R that are incompatible with i | |
return schedule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort the n requests in order of finish time | |
schedule = {} | |
last_finish = 0 | |
for i = 1 to n: | |
if s(i) >= last_finish: | |
Add i to schedule | |
last_finish = f(i) | |
return schedule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Initially all m ∈ M and w ∈ W are free | |
while ∃ m who is free and hasn't proposed to every woman: | |
choose m | |
Let w be the highest-ranked woman in m's preference list to whom m has not yet proposed | |
if w is free: | |
(m, w) become engaged | |
elif w is currently engaged to m': | |
if w prefers m' to m: | |
m remains free | |
else w prefers m to m': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assume graph G is connected. Otherwise, we can run the algorithm for each connected component of G. | |
Let q be an empty queue | |
Pick any vertex s ∈ V and color it Red | |
q.enqueue(s) | |
while !q.empty() | |
u = q.dequeue() | |
foreach v in u.adjList: | |
if v.color is nil: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interpolation_search(A[0...n-1], x): | |
i = 0, j = n-1, lo = A[i], hi = A[j] | |
if x < lo: | |
return -1 | |
if x >= hi: | |
i = j | |
while i < j: | |
k = i + ((j - i) * (x - lo)) / (hi - lo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach p of the remaining n-3 points in sorted order | |
while (point next to top in S, S.top(), p) do not form a counter-clockwise turn | |
S.pop() | |
S.push(p) | |
return S |