Union-Find or DFS: which one is better to find connected component?

The union-find algorithm is best suited for situations where the equivalence relationship is changing, i.e., there are “Union” operations which need to be performed on your set of partitions. Given a fixed undirected graph, you don’t have the equivalence relationships changing at all – the edges are all fixed. OTOH, if you have a graph … Read more

Algorithm for finding a Hamiltonian Path in a DAG

You can first topologically sort the DAG (every DAG can be topologically sorted) in O(n+m). Once this is done, you know that edge go from lower index vertices to higher. This means that there exists a Hamiltonian path if and only if there are edge between consecutive vertices, e.g. (1,2), (2,3), …, (n-1,n). (This is … Read more

What is the problem name for Traveling salesman problem(TSP) without considering going back to starting point?

I’ve found the answer to my question in this book. It is the same with Computer wiring problem which occurs repeatedly in the design of computers and other digital systems. The purpose is to minimize the total wire length. So, it is indeed a minimum length Hamiltonian path. What the book suggests is to create … Read more

Relaxation of an edge in Dijkstra’s algorithm

Here’s a nice description of the Algorithm that also explains the notion of relaxation. The notion of “relaxation” comes from an analogy between the estimate of the shortest path and the length of a helical tension spring, which is not designed for compression. Initially, the cost of the shortest path is an overestimate, likened to … Read more

A* Algorithm for very large graphs, any thoughts on caching shortcuts?

You should be able to make it much faster by trading off optimality. See Admissibility and optimality on wikipedia. The idea is to use an epsilon value which will lead to a solution no worse than 1 + epsilon times the optimal path, but which will cause fewer nodes to be considered by the algorithm. … Read more

Comparing object graph representation to adjacency list and matrix representations

objects and pointers These are just basic datastructures like hammar said in the other answer, in Java you would represent this with classes like edges and vertices. For example an edge connects two vertices and can either be directed or undirected and it can contain a weight. A vertex can have an ID, name etc. … Read more

Why does Dijkstra’s algorithm use decrease-key?

The reason for using decrease-key rather than reinserting nodes is to keep the number of nodes in the priority queue small, thus keeping the total number of priority queue dequeues small and the cost of each priority queue balance low. In an implementation of Dijkstra’s algorithm that reinserts nodes into the priority queue with their … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)