Developing a linear time algorithm to traverse a graph - algorithm

I'm going through an algorithms textbook to improve my algorithm skills but I'm completely stuck on this question and it's bugging me. I think the underlying data structure is a graph but I don't even know where to begin with this problem. Can anyone give some insight? Thanks
You are given a topographical map that provides the maximum altitude
along the direct road between any two neighboring cities, and two
cities a and b. Come up with an a linear time algorithm that finds a
route from s to t that minimizes the maximum altitude. Roads can be
traversed in both directions.

This is a tricky question. I would assume that there are some hints in the chapter that are supposed to guide you towards the solution.
The problem you are describing is an instance of the minimax path problem, or widest path problem.
http://en.wikipedia.org/wiki/Widest_path_problem
According to wikipedia, there is a linear time algorithm, but it is pretty complicated, so I doubt the book expects you to figure that out. The simpler way to solve this problem is to find a minimum spanning tree. Due to the "min cut" property of a minimum spanning tree, the path connecting a and b along a minimum spanning tree will have the minimax property, meaning that the maximum altitude along this path will be the minimum of any path connecting a to b.
However, there is no linear time minimum spanning tree algorithm. On the other hand, if we can assume that the graph is planar -- which we probably can since it is a road map -- then it is possible to find a minimum spanning tree in linear time. So I think this is what they might be after. Does the chapter containing this problem talk about minimum spanning trees and/or planar graphs?

Related

How to build a Minimum Spanning Tree given a list of 200 000 nodes?

