This file contains 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
def A*-TREE-SEARCH (start): | |
Let pq be an empty min priority queue | |
g(start) = 0 | |
f(start) = h(start) | |
path(start) = [] | |
pq.push(start, f(start)) | |
while not pq.empty(): | |
top = pq.pop() |
This file contains 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
def A*-GRAPH-SEARCH (start): | |
Let pq be an empty min priority queue | |
Let closed be an empty set | |
g(start) = 0 | |
f(start) = h(start) | |
path(start) = [] | |
pq.push(start, f(start)) | |
while not pq.empty(): |
This file contains 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
def next-move(state, depth): | |
bestMove = nil | |
alpha = -INF | |
for next-state in state.nexts(): | |
result = minscore(next-state, depth-1, alpha, INF) | |
if result > alpha: | |
alpha = result | |
bestMove = next-state.move() | |
if alpha >= MAX-POSSIBLE-SCORE: | |
break |
This file contains 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
Evaluation function for Phase 1 = 18 * (1) + 26 * (2) + 1 * (3) + 9 * (4) + 10 * (5) + 7 * (6) | |
Evaluation function for Phase 2 = 14 * (1) + 43 * (2) + 10 * (3) + 11 * (4) + 8 * (7) + 1086 * (8) | |
Evaluation function for Phase 3 = 16 * (1) + 10 * (5) + 1 * (6) + 1190 * (8) |
This file contains 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
# Add v to A[p] | |
update(p, v): | |
for (; p <= N; p += p&(-p)) | |
ft[p] += v | |
# Return sum A[1...b] | |
query(b): | |
sum = 0 | |
for(; b > 0; b -= b&(-b)) | |
sum += ft[b] |
This file contains 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
# A[] is the original array | |
# ft[] is the fenwick tree maintaining the diffs initialized with 0 | |
# Add v to A[p] | |
update(p, v): | |
for (; p <= N; p += p&(-p)) | |
ft[p] += v | |
# Add v to A[a...b] | |
update(a, b, v): |
This file contains 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
update(ft, p, v): | |
for (; p <= N; p += p&(-p)) | |
ft[p] += v | |
# Add v to A[a...b] | |
update(a, b, v): | |
update(B1, a, v) | |
update(B1, b + 1, -v) | |
update(B2, a, v * (a-1)) | |
update(B2, b + 1, -v * b) |
This file contains 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 jobs in non-decreasing order of their deadlines | |
last_finished = s[1] | |
for i = 1 to n: | |
Assign job i to the interval [last_finished, last_finished + t[i]] | |
last_finished += t[i] |
This file contains 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 disc_time[v] = -1 and explored[v] = false forall v | |
dfscounter = 0 | |
DFS(v): | |
explored[v] = true | |
disc_time[v] = low[v] = ++dfscounter | |
foreach edge (v,x): | |
if !explored[x]: | |
DFS(x) | |
low[v] = min(low[v], low[x]) |
This file contains 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
Partition(bolts[lo...hi], nut): | |
j = lo | |
for i in range(lo, hi): | |
if bolts[i] < nut: | |
swap(bolts[i], bolts[j]) | |
j += 1 | |
elif bolts[i] == nut: | |
swap(bolts[i], bolts[hi]) | |
# the bolt that ends up at i might be larger than nut | |
i -= 1 |
OlderNewer