Skip to content

Commit a71de21

Browse files
authored
Update README with correct math markdown
1 parent 5f99397 commit a71de21

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

bonus-assignment/README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# K-Minimum Spanning Tree - Bonus Assignment
22
## Description
3-
This project given n points in the
4-
two-dimensional space and a positive integer k (k<=n),
5-
constructs a tree spanning at least k of
6-
these points such that the total length of the tree is at most O(k ^(1/4))
7-
times that of a minimum-length tree spanning any k of the points.
3+
This project given $n$ points in the
4+
two-dimensional space and a positive integer $k$ $(k<=n) $,
5+
constructs a tree spanning at least $k$ of
6+
these points such that the total length of the tree is at most $O(k ^{1/4} )$
7+
times that of a minimum-length tree spanning any $k$ of the points.
88
In the best case the minimum tree constructed consists of
9-
exactly k points. If that is not possible the tree will
10-
consist of k+m points where m>0 and k+m<n and m the least integer so that the square root
11-
of (k+m) has no decimal places (root (k+m) is an integer).
9+
exactly $k$ points. If that is not possible the tree will
10+
consist of $k+m$ points where $m>0$ and $k+m < n$ and $m$ the least integer so that the square root
11+
of $(k+m)$ has no decimal places ( $\sqrt{k+m}$ is an integer).
1212
Lastly, in the worst case scenario if there is no such number
13-
as m, the minimum spanning tree will consist of exactly n points.
13+
as $m$, the minimum spanning tree will consist of exactly $n$ points.
1414
The output of the project describes the number of points that the
1515
MST (minimum-spanning tree) consists of, the length of the MST
16-
( the sum of distances of all the connections used in the MST)
16+
(the sum of distances of all the connections used in the MST)
1717
and finally the connections of the points that are used to construct
1818
the MST. Full description is found [here](https://github.com/stef4k/Algorithms-and-data-structures-assignments2019/blob/main/bonus-assignment/ravi1996.pdf)
1919

@@ -32,37 +32,37 @@ have a good chance of containing oil under the sea bed. The company has a limite
3232
number of oil rigs that it is willing to invest in the effort. The problem is to position
3333
these oil rigs at marked places so that the cost of laying down pipelines between these
3434
rigs is minimized. The problem at hand can be modeled as follows: given a graph with
35-
nonnegative edge weights and a specified number k, find a tree of minimum weight
36-
spanning at least k nodes. The solution to the problem will be a tree spanning
37-
exactly k nodes. This problem is called the k-minimum spanning tree (kMST).
35+
nonnegative edge weights and a specified number $k$, find a tree of minimum weight
36+
spanning at least $k$ nodes. The solution to the problem will be a tree spanning
37+
exactly $k$ nodes. This problem is called the k-minimum spanning tree (kMST).
3838

3939
## Algorithm
40-
Before calculations start, k is checked if it has a square root without any decimal places. If not, k is continuously
41-
increased till it becomes an integer whose square root has no decimal places or till it becomes equal to n . In those cases, k will be changed.
40+
Before calculations start, $k$ is checked if it has a square root without any decimal places. If not, $k$ is continuously
41+
increased till it becomes an integer whose square root has no decimal places or till it becomes equal to $n$. In those cases, $k$ will be changed.
4242

43-
If k is equal to n, there will be only one MST (the one that contains all the n points). As a result, the MST of the n points
43+
If $k$ is equal to $n$, there will be only one MST (the one that contains all the $n$ points). As a result, the MST of the $n$ points
4444
is constructed by using the Prim's algorithm for finding minimum spanning trees. Via the MST, the length of the tree is calculated
4545
and the appropriate output is made.
4646

47-
In any other case ( it will be: k < n ), the right k points must be estimated in order to find the MST for those k points. Let's
48-
call S={s1,s2,...,sn} the given set of points and d(i,j) the Euclidean distance between si and sj. In order to find
49-
the right k points and followingly the MST, the following steps must be pursued, for each distinct pair of points si, sj in S:
50-
1. Construct the circle C with diameter D = root(3) * d(i, j) centered at the
47+
In any other case ( it will be: $k < n$ ), the right $k$ points must be estimated in order to find the MST for those $k$ points. Let's
48+
call $S={s1,s2,...,sn}$ the given set of points and $d(i,j)$ the Euclidean distance between si and sj. In order to find
49+
the right $k$ points and followingly the MST, the following steps must be pursued, for each distinct pair of points si, sj in S:
50+
1. Construct the circle C with diameter $D = \sqrt{3} * d(i, j)$ centered at the
5151
midpoint of the line segment (si, sj)
5252
2. Let Sc be the subset of S contained in C. If Sc contains fewer than
53-
k points, skip to the next iteration of the loop (i.e., try the next pair of
53+
$k$ points, skip to the next iteration of the loop (i.e., try the next pair of
5454
points). Otherwise, do the following.
5555
3. Let Q be the square of side D circumscribing C.
56-
4. Divide Q into k square cells each with side = D / root(k)
56+
4. Divide Q into $k$ square cells each with $side = D / \sqrt{k}$
5757
5. Sort the cells by the number of points from Sc they contain and
5858
choose the minimum number of cells so that the chosen cells together
59-
contain at least k points. In case there are more than k points in the chosen cells, randomly discard points from
59+
contain at least $k$ points. In case there are more than $k$ points in the chosen cells, randomly discard points from
6060
the last chosen cell so that the total number of points in all the cells is
61-
equal to k.
62-
6. Construct a minimum spanning tree for the k chosen points.
63-
7. The solution value for the pair (si, sj) is the length of this MST.
61+
equal to $k$.
62+
6. Construct a minimum spanning tree for the $k$ chosen points.
63+
7. The solution value for the pair $(si, sj)$ is the length of this MST.
6464

65-
From all the distinct pairs select the pair with the minimum length of its MST. That MST is the soltuion and together with the length and the connections,
65+
From all the distinct pairs select the pair with the minimum length of its MST. That MST is the solution and together with the length and the connections,
6666
the appropriate output is made.
6767

6868

@@ -92,11 +92,11 @@ pointn (abscissan, ordinaten)
9292
9393
```
9494

95-
* <k_number> is the minimum integer number of points that the tree will span, so the following must be valid: k_number > 1 and k_number <=n
95+
* <k_number> is the minimum integer number of points that the tree will span, so the following must be valid: $knumber > 1$ and $knumber <=n$
9696

9797
## Examples
9898
### Example 1
99-
* Running the file points1.txt for k=4
99+
* Running the file points1.txt for $k=4$
100100
```
101101
python kmst.py points1.txt 4
102102
```
@@ -108,9 +108,9 @@ The links that were used are:
108108
('s5', 's7'): 1.0,
109109
('s7', 's6'): 1.4142135623730951}
110110
```
111-
In conlusion, it is noticed that the k we inputed has a square root without decimal places (root(4)=2), as a result the MST contains exactly 4 points.
111+
In conlusion, it is noticed that the k we inputed has a square root without decimal places $(\sqrt{4} = 2)$, as a result the MST contains exactly 4 points.
112112

113-
* Running the file points1.txt for k=5
113+
* Running the file points1.txt for $k=5$
114114
```
115115
python kmst.py points1.txt 5
116116
```
@@ -131,7 +131,7 @@ In conclusion, it is noticable that the MST that is constructed contains 9 point
131131
As a result, k is transformed into 9 whose root equals to 3.
132132

133133
### Example 2
134-
* Running the file points2.txt for k=7
134+
* Running the file points2.txt for $k=7$
135135
```
136136
python kmst.py points2.txt 7
137137
```
@@ -150,7 +150,7 @@ The links that were used are:
150150
```
151151
To sum up, k is changed from 7 to 9 and the MST for 9 points is calculated.
152152

153-
* Running the file points2.txt for k=16
153+
* Running the file points2.txt for $k=16$
154154
```
155155
python kmst.py points2.txt 16
156156
```
@@ -178,7 +178,7 @@ Last but not least, k is not changed because square root of 16 equals to 4. As a
178178
its length is found.
179179

180180
### Example 3
181-
Running the file points4.txt for k=16
181+
Running the file points4.txt for $k=16$
182182
```
183183
python kmst.py points4.txt 16
184184
```

0 commit comments

Comments
 (0)