Problem
I have a list of approximatly 200000 nodes that represent lat/lon position in a city and I have to compute the Minimum Spanning Tree. I know that I need to use Prim algorithm but first of all I need a connected graph. (We can assume that those nodes are in a Euclidian plan)
To build this connected graph I thought firstly to compute the complete graph but (205000*(205000-1)/2 is around 19 billions edges and I can't handle that.
Options
Then I came across to Delaunay triangulation: with the fact that if I build this "Delauney graph", it contains a sub graph that is the Minimum Spanning Tree according and I have a total of around 600000 edges according to Wikipedia [..]it has at most 3n-6 edges. So it may be a good starting point for a Minimum Spanning Tree algorithm.
Another options is to build an approximately connected graph but with that I will maybe miss important edges that will influence my Minimum Spanning Tree.
My question
Is Delaunay a reliable solution in this case? If so, is there any other reliable solution than delaunay triangulation to this problem ?
Further information: this problem has to be solved in C.
The Delaunay triangulation of a point set is always a superset of the EMST of these points. So it is absolutely "reliable"*. And recommended, as it has a size linear in the number of points and can be efficiently built.
*When there are cocircular point quadruples, neither the triangulation nor the EMST are uniquely defined, but this is usually harmless.
There's a big question here of what libraries you have access to and how much you trust yourself as a coder. (I'm assuming the fact that you're new on SO should not be taken as a measure of your overall experience as a programmer - if it is, well, RIP.)
If we assume you don't have access to Delaunay and can't implement it yourself, minimum spanning trees algorithms that pre-suppose a graph aren't necessarily off limits to you. You can have the complete graph conceptually but not actually. Kruskal's algorithm, for instance, assumes you have a sorted list of all edges in your graph; most of your edges will not be near the minimum, and you do not have to compare all n^2 to find the minimum.
You can find minimum edges quickly by estimations that give you a reduced set, then refinement. For instance, if you divide your graph into a 100*100 grid, for any point p in the graph, points in the same grid square as p are guaranteed to be closer than points three or more squares away. This gives a much smaller set of points you have to compare to safely know you've found the closest.
It still won't be easy, but that might be easier than Delaunay.

Minimum number of cameras required to cover all nodes in graph

I came across a problem in leetcode named "Binary Tree Camera".
I was wondering how to approach this similar problem:-
You have to place cameras at nodes of a graph such that whole graph is covered. A camera on a node monitors all its immediate neighbour nodes and itself. Find the minimum number of cameras required to cover all nodes.
This is a set cover problem, which there are many well-known algorithms for. To model it as an instance of the set cover problem, map each node to the set of nodes which a camera at that node would cover. The original problem of choosing the fewest number of nodes is equivalent to choosing the fewest number of those sets.
In general, this is an "NP Hard" problem, meaning there is no known algorithm which always gives the minimum covering and also scales well to large instances of the problem. Since the problem asks for the minimum, a heuristic algorithm is not suitable, so you will need to do something like a backtracking search.
This problem is called the Minimum Dominating Set and is NP-hard for the general graph case. Algorithms exist that approach this problem by either approximation, parameterization or restricting the class of graphs. See the Wikipedia link for details.

Minimal spanning tree with K extra node

Assume we're given a graph on a 2D-plane with n nodes and edge between each pair of nodes, having a weight equal to a euclidean distance. The initial problem is to find MST of this graph and it's quite clear how to solve that using Prim's or Kruskal's algorithm.
Now let's say we have k extra nodes, which we can place in any integer point on our 2D-plane. The problem is to find locations for these nodes so as new graph has the smallest possible MST, if it is not necessary to use all of these extra nodes.
It is obviously impossible to find the exact solution (in poly-time), but the goal is to find the best approximate one (which can be found within 1 sec). Maybe you can come up with some hints of the most efficient way of going throw possible solutions, or provide with some articles, where the similar problem is covered.
It is very interesting problem which you are working on. You have many options to attack this problem. The best known heuristics in such situation are - Genetic Algorithms, Particle Swarm Optimization, Differential Evolution and many others of this kind.
What is nice for such kind of heuristics is that you can limit their execution to a certain amount of time (let say 1 second). If it was my task to do I would try first Genetic Algorithms.
You could try with a greedy algorithm, try the longest edges in the MST, potentially these could give the largest savings.
Select the longest edge, now get the potential edge from each vertex that are closed in angle to the chosen one, from each side.
from these select the best Steiner point.
Fix the MST ...
repeat until 1 sec is gone.
The challenge is what to do if one of the vertexes is itself a Steiner point.

Shortest path to connect n points

I have n points and I need to connect all of them minimizing the final distance. The image above represents an algorithm that in each node it connects to the nearest one but the final output might be really of.
I've been searching a lot, I know some pathfinding algos but unaware of one that solves exactly this case. I found a question on Math Stackexchange but the answer is not providing any algorithm - https://math.stackexchange.com/a/581844/156584.
Is there any algorithm that solves exactly this problem? Otherwise I can bruteforce it.
Edit: Some clarification regarding the result I'm expecting: each node can be connected to 2 other nodes, creating a continuous path (like taking a pen and without ever lifting it, connect the nodes minimizing the final distance). I don't want to create a cycle (that being the travelling salesman problem).
PS: this question can also be translated to "complete graph with n vertices, and wanting to choose the set of edges such that the graph is connected, but the sum of the edge weights is minimized"
This problem is known as the shortest Hamiltonian path problem and it is NP-hard. So if the number of points is small, you can use backtracking or dynamic programming to find an optimal solution. If the number of points is large, you can use heuristics and/or approximations to obtain a relatively good answer(it is not always possible to find the best one in this case, though).

Do minimum depth, spanning trees algorithms exist?

I'm currently optimizing electrical grid planning and the MST doesn't solve the problem well, because if the connection to the main grid is in a radial point all the power has to flow through one edge and will travel a long "electrical distance" to every consumption point.
The problem I'm looking at could be minimizing the MW*distance or active power moment, but that creates a non-linear problem.
So what I want to find is a minimum spanning tree (not the optimal, just most efficient) that minimizes the maximum electrical distance (distance through the graph) to the tree root.
In this way I just buy longer thinner cables that is a cheaper solution to shorter thicker cables.
In this case, you don't want a minimum spanning tree. You want a shortest path tree, which is a spanning tree minimizing the distance from each point in the graph back to the source node. Any standard shortest-path algorithm can be modified to produce a shortest-path tree. For example, a standard implementation of Dijkstra's algorithm can produce such a tree.
That said... shortest path trees are not guaranteed to be cheap, and it's possible to construct graphs where shortest path trees are significantly more expensive than the corresponding minimum spanning tree. In other words, you might have to pay significantly more money to build a shortest path tree than a minimum-spanning tree.
There has been some research into algorithms for finding spanning trees that are good compromises between an MST (minimum total weight) and shortest-path trees (minimum distances to each node), though unfortunately I can't remember off the top of my head where to look to find this.
Hope this helps!
This looks like it is just minimum spanning tree with some extra conditions. Something like Prim's will work.
give a weight to each node to account for consumption at each point. You should end up with a connection between the central node and each outlying node that has the shortest length while also avoiding sending power through too many different nodes.

Resources