MST can be solved several ways, here are two (pseudo code).
Prim's Algorithm
Start at arbitrary node (0)
visitied[0] = true
visitedCount = 1;
while (visitedCount < nodeCount) {
Traverse all visited nodes and look at all adjacent edges and determine the least weighted edge.
If the edge has an unvisited node on the end of it then mark that node as visited and increment visitedCount
}
Kruskal's Algorithm
Add all edges to a priority queue ordered from least weighted edge to most weighted edge.
visitedCount = 0;
while (visitedCount < nodeCount) {
Remove the edge (with the least weight) from the queue
If one of the nodes on the edge has not been visited {
Mark any unvisited node as visited
For each recently visited node increment visitedCount
}
}
To approximate a zero of a function F(x) to arbitrary precision 1) Choose a starting value x0 2) compute or approximate the derivative f(x0) = dF/dt (at x0) 3) construct the tangent line at F(x): y = F(x0) + f(x0)*(x - x0) 4) Set y=0 to find the zero-crossing of this line: x = x0 - (F(x0)/f(x0)) 5) goto (2) with this x as your new x0 Terminate when (x == x0) within the required tolerance. This will tend to find zeros near x0; it is not guaranteed to find a particular zero (some are repellers, not attractors of this algorithm), but it should find at least one zero for any analytic function / function with a continuous second derivative over the area of interest (i.e. any function you'd see in competition).
No comments:
Post a Comment