The problem:
We have a weighted graph $G=(V, E, W)$ with $|V| = n$, $|E| = n-1$ and $W$ is set of edge's weight. The graph $G$ includes one ring on $n_1 \geq 3$ nodes and $n_2$ isolated nodes, $n_1+ n_2 = n$.
We want to connect isolated nodes to the ring using an edge weight (euclidean distance between nodes and edges) as the feature for connection. The ring's weight must be minimal.
Algorithm
- select an edge $(u,v) \in E$
- match to the edge $(u,v)$ the minimum distance to isolated nodes (this is an edge's weight)
- repeat steps 1-2 for all edges
- find the edge $(u,v)_{\min}$ with the global minimum weight $\arg \min_{(u,v) \in E} W$
- connect the head $u$ and tail $v$ of specifited edge $(u,v)_{\min}$ with the corresponded isolated node $a$ by adding two edges $(u,a)$ and $(a,v)$
- delete the edge $(u,v)_{\min}$ from the triangle $\{(u,a), (a,v), (v,u)\} \subset E$
- repeat steps the 1-5 while the set of isolated nodes is not empty.
In the wortest case on step 4 we can have more one edges (some edges can have the same weight) and we can randomly select one of them. But we need to store weight of non-used edges for the possible back propogation on the next steps.
Problem. How to estimate the computation complexity of the proposed algorithm?
My attemp is:
- $n$ elementary operations
- $n_2$ elementary operations
- $n \cdot (n-1)$ elementary operations
- $n^2/2 - n$ elementary operations, if $W$ is simmetric matrix with zero diagonal and all elements are different on all steps (one choice)
- $2$ elementary operations
- $1$ elementary operation
- $n$ elementary operations
The complexity is $O(n^2)$.