primPath Given a starting node, creates the minimum spanning tree path through a point configuration.

primPath(A, start)

Arguments

A

the distance matrix for which the minimum spanning tree path will be created

start

the starting node for the path

Value

return a 2x(n-1) matrix, where row 1 contains the parent nodes of the MST path, and row 2 contains the corresponding child nodes.

Details

Given a starting node, compute Prim's algorithm, resulting in the path taken to construct the minimum spanning tree.

Examples

A <- dist(cbind(rnorm(100,0,1),rnorm(100,0,1))) primPath(as.matrix(A),1)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] #> Parent 1 74 74 23 48 100 68 68 23 45 84 45 19 #> Kid 74 23 95 48 100 68 18 2 45 84 50 19 27 #> [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] #> Parent 27 100 54 36 39 36 25 25 6 70 84 90 #> Kid 54 92 36 39 57 25 70 6 31 99 90 28 #> [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] #> Parent 28 38 38 66 80 80 12 24 85 42 95 5 #> Kid 38 66 12 80 10 24 69 85 42 8 5 43 #> [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] #> Parent 43 26 58 47 59 59 88 56 33 33 71 22 #> Kid 26 58 47 59 86 88 56 33 22 71 78 14 #> [,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] #> Parent 14 89 98 98 51 49 49 13 30 73 13 76 #> Kid 89 98 34 51 49 91 13 30 73 76 75 3 #> [,62] [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] #> Parent 89 16 7 14 82 56 7 4 41 91 92 83 #> Kid 16 7 4 82 17 62 55 41 11 60 83 63 #> [,74] [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] #> Parent 63 37 3 3 94 67 97 67 65 5 32 44 #> Kid 37 64 87 94 67 97 15 65 96 32 44 9 #> [,86] [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] #> Parent 44 44 20 9 83 79 61 86 72 60 8 53 #> Kid 35 20 77 61 79 29 93 72 52 21 53 40 #> [,98] [,99] #> Parent 93 29 #> Kid 46 81
primPath(as.matrix(A),2)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] #> Parent 2 68 100 68 48 23 74 74 23 45 84 45 19 #> Kid 68 100 48 18 23 74 95 1 45 84 50 19 27 #> [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] #> Parent 27 100 54 36 39 36 25 25 6 70 84 90 #> Kid 54 92 36 39 57 25 70 6 31 99 90 28 #> [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] #> Parent 28 38 38 66 80 80 12 24 85 42 95 5 #> Kid 38 66 12 80 10 24 69 85 42 8 5 43 #> [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] #> Parent 43 26 58 47 59 59 88 56 33 33 71 22 #> Kid 26 58 47 59 86 88 56 33 22 71 78 14 #> [,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] #> Parent 14 89 98 98 51 49 49 13 30 73 13 76 #> Kid 89 98 34 51 49 91 13 30 73 76 75 3 #> [,62] [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] #> Parent 89 16 7 14 82 56 7 4 41 91 92 83 #> Kid 16 7 4 82 17 62 55 41 11 60 83 63 #> [,74] [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] #> Parent 63 37 3 3 94 67 97 67 65 5 32 44 #> Kid 37 64 87 94 67 97 15 65 96 32 44 9 #> [,86] [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] #> Parent 44 44 20 9 83 79 61 86 72 60 8 53 #> Kid 35 20 77 61 79 29 93 72 52 21 53 40 #> [,98] [,99] #> Parent 93 29 #> Kid 46 81