how to find out a MST of a given graph, which must include the edges from set A - greedy

Given a graph G = (V,E) and a set of edges A(which is a subset of E)
How to find a minimum spanning tree that must include the edges in A?

Related

When calculating Manhattan Distance, should you calculate distance to end point or start point?

I'm trying to learn the A* algorithm (when applied to a grid pattern) and think I have grasped that before you can find the shortest path, you need to calculate the distance away from the start for any given square.
I'm following the guide here: https://medium.com/#nicholas.w.swift/easy-a-star-pathfinding-7e6689c7f7b2 which has the following image showing the Manhattan distances for each square on the grid:
with the start square being the green square and the end being the blue.
However, surely it makes more sense to figure the distance in reverse? The A* chooses the connected square with the shortest distance to the goal right? So surely this (based on the image) would make sense if we started at the end and asked what's the lowest value connected to the start, in this case 17, so go there, then 15 so go there etc etc.
Sub question: The distances in the image away from the start appear to be based on moving through Von Neumann neighbours, so surely on the way back you cannot go diagonally?
It is quite simple actually:
F = G + H
F is the total cost of the node.
G is the distance between the current node and the start node.
H is the heuristic — estimated distance from the current node to the end node.
The numbers in the grid represent G (and not the heuristic). G is the actual distance from the start point.
H should be calculated to the endpoint.

How can I calculate center of mass after floodfill?

I have an image like this one
with 3 distinct regions. Using a breath first 4 neighbor queue, I have implemented a basic flood fill that distinguishes between the 3.
Now I need to find the center of mass of these regions with each pixel weighing one unit of weight.
Whats the best way of going about that?
The simplest way is to keep three arrays, sumx, sumy and count, each with one entry per label (3 in your case), and all initialized to 0. Then run through the image once, and for each labeled pixel add the x coordinate to the corresponding bin in sumx, the y coordinate to the corresponding bin in sumy, and 1 to the corresponding bin in count.
At the end, for each label l you can compute sumx[l]/count[l] and sumy[l]/count[l]. These are the unweighted centers of gravity (centroids).

Minimum cost to connect components of a disconnected graph?

We are initially given a fully connected graph by means of an adjacency matrix. Then, some edges are removed such that the graph becomes disconnected and we now have multiple components of this disconnected graph. What is the minimum cost needed to connect all the components?
Let G = (V, E_1 ∪ E_2) be the original (weighted, fully connected) graph and G' = (V, E_1) the graph obtained by removing the edges in the set E_2.
Consider the graph G'' that is obtained by contracting the connected components of G' (i.e., each connected component becomes a single vertex), where two vertices of G'' are neighbours if and only if the corresponding connected components in G' were connected by an edge in E_2. Essentially, this means that the edges of G'' are the edges in the set E_2 (the edges that were removed from the original graph).
Observe that adding a subset of the edges from E_2 to G' restores (full) connectivity of G' if and only if these edges connect all vertices from G''. The cheapest way to do this is by selecting a min-cost spanning tree on G'' (with respect to the weights of the edges). From your comments, I assume you know what a minimum spanning tree is and how it can be computed.
One-sentence-summary:
A cost-minimal set of edges that is needed to restore connectivity can be found by computing a minimum (cost) spanning tree on the graph that is obtained by contracting each of the connected components into a single vertex and that contains, as its edge set, the edges that were removed from the original graph.

r-tree how to calculate minimum bounding rectangles of non leaf nodes

I have many building footprints and want to store them in a r-tree structure.I want to understand that in a r-tree structure leaf nodes are minimum bounding rectangles (MBR) of real objects, in my case building footprints. But I could not understand how MBRs of non leaf nodes can be calculated and I want to know how can it be done (In the picture Green boxes). I suppose there are many possible solution but I just want to know only one of them.
The bounding boxes of inner nodes are computed exactly the same way as for leaf nodes.
You need the minimum and maximum in each axis.
The MBR of a non-leaf node is the union of its children nodes (can be leaf or non-leaf nodes) so that it is the bounding box of offspring data.
Take the two-dimensional example in your picture, suppose the children nodes A(X_amin, X_amax, Y_amin, Y_amax) and B(X_bmin, X_bmax, Y_bmin, Y_bmax), the non-leaf parent node is N(min(X_amin, X_bmin), max(X_amax, X_bmax), min(Y_amin, Y_bmin), max(Y_amax, Y_bmax)).

How to determine area of MKMapRect with greatest concentration of MKAnnotation objects?

Given an MKMapView that contains a variable amount of annotations ([mapView annotations]) at various points on the map and the MKMapRect value MKMapRectWorld, how can I determine an area on the map that has the greatest concentration on MKAnnotation objects (perhaps the 5-15 annotations closest to one another) ?
Example scenarios:
* Coffee finder: Determine which area of the map has the most Starbucks
* K9 statistics: Determine which area of the map has the most Cocker Spaniels
The "area" could be a set rect size or determined by a block of annotations, I don't necessarily care. Thanks for your help!
You will find related question helpful.
Also take look at K-means_algorithm
K-means_algorithm
If you have N annotations and want to break into K parts you can find center (which will fill certain criteria. e.g. minimize the within-cluster sum of squares ) of each of K parts with K-means-algorithm. Once you have center find out distance between center and annotation farthest from center it will give radius of region you are interested. There are several variations of K-means_algorithm, you can choose whichever based on performance and ease of implementation.
EDIT:
I have not implemented following, but think will definitely give one of solution
If you are OK with range 5-10, there can be multiple solutions. So we will find one of solution.
1- Say you have (N=100) annotations and want which (P =15) of them are most located densely.
2- Then we will divide N annotations in K = N/P groups(here K = 7) randomly
3- Use K-means algorithm so that finally we will have K groups that can be differentiated as separate entities.
4- These K groups will have property of minimum " within-cluster sum of squares".
5- If you want to save computational time, you can relax definition of most concentrated group as minimum "within-cluster sum of squares" as opposed to area bounded by them.
6- select a group from obtained K group that satisfies your criteria.
7- If want to persist to minimum area(greatest concentration) definition then you will need to do lots of computation
a. First determine boundary annotations of given group, which itself a huge problem.
b. calculate are of each polygon and see which is least. not complicated but computationally demanding)
EDIT2:
I tried whatever I can and finally thought it this question belongs to specialist math website. I asked your question here and from the answer , you can get paper discussing this problem and solution here. Problem they discuss is given N points, find the K points whose area of convex hull is minimum.

Resources