Nearest Insertion Traveling Salesman Heuristic: is it faster to insert nearest nodes first?

I am trying to implement the nearest insertion TSP heuristic. However, I am wondering if it matters which node I insert into the subgraph first. For example, should I start with one node; calculate the distance between this node and the other nodes; and sort the other nodes by this distance? Then, I will insert … Read more

Intuition behind Floyd-Warshall being faster

I know the Floyd-Warshall, and I also clearly understand the proof of running time of $O(V^3)$ of F-W algorithm. However, consider this algorithm: Let $dp[i][j][n]$ denote the shortest path from $V_i$ to $V_j$ using at most $n$ vertices. Use $dp[i][j][n] = \min_{V_k\text{ adjacent to } V_i} (e_{ik}+dp[k][j][n-1], dp[i][j][n-1])$ to compute all values of $dp[i][j][n]$. This … Read more

Find the minimum edge size, L, that would allow the construction of a tree whose edges connect all given 2-d points, but no edge exceeds length L

Given a set of points in the 2-d plane, find the minimum edge size, L, that would allow the construction of a tree whose edges connect all given points, but no edge exceeds length L. Here is an algorithm, which I think might work but seems slow: Pick a random point find the distance of … Read more

Concurrent Shortest Paths with “Congestion Penalty”

Given a graph with positive edge weight representing “time to travel through”, and 2 or more pairs of start/end vertices, we can find concurrent paths for the pairs such that the maximum cumulative weight along any path is minimum, using classic shortest path algorithms. Now what if the weight is not static, but represents “congestion … Read more

How can I implement locking a range of values in a sorted sequence?

I am trying to write a general purpose locking algorithm which allows me to lock a range of contiguous values in a sorted array. To start with, these could be exclusive locks – so two concurrent locks must be non-overlapping. What could be a good, scalable algorithm to do this? (Scalable ~ concurrent) A specific … Read more

Can you use CPS to simulate state in a stateless programming language?

In a language supporting CPS, but no built in global state, we can represent a state based computation using a function. We call this function a state function. Assume the function takes three arguments, get, put, and cont. The intended interpretation of these functions is that get takes a continuation, and applies that continuation to … Read more

Point rank in 2D plane time complexity?

I’m reading about the algorithm of finding the ranks of all points in a 2D plane, I don’t understand the time complexity formula for it. It has four steps: Compute the median of x-coordinates of all point, and divide the plane into two half Left, and Right. Recursively do 1. then when there is only … Read more

An algorithm for getting the position index

Consider these two equation. m1+m2+m3+m4=Mm|m1|+|m2|+|m3|+|m4|=Nm where {mi,Mm,Nm}∈Z. Given the value of (Nm,Mm) we can find the different solutions for (m1,m2,m3,m4). The solutions are ordered in a particular way which is best explained by giving a few examples. For e.g. with (Nm=2,Mm=2) the solutions are {{0, 0, 0, 2}, {0, 0, 1, 1}, {0, 0, 2, … Read more