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
#define Possible_Wins 8 | |
const int Three_in_a_Row[Possible_Wins][3] = { | |
{ 0, 1, 2 }, | |
{ 3, 4, 5 }, | |
{ 6, 7, 8 }, | |
{ 0, 3, 6 }, | |
{ 1, 4, 7 }, | |
{ 2, 5, 8 }, | |
{ 0, 4, 8 }, | |
{ 2, 4, 6 } |
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 edges in order of increasing cost | |
MST = {} | |
foreach edge (u, v) in order of increasing cost | |
if MST ∪ (u, v) does not create a cycle | |
add (u, v) to MST | |
return MST |
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 the MST contain a single vertex v, where v is any arbitrary vertex of the graph | |
while it is possible to add an edge (u, v) to the MST such that u ∈ MST and v ∉ MST | |
add v and the least-cost edge (u, v) to the MST such that u ∈ MST and v ∉ MST | |
return MST |
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 vertex v in graph: | |
dist[v] = infinity | |
previous[v] = null | |
dist[s] = 0 | |
Q = min-priority queue, holding all nodes v in the graph, ordered by dist[v] | |
while !Q.empty(): | |
u = vertex in Q having smallest key | |
Q.deleteMin() |
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 P be the array of N points | |
minDist = infinity | |
for i = 1 to N-1 | |
for j = i+1 to N | |
if dist(P[i], P[j]) < minDist | |
minDist = dist(P[i], P[j]) | |
closestPair = (P[i], P[j]) | |
return closestPair |
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 A be the given array of integers | |
let minSum = infinity, minLeft = 0, minRight = 0, currentMin = 0, left = 0, right = 0 | |
for i = 0 to A.length - 1 | |
currentMin += A[i] | |
if currentMin < minSum | |
minSum = currentMin | |
right = i; | |
minLeft = left | |
minRight = right | |
if currentMin > 0 |
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 A be the given array of integers | |
let maxSum = -infinity, maxLeft = 0, maxRight = 0, currentMax = 0, left = 0, right = 0 | |
for i = 0 to A.length - 1 | |
currentMax += A[i] | |
if currentMax > maxSum | |
maxSum = currentMax | |
right = i; | |
maxLeft = left | |
maxRight = right | |
if currentMax < 0 |
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 L be an empty list | |
Let all vertices be initially unmarked | |
while there are unmarked vertices: | |
select an unmarked vertex u | |
dfs(u) | |
def dfs(vertex u): | |
mark u | |
foreach edge u -> v |
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 H be a min heap of size m | |
add first element of each list to H | |
Let O be the output list | |
while !H.empty() | |
e = H.deleteMin() | |
add e to O | |
add to H the next element of the list e was taken from | |
return O |
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 |