diff --git a/content/posts/2024-07-20-treap/index.md b/content/posts/2024-07-20-treap/index.md new file mode 100644 index 0000000..cd7fe79 --- /dev/null +++ b/content/posts/2024-07-20-treap/index.md @@ -0,0 +1,159 @@ +--- +title: "Treap" +date: 2024-07-20T14:12:27+01:00 +draft: false # I don't care for draft mode, git has branches for that +description: "A simpler BST" +tags: + - algorithms + - data structures + - python +categories: + - programming +series: +- Cool algorithms +favorite: false +disable_feed: false +graphviz: true +--- + +The [_Treap_][wiki] is a mix between a _Binary Search Tree_ and a _Heap_. + +Like a _Binary Search Tree_, it keeps an ordered set of keys in the shape of a +tree, allowing for binary search traversal. + +Like a _Heap_, it associates each node with a priority, making sure that a +parent's priority is always higher than any of its children. + +[wiki]: https://en.wikipedia.org/wiki/Treap + + + +## What does it do? + +By randomizing the priority value of each key at insertion time, we ensure a +high likelihook that the tree stays _roughly_ balanced, avoiding degenerating to +unbalanced O(N) height. + +Here's a sample tree created by inserting integers from 0 to 250 into the tree: + +{{< graphviz file="treap.gv" />}} + +## Implementation + +I'll be keeping the theme for this [series] by using Python to implement the +_Treap_. This leads to somewhat annoying code to handle the `left`/`right` nodes +which is easier to do in C, using pointers. + +[series]: {{< ref "/series/cool-algorithms/" >}} + +### Representation + +Creating a new `Treap` is easy: the tree starts off empty, waiting for new nodes +to insert. + +Each `Node` must keep track of the `key`, the mapped `value`, and the node's +`priority` (which is assigned randomly). Finally it must also allow for storing +two children (`left` and `right`). + +```python +class Node[K, V]: + key: K + value: V + priority: float + left: Node[K, V] | None + righg: Node[K, V] | None + + def __init__(self, key: K, value: V): + # Store key and value, like a normal BST node + self.key = key + self.value = value + # Priority is derived randomly + self.priority = random() + self.left = None + self.right = None + +class Treap[K, V]: + _root: Node[K, V] | None + + def __init__(self): + # The tree starts out empty + self._root = None +``` + +### Search + +Searching the tree is the same as in any other _Binary Search Tree_. + +```python +def get(self, key: K) -> T | None: + node = self._root + # The usual BST traversal + while node is not None: + if node.key == key: + return node.value + elif node.key < key: + node = node.right + else: + node = node.left + return None +``` + +### Insertion + +To insert a new `key` into the tree, we identify which leaf position it should +be inserted at. We then generate the node's priority, insert it at this +position, and rotate the node upwards until the heap property is respected. + +```python +type ChildField = Literal["left, right"] + +def insert(self, key: K, value: V) -> bool: + # Empty treap base-case + if self._root is None: + self._root = Node(key, value) + # Signal that we're not overwriting the value + return False + # Keep track of the parent chain for rotation after insertion + parents = [] + node = self._root + while node is not None: + # Insert a pre-existing key + if node.key == key: + node.value = value + return True + # Go down the tree, keep track of the path through the tree + field = "left" if key < node.key else "right" + parents.append((node, field)) + node = getattr(node, field) + # Key wasn't found, we're inserting a new node + child = Node(key, value) + parent, field = parents[-1] + setattr(parent, field, child) + # Rotate the new node up until we respect the decreasing priority property + self._rotate_up(child, parents) + # Key wasn't found, signal that we inserted a new node + return False + +def _rotate_up( + self, + node: Node[K, V], + parents: list[tuple[Node[K, V], ChildField]], +) -> None: + while parents: + parent, field = parents.pop() + # If the parent has higher priority, we're done rotating + if parent.priority >= node.priority: + break + # Check for grand-parent/root of tree edge-case + if parents: + # Update grand-parent to point to the new rotated node + grand_parent, field = parents[-1] + setattr(grand_parent, field, node) + else: + # Point the root to the new rotated node + self._root = node + other_field = "left" if field == "right" else "right" + # Rotate the node up + setattr(parent, field, getattr(node, other_field)) + setattr(node, other_field, parent) +``` diff --git a/content/posts/2024-07-20-treap/treap.gv b/content/posts/2024-07-20-treap/treap.gv new file mode 100644 index 0000000..156eff9 --- /dev/null +++ b/content/posts/2024-07-20-treap/treap.gv @@ -0,0 +1,1004 @@ +graph { + node [shape=circle] + 2[label=<2
0.9957869495270144>]; + 2 -- 1 [side=L] + 1[label=<1
0.8476937427586738>]; + 1 -- 0 [side=L] + 0[label=<0
0.7514570833207395>]; + 2 -- 145 [side=R] + 145[label=<145
0.9939888728473314>]; + 145 -- 12 [side=L] + 12[label=<12
0.9907319285760915>]; + 12 -- 5 [side=L] + 5[label=<5
0.988082370881665>]; + 5 -- 4 [side=L] + 4[label=<4
0.7422137887388395>]; + 4 -- 3 [side=L] + 3[label=<3
0.24440218394323976>]; + 5 -- 8 [side=R] + 8[label=<8
0.695547503791194>]; + 8 -- 6 [side=L] + 6[label=<6
0.5664414792316717>]; + 6 -- 7 [side=R] + 7[label=<7
0.11672897928969816>]; + 8 -- 11 [side=R] + 11[label=<11
0.45404068759973704>]; + 11 -- 9 [side=L] + 9[label=<9
0.3325186970255505>]; + 9 -- 10 [side=R] + 10[label=<10
0.10578109016044712>]; + 12 -- 47 [side=R] + 47[label=<47
0.9904839559513964>]; + 47 -- 33 [side=L] + 33[label=<33
0.9758188259688814>]; + 33 -- 28 [side=L] + 28[label=<28
0.915671870648212>]; + 28 -- 23 [side=L] + 23[label=<23
0.8487360320264957>]; + 23 -- 20 [side=L] + 20[label=<20
0.7063809958484802>]; + 20 -- 16 [side=L] + 16[label=<16
0.7034299359160114>]; + 16 -- 15 [side=L] + 15[label=<15
0.5922634040068163>]; + 15 -- 13 [side=L] + 13[label=<13
0.4543498778672278>]; + 13 -- 14 [side=R] + 14[label=<14
0.21605966187340298>]; + 16 -- 17 [side=R] + 17[label=<17
0.3709284358038115>]; + 17 -- 18 [side=R] + 18[label=<18
0.260599350868457>]; + 18 -- 19 [side=R] + 19[label=<19
0.1817886048339078>]; + 20 -- 21 [side=R] + 21[label=<21
0.14210053829804103>]; + 21 -- 22 [side=R] + 22[label=<22
0.08869917426783513>]; + 23 -- 25 [side=R] + 25[label=<25
0.4892716208875628>]; + 25 -- 24 [side=L] + 24[label=<24
0.25363061372658946>]; + 25 -- 26 [side=R] + 26[label=<26
0.13796660931463622>]; + 26 -- 27 [side=R] + 27[label=<27
0.12997273552181765>]; + 28 -- 31 [side=R] + 31[label=<31
0.8601319422972336>]; + 31 -- 29 [side=L] + 29[label=<29
0.8084698172467167>]; + 29 -- 30 [side=R] + 30[label=<30
0.27908621178937176>]; + 31 -- 32 [side=R] + 32[label=<32
0.0844421977476495>]; + 33 -- 35 [side=R] + 35[label=<35
0.967049096465691>]; + 35 -- 34 [side=L] + 34[label=<34
0.12377873295631248>]; + 35 -- 39 [side=R] + 39[label=<39
0.9328169604588316>]; + 39 -- 38 [side=L] + 38[label=<38
0.7787222122657034>]; + 38 -- 37 [side=L] + 37[label=<37
0.4043690842717128>]; + 37 -- 36 [side=L] + 36[label=<36
0.3046740248996985>]; + 39 -- 43 [side=R] + 43[label=<43
0.8350649185763811>]; + 43 -- 40 [side=L] + 40[label=<40
0.5406537578359348>]; + 40 -- 42 [side=R] + 42[label=<42
0.3193437618727414>]; + 42 -- 41 [side=L] + 41[label=<41
0.27788504363715394>]; + 43 -- 44 [side=R] + 44[label=<44
0.4830145820991081>]; + 44 -- 46 [side=R] + 46[label=<46
0.33052118143151343>]; + 46 -- 45 [side=L] + 45[label=<45
0.29551968300055065>]; + 47 -- 114 [side=R] + 114[label=<114
0.9876511078116038>]; + 114 -- 86 [side=L] + 86[label=<86
0.9735379804960496>]; + 86 -- 77 [side=L] + 77[label=<77
0.9269342780771458>]; + 77 -- 68 [side=L] + 68[label=<68
0.9230582358699485>]; + 68 -- 55 [side=L] + 55[label=<55
0.839490204679298>]; + 55 -- 51 [side=L] + 51[label=<51
0.3385715557270519>]; + 51 -- 50 [side=L] + 50[label=<50
0.3360608605201836>]; + 50 -- 49 [side=L] + 49[label=<49
0.2774445142713422>]; + 49 -- 48 [side=L] + 48[label=<48
0.17489390663513982>]; + 51 -- 52 [side=R] + 52[label=<52
0.1886079446757799>]; + 52 -- 54 [side=R] + 54[label=<54
0.12293678964136756>]; + 54 -- 53 [side=L] + 53[label=<53
0.08266549169366844>]; + 55 -- 64 [side=R] + 64[label=<64
0.5480541758673416>]; + 64 -- 61 [side=L] + 61[label=<61
0.4333510895474586>]; + 61 -- 58 [side=L] + 58[label=<58
0.22965679673111572>]; + 58 -- 57 [side=L] + 57[label=<57
0.1750392554452569>]; + 57 -- 56 [side=L] + 56[label=<56
0.1154682181055644>]; + 58 -- 60 [side=R] + 60[label=<60
0.19505416228675265>]; + 60 -- 59 [side=L] + 59[label=<59
0.15628574332026035>]; + 61 -- 63 [side=R] + 63[label=<63
0.23625159275800722>]; + 63 -- 62 [side=L] + 62[label=<62
0.10778840213677576>]; + 64 -- 66 [side=R] + 66[label=<66
0.4795221664420316>]; + 66 -- 65 [side=L] + 65[label=<65
0.29689544767487486>]; + 66 -- 67 [side=R] + 67[label=<67
0.1446107813011439>]; + 68 -- 75 [side=R] + 75[label=<75
0.9136368186744673>]; + 75 -- 73 [side=L] + 73[label=<73
0.8180762618516633>]; + 73 -- 72 [side=L] + 72[label=<72
0.790052528538962>]; + 72 -- 69 [side=L] + 69[label=<69
0.6662534331501744>]; + 69 -- 70 [side=R] + 70[label=<70
0.198170103856931>]; + 70 -- 71 [side=R] + 71[label=<71
0.09798170568469355>]; + 73 -- 74 [side=R] + 74[label=<74
0.3113326781632004>]; + 75 -- 76 [side=R] + 76[label=<76
0.878956270284837>]; + 77 -- 84 [side=R] + 84[label=<84
0.7298827990732385>]; + 84 -- 81 [side=L] + 81[label=<81
0.7294243899593819>]; + 81 -- 78 [side=L] + 78[label=<78
0.6751780813023192>]; + 78 -- 80 [side=R] + 80[label=<80
0.2765792284019555>]; + 80 -- 79 [side=L] + 79[label=<79
0.12189576635143229>]; + 81 -- 83 [side=R] + 83[label=<83
0.5986915452921237>]; + 83 -- 82 [side=L] + 82[label=<82
0.5846092825823913>]; + 84 -- 85 [side=R] + 85[label=<85
0.5030186847252209>]; + 86 -- 103 [side=R] + 103[label=<103
0.968253245483458>]; + 103 -- 88 [side=L] + 88[label=<88
0.9609670084738324>]; + 88 -- 87 [side=L] + 87[label=<87
0.5446892558733331>]; + 88 -- 97 [side=R] + 97[label=<97
0.9483161815322799>]; + 97 -- 92 [side=L] + 92[label=<92
0.9417148997777522>]; + 92 -- 89 [side=L] + 89[label=<89
0.2455511319571373>]; + 89 -- 90 [side=R] + 90[label=<90
0.15647633602612276>]; + 90 -- 91 [side=R] + 91[label=<91
0.13997459061178652>]; + 92 -- 93 [side=R] + 93[label=<93
0.7804508194274744>]; + 93 -- 95 [side=R] + 95[label=<95
0.7226672256819942>]; + 95 -- 94 [side=L] + 94[label=<94
0.43503881905350683>]; + 95 -- 96 [side=R] + 96[label=<96
0.40712673636645136>]; + 97 -- 101 [side=R] + 101[label=<101
0.9255359833317219>]; + 101 -- 99 [side=L] + 99[label=<99
0.7139348283525223>]; + 99 -- 98 [side=L] + 98[label=<98
0.21279150783985867>]; + 99 -- 100 [side=R] + 100[label=<100
0.48002453571456083>]; + 101 -- 102 [side=R] + 102[label=<102
0.6219674393805691>]; + 103 -- 106 [side=R] + 106[label=<106
0.8731379458552129>]; + 106 -- 104 [side=L] + 104[label=<104
0.5400277589431796>]; + 104 -- 105 [side=R] + 105[label=<105
0.0007891566377928871>]; + 106 -- 110 [side=R] + 110[label=<110
0.8382929650437165>]; + 110 -- 109 [side=L] + 109[label=<109
0.4615149406437542>]; + 109 -- 107 [side=L] + 107[label=<107
0.43337904959817486>]; + 107 -- 108 [side=R] + 108[label=<108
0.053658620013432023>]; + 110 -- 112 [side=R] + 112[label=<112
0.5679810533328041>]; + 112 -- 111 [side=L] + 111[label=<111
0.541018763444613>]; + 112 -- 113 [side=R] + 113[label=<113
0.42841646768139463>]; + 114 -- 123 [side=R] + 123[label=<123
0.9464643826259924>]; + 123 -- 119 [side=L] + 119[label=<119
0.8662877311047388>]; + 119 -- 116 [side=L] + 116[label=<116
0.7670170824076343>]; + 116 -- 115 [side=L] + 115[label=<115
0.17190031141596263>]; + 116 -- 118 [side=R] + 118[label=<118
0.3671674221014496>]; + 118 -- 117 [side=L] + 117[label=<117
0.2159590427591035>]; + 119 -- 121 [side=R] + 121[label=<121
0.74738638353363>]; + 121 -- 120 [side=L] + 120[label=<120
0.08665916013292596>]; + 121 -- 122 [side=R] + 122[label=<122
0.4119543486009871>]; + 123 -- 143 [side=R] + 143[label=<143
0.9247442715890171>]; + 143 -- 140 [side=L] + 140[label=<140
0.8936337545064225>]; + 140 -- 125 [side=L] + 125[label=<125
0.8517904638602968>]; + 125 -- 124 [side=L] + 124[label=<124
0.681815353261336>]; + 125 -- 126 [side=R] + 126[label=<126
0.7946927108945189>]; + 126 -- 133 [side=R] + 133[label=<133
0.7289879153749418>]; + 133 -- 128 [side=L] + 128[label=<128
0.7256302169867033>]; + 128 -- 127 [side=L] + 127[label=<127
0.6200343851508556>]; + 128 -- 131 [side=R] + 131[label=<131
0.7089639682237622>]; + 131 -- 129 [side=L] + 129[label=<129
0.5255088944172916>]; + 129 -- 130 [side=R] + 130[label=<130
0.41550021924797953>]; + 131 -- 132 [side=R] + 132[label=<132
0.1851371011016204>]; + 133 -- 134 [side=R] + 134[label=<134
0.6333388625482715>]; + 134 -- 135 [side=R] + 135[label=<135
0.4707182839428111>]; + 135 -- 138 [side=R] + 138[label=<138
0.4128350639522185>]; + 138 -- 137 [side=L] + 137[label=<137
0.25475301393491523>]; + 137 -- 136 [side=L] + 136[label=<136
0.04841095612377411>]; + 138 -- 139 [side=R] + 139[label=<139
0.3855980374729622>]; + 140 -- 141 [side=R] + 141[label=<141
0.8655582249610275>]; + 141 -- 142 [side=R] + 142[label=<142
0.2288591915235536>]; + 143 -- 144 [side=R] + 144[label=<144
0.36710686055015185>]; + 145 -- 235 [side=R] + 235[label=<235
0.9812914040931304>]; + 235 -- 169 [side=L] + 169[label=<169
0.9782585107854103>]; + 169 -- 148 [side=L] + 148[label=<148
0.9449023406787344>]; + 148 -- 147 [side=L] + 147[label=<147
0.7293740098286456>]; + 147 -- 146 [side=L] + 146[label=<146
0.509027051210447>]; + 148 -- 150 [side=R] + 150[label=<150
0.9020436951014624>]; + 150 -- 149 [side=L] + 149[label=<149
0.8190200516813236>]; + 150 -- 153 [side=R] + 153[label=<153
0.8855777631108436>]; + 153 -- 152 [side=L] + 152[label=<152
0.8603376027563862>]; + 152 -- 151 [side=L] + 151[label=<151
0.45459695989529647>]; + 153 -- 167 [side=R] + 167[label=<167
0.8492899523613442>]; + 167 -- 163 [side=L] + 163[label=<163
0.8177575678069656>]; + 163 -- 160 [side=L] + 160[label=<160
0.7759852430212377>]; + 160 -- 158 [side=L] + 158[label=<158
0.734924251943539>]; + 158 -- 156 [side=L] + 156[label=<156
0.710110660084087>]; + 156 -- 155 [side=L] + 155[label=<155
0.2959097323390557>]; + 155 -- 154 [side=L] + 154[label=<154
0.23060113716089548>]; + 156 -- 157 [side=R] + 157[label=<157
0.04398748527099361>]; + 158 -- 159 [side=R] + 159[label=<159
0.09047000528918914>]; + 160 -- 162 [side=R] + 162[label=<162
0.7216878041963218>]; + 162 -- 161 [side=L] + 161[label=<161
0.6871202472393689>]; + 163 -- 165 [side=R] + 165[label=<165
0.3886140063494328>]; + 165 -- 164 [side=L] + 164[label=<164
0.3870484684485387>]; + 165 -- 166 [side=R] + 166[label=<166
0.3476475192762013>]; + 167 -- 168 [side=R] + 168[label=<168
0.8169397159175148>]; + 169 -- 172 [side=R] + 172[label=<172
0.9747928133504129>]; + 172 -- 170 [side=L] + 170[label=<170
0.846452976104617>]; + 170 -- 171 [side=R] + 171[label=<171
0.3121690933042578>]; + 172 -- 230 [side=R] + 230[label=<230
0.958355558453681>]; + 230 -- 187 [side=L] + 187[label=<187
0.957557676245447>]; + 187 -- 180 [side=L] + 180[label=<180
0.92710438449752>]; + 180 -- 174 [side=L] + 174[label=<174
0.7049973940003331>]; + 174 -- 173 [side=L] + 173[label=<173
0.152023809588824>]; + 174 -- 179 [side=R] + 179[label=<179
0.6715227532708304>]; + 179 -- 176 [side=L] + 176[label=<176
0.6621862385446002>]; + 176 -- 175 [side=L] + 175[label=<175
0.1248086920689816>]; + 176 -- 178 [side=R] + 178[label=<178
0.5713418767827186>]; + 178 -- 177 [side=L] + 177[label=<177
0.5560171098718876>]; + 180 -- 183 [side=R] + 183[label=<183
0.9250644230760526>]; + 183 -- 182 [side=L] + 182[label=<182
0.6824354777265715>]; + 182 -- 181 [side=L] + 181[label=<181
0.012508171868127804>]; + 183 -- 184 [side=R] + 184[label=<184
0.4823271793225655>]; + 184 -- 185 [side=R] + 185[label=<185
0.3841022310929997>]; + 185 -- 186 [side=R] + 186[label=<186
0.18775042542247533>]; + 187 -- 203 [side=R] + 203[label=<203
0.8944186382789656>]; + 203 -- 194 [side=L] + 194[label=<194
0.878541152511799>]; + 194 -- 190 [side=L] + 190[label=<190
0.6762694909925744>]; + 190 -- 188 [side=L] + 188[label=<188
0.3829541869540283>]; + 188 -- 189 [side=R] + 189[label=<189
0.20943675668859407>]; + 190 -- 192 [side=R] + 192[label=<192
0.5817469625147841>]; + 192 -- 191 [side=L] + 191[label=<191
0.09503744303386963>]; + 192 -- 193 [side=R] + 193[label=<193
0.3644771285875493>]; + 194 -- 197 [side=R] + 197[label=<197
0.7948407869124952>]; + 197 -- 195 [side=L] + 195[label=<195
0.7942811285510138>]; + 195 -- 196 [side=R] + 196[label=<196
0.5627582929517205>]; + 197 -- 202 [side=R] + 202[label=<202
0.6971384514391066>]; + 202 -- 198 [side=L] + 198[label=<198
0.6927264474372884>]; + 198 -- 200 [side=R] + 200[label=<200
0.6455091049085492>]; + 200 -- 199 [side=L] + 199[label=<199
0.5952913724552451>]; + 200 -- 201 [side=R] + 201[label=<201
0.02134082793304981>]; + 203 -- 222 [side=R] + 222[label=<222
0.7905661844403327>]; + 222 -- 221 [side=L] + 221[label=<221
0.7344461814842598>]; + 221 -- 218 [side=L] + 218[label=<218
0.710158738001777>]; + 218 -- 214 [side=L] + 214[label=<214
0.6681641416928006>]; + 214 -- 210 [side=L] + 210[label=<210
0.6445674840025054>]; + 210 -- 204 [side=L] + 204[label=<204
0.4613335241960753>]; + 204 -- 207 [side=R] + 207[label=<207
0.4534069998012402>]; + 207 -- 205 [side=L] + 205[label=<205
0.3958801765835097>]; + 205 -- 206 [side=R] + 206[label=<206
0.11317604266906478>]; + 207 -- 208 [side=R] + 208[label=<208
0.15215468537761012>]; + 208 -- 209 [side=R] + 209[label=<209
0.1517155863611125>]; + 210 -- 213 [side=R] + 213[label=<213
0.5254528847170963>]; + 213 -- 212 [side=L] + 212[label=<212
0.3831362875816451>]; + 212 -- 211 [side=L] + 211[label=<211
0.05056020282973139>]; + 214 -- 215 [side=R] + 215[label=<215
0.5009367015686823>]; + 215 -- 216 [side=R] + 216[label=<216
0.10901874828554337>]; + 216 -- 217 [side=R] + 217[label=<217
0.05646524838685241>]; + 218 -- 220 [side=R] + 220[label=<220
0.674411240175005>]; + 220 -- 219 [side=L] + 219[label=<219
0.14299197003272757>]; + 222 -- 223 [side=R] + 223[label=<223
0.6736901076540927>]; + 223 -- 226 [side=R] + 226[label=<226
0.6137254504515176>]; + 226 -- 225 [side=L] + 225[label=<225
0.42057192814517086>]; + 225 -- 224 [side=L] + 224[label=<224
0.15459807255670532>]; + 226 -- 227 [side=R] + 227[label=<227
0.3240860179195383>]; + 227 -- 229 [side=R] + 229[label=<229
0.1917962317572811>]; + 229 -- 228 [side=L] + 228[label=<228
0.09544487292662296>]; + 230 -- 231 [side=R] + 231[label=<231
0.9537855788342208>]; + 231 -- 234 [side=R] + 234[label=<234
0.8201857812416328>]; + 234 -- 233 [side=L] + 233[label=<233
0.38950247492509926>]; + 233 -- 232 [side=L] + 232[label=<232
0.3117950672088875>]; + 235 -- 245 [side=R] + 245[label=<245
0.9606326065278836>]; + 245 -- 243 [side=L] + 243[label=<243
0.9010055124673463>]; + 243 -- 237 [side=L] + 237[label=<237
0.8906258722253291>]; + 237 -- 236 [side=L] + 236[label=<236
0.699210568923407>]; + 237 -- 239 [side=R] + 239[label=<239
0.8460173468831691>]; + 239 -- 238 [side=L] + 238[label=<238
0.11026801706799916>]; + 239 -- 242 [side=R] + 242[label=<242
0.8439586286718704>]; + 242 -- 240 [side=L] + 240[label=<240
0.6602788030770246>]; + 240 -- 241 [side=R] + 241[label=<241
0.5119345141518413>]; + 243 -- 244 [side=R] + 244[label=<244
0.7247536554274525>]; + 245 -- 246 [side=R] + 246[label=<246
0.5721754588545217>]; + 246 -- 247 [side=R] + 247[label=<247
0.5181752052426042>]; + 247 -- 249 [side=R] + 249[label=<249
0.07619775425067954>]; + 249 -- 248 [side=L] + 248[label=<248
0.03123446276525388>]; +} +graph { + node [shape=circle] + 2[label=<2
0.9957869495270144>]; + 2 -- 1 [side=L] + 1[label=<1
0.8476937427586738>]; + 1 -- 0 [side=L] + 0[label=<0
0.7514570833207395>]; + 2 -- 145 [side=R] + 145[label=<145
0.9939888728473314>]; + 145 -- 12 [side=L] + 12[label=<12
0.9907319285760915>]; + 12 -- 5 [side=L] + 5[label=<5
0.988082370881665>]; + 5 -- 4 [side=L] + 4[label=<4
0.7422137887388395>]; + 4 -- 3 [side=L] + 3[label=<3
0.24440218394323976>]; + 5 -- 8 [side=R] + 8[label=<8
0.695547503791194>]; + 8 -- 6 [side=L] + 6[label=<6
0.5664414792316717>]; + 6 -- 7 [side=R] + 7[label=<7
0.11672897928969816>]; + 8 -- 11 [side=R] + 11[label=<11
0.45404068759973704>]; + 11 -- 9 [side=L] + 9[label=<9
0.3325186970255505>]; + 9 -- 10 [side=R] + 10[label=<10
0.10578109016044712>]; + 12 -- 47 [side=R] + 47[label=<47
0.9904839559513964>]; + 47 -- 33 [side=L] + 33[label=<33
0.9758188259688814>]; + 33 -- 28 [side=L] + 28[label=<28
0.915671870648212>]; + 28 -- 23 [side=L] + 23[label=<23
0.8487360320264957>]; + 23 -- 20 [side=L] + 20[label=<20
0.7063809958484802>]; + 20 -- 16 [side=L] + 16[label=<16
0.7034299359160114>]; + 16 -- 15 [side=L] + 15[label=<15
0.5922634040068163>]; + 15 -- 13 [side=L] + 13[label=<13
0.4543498778672278>]; + 13 -- 14 [side=R] + 14[label=<14
0.21605966187340298>]; + 16 -- 17 [side=R] + 17[label=<17
0.3709284358038115>]; + 17 -- 18 [side=R] + 18[label=<18
0.260599350868457>]; + 18 -- 19 [side=R] + 19[label=<19
0.1817886048339078>]; + 20 -- 21 [side=R] + 21[label=<21
0.14210053829804103>]; + 21 -- 22 [side=R] + 22[label=<22
0.08869917426783513>]; + 23 -- 25 [side=R] + 25[label=<25
0.4892716208875628>]; + 25 -- 24 [side=L] + 24[label=<24
0.25363061372658946>]; + 25 -- 26 [side=R] + 26[label=<26
0.13796660931463622>]; + 26 -- 27 [side=R] + 27[label=<27
0.12997273552181765>]; + 28 -- 31 [side=R] + 31[label=<31
0.8601319422972336>]; + 31 -- 29 [side=L] + 29[label=<29
0.8084698172467167>]; + 29 -- 30 [side=R] + 30[label=<30
0.27908621178937176>]; + 31 -- 32 [side=R] + 32[label=<32
0.0844421977476495>]; + 33 -- 35 [side=R] + 35[label=<35
0.967049096465691>]; + 35 -- 34 [side=L] + 34[label=<34
0.12377873295631248>]; + 35 -- 39 [side=R] + 39[label=<39
0.9328169604588316>]; + 39 -- 38 [side=L] + 38[label=<38
0.7787222122657034>]; + 38 -- 37 [side=L] + 37[label=<37
0.4043690842717128>]; + 37 -- 36 [side=L] + 36[label=<36
0.3046740248996985>]; + 39 -- 43 [side=R] + 43[label=<43
0.8350649185763811>]; + 43 -- 40 [side=L] + 40[label=<40
0.5406537578359348>]; + 40 -- 42 [side=R] + 42[label=<42
0.3193437618727414>]; + 42 -- 41 [side=L] + 41[label=<41
0.27788504363715394>]; + 43 -- 44 [side=R] + 44[label=<44
0.4830145820991081>]; + 44 -- 46 [side=R] + 46[label=<46
0.33052118143151343>]; + 46 -- 45 [side=L] + 45[label=<45
0.29551968300055065>]; + 47 -- 114 [side=R] + 114[label=<114
0.9876511078116038>]; + 114 -- 86 [side=L] + 86[label=<86
0.9735379804960496>]; + 86 -- 77 [side=L] + 77[label=<77
0.9269342780771458>]; + 77 -- 68 [side=L] + 68[label=<68
0.9230582358699485>]; + 68 -- 55 [side=L] + 55[label=<55
0.839490204679298>]; + 55 -- 51 [side=L] + 51[label=<51
0.3385715557270519>]; + 51 -- 50 [side=L] + 50[label=<50
0.3360608605201836>]; + 50 -- 49 [side=L] + 49[label=<49
0.2774445142713422>]; + 49 -- 48 [side=L] + 48[label=<48
0.17489390663513982>]; + 51 -- 52 [side=R] + 52[label=<52
0.1886079446757799>]; + 52 -- 54 [side=R] + 54[label=<54
0.12293678964136756>]; + 54 -- 53 [side=L] + 53[label=<53
0.08266549169366844>]; + 55 -- 64 [side=R] + 64[label=<64
0.5480541758673416>]; + 64 -- 61 [side=L] + 61[label=<61
0.4333510895474586>]; + 61 -- 58 [side=L] + 58[label=<58
0.22965679673111572>]; + 58 -- 57 [side=L] + 57[label=<57
0.1750392554452569>]; + 57 -- 56 [side=L] + 56[label=<56
0.1154682181055644>]; + 58 -- 60 [side=R] + 60[label=<60
0.19505416228675265>]; + 60 -- 59 [side=L] + 59[label=<59
0.15628574332026035>]; + 61 -- 63 [side=R] + 63[label=<63
0.23625159275800722>]; + 63 -- 62 [side=L] + 62[label=<62
0.10778840213677576>]; + 64 -- 66 [side=R] + 66[label=<66
0.4795221664420316>]; + 66 -- 65 [side=L] + 65[label=<65
0.29689544767487486>]; + 66 -- 67 [side=R] + 67[label=<67
0.1446107813011439>]; + 68 -- 75 [side=R] + 75[label=<75
0.9136368186744673>]; + 75 -- 73 [side=L] + 73[label=<73
0.8180762618516633>]; + 73 -- 72 [side=L] + 72[label=<72
0.790052528538962>]; + 72 -- 69 [side=L] + 69[label=<69
0.6662534331501744>]; + 69 -- 70 [side=R] + 70[label=<70
0.198170103856931>]; + 70 -- 71 [side=R] + 71[label=<71
0.09798170568469355>]; + 73 -- 74 [side=R] + 74[label=<74
0.3113326781632004>]; + 75 -- 76 [side=R] + 76[label=<76
0.878956270284837>]; + 77 -- 84 [side=R] + 84[label=<84
0.7298827990732385>]; + 84 -- 81 [side=L] + 81[label=<81
0.7294243899593819>]; + 81 -- 78 [side=L] + 78[label=<78
0.6751780813023192>]; + 78 -- 80 [side=R] + 80[label=<80
0.2765792284019555>]; + 80 -- 79 [side=L] + 79[label=<79
0.12189576635143229>]; + 81 -- 83 [side=R] + 83[label=<83
0.5986915452921237>]; + 83 -- 82 [side=L] + 82[label=<82
0.5846092825823913>]; + 84 -- 85 [side=R] + 85[label=<85
0.5030186847252209>]; + 86 -- 103 [side=R] + 103[label=<103
0.968253245483458>]; + 103 -- 88 [side=L] + 88[label=<88
0.9609670084738324>]; + 88 -- 87 [side=L] + 87[label=<87
0.5446892558733331>]; + 88 -- 97 [side=R] + 97[label=<97
0.9483161815322799>]; + 97 -- 92 [side=L] + 92[label=<92
0.9417148997777522>]; + 92 -- 89 [side=L] + 89[label=<89
0.2455511319571373>]; + 89 -- 90 [side=R] + 90[label=<90
0.15647633602612276>]; + 90 -- 91 [side=R] + 91[label=<91
0.13997459061178652>]; + 92 -- 93 [side=R] + 93[label=<93
0.7804508194274744>]; + 93 -- 95 [side=R] + 95[label=<95
0.7226672256819942>]; + 95 -- 94 [side=L] + 94[label=<94
0.43503881905350683>]; + 95 -- 96 [side=R] + 96[label=<96
0.40712673636645136>]; + 97 -- 101 [side=R] + 101[label=<101
0.9255359833317219>]; + 101 -- 99 [side=L] + 99[label=<99
0.7139348283525223>]; + 99 -- 98 [side=L] + 98[label=<98
0.21279150783985867>]; + 99 -- 100 [side=R] + 100[label=<100
0.48002453571456083>]; + 101 -- 102 [side=R] + 102[label=<102
0.6219674393805691>]; + 103 -- 106 [side=R] + 106[label=<106
0.8731379458552129>]; + 106 -- 104 [side=L] + 104[label=<104
0.5400277589431796>]; + 104 -- 105 [side=R] + 105[label=<105
0.0007891566377928871>]; + 106 -- 110 [side=R] + 110[label=<110
0.8382929650437165>]; + 110 -- 109 [side=L] + 109[label=<109
0.4615149406437542>]; + 109 -- 107 [side=L] + 107[label=<107
0.43337904959817486>]; + 107 -- 108 [side=R] + 108[label=<108
0.053658620013432023>]; + 110 -- 112 [side=R] + 112[label=<112
0.5679810533328041>]; + 112 -- 111 [side=L] + 111[label=<111
0.541018763444613>]; + 112 -- 113 [side=R] + 113[label=<113
0.42841646768139463>]; + 114 -- 123 [side=R] + 123[label=<123
0.9464643826259924>]; + 123 -- 119 [side=L] + 119[label=<119
0.8662877311047388>]; + 119 -- 116 [side=L] + 116[label=<116
0.7670170824076343>]; + 116 -- 115 [side=L] + 115[label=<115
0.17190031141596263>]; + 116 -- 118 [side=R] + 118[label=<118
0.3671674221014496>]; + 118 -- 117 [side=L] + 117[label=<117
0.2159590427591035>]; + 119 -- 121 [side=R] + 121[label=<121
0.74738638353363>]; + 121 -- 120 [side=L] + 120[label=<120
0.08665916013292596>]; + 121 -- 122 [side=R] + 122[label=<122
0.4119543486009871>]; + 123 -- 143 [side=R] + 143[label=<143
0.9247442715890171>]; + 143 -- 140 [side=L] + 140[label=<140
0.8936337545064225>]; + 140 -- 125 [side=L] + 125[label=<125
0.8517904638602968>]; + 125 -- 124 [side=L] + 124[label=<124
0.681815353261336>]; + 125 -- 126 [side=R] + 126[label=<126
0.7946927108945189>]; + 126 -- 133 [side=R] + 133[label=<133
0.7289879153749418>]; + 133 -- 128 [side=L] + 128[label=<128
0.7256302169867033>]; + 128 -- 127 [side=L] + 127[label=<127
0.6200343851508556>]; + 128 -- 131 [side=R] + 131[label=<131
0.7089639682237622>]; + 131 -- 129 [side=L] + 129[label=<129
0.5255088944172916>]; + 129 -- 130 [side=R] + 130[label=<130
0.41550021924797953>]; + 131 -- 132 [side=R] + 132[label=<132
0.1851371011016204>]; + 133 -- 134 [side=R] + 134[label=<134
0.6333388625482715>]; + 134 -- 135 [side=R] + 135[label=<135
0.4707182839428111>]; + 135 -- 138 [side=R] + 138[label=<138
0.4128350639522185>]; + 138 -- 137 [side=L] + 137[label=<137
0.25475301393491523>]; + 137 -- 136 [side=L] + 136[label=<136
0.04841095612377411>]; + 138 -- 139 [side=R] + 139[label=<139
0.3855980374729622>]; + 140 -- 141 [side=R] + 141[label=<141
0.8655582249610275>]; + 141 -- 142 [side=R] + 142[label=<142
0.2288591915235536>]; + 143 -- 144 [side=R] + 144[label=<144
0.36710686055015185>]; + 145 -- 235 [side=R] + 235[label=<235
0.9812914040931304>]; + 235 -- 169 [side=L] + 169[label=<169
0.9782585107854103>]; + 169 -- 148 [side=L] + 148[label=<148
0.9449023406787344>]; + 148 -- 147 [side=L] + 147[label=<147
0.7293740098286456>]; + 147 -- 146 [side=L] + 146[label=<146
0.509027051210447>]; + 148 -- 150 [side=R] + 150[label=<150
0.9020436951014624>]; + 150 -- 149 [side=L] + 149[label=<149
0.8190200516813236>]; + 150 -- 153 [side=R] + 153[label=<153
0.8855777631108436>]; + 153 -- 152 [side=L] + 152[label=<152
0.8603376027563862>]; + 152 -- 151 [side=L] + 151[label=<151
0.45459695989529647>]; + 153 -- 167 [side=R] + 167[label=<167
0.8492899523613442>]; + 167 -- 163 [side=L] + 163[label=<163
0.8177575678069656>]; + 163 -- 160 [side=L] + 160[label=<160
0.7759852430212377>]; + 160 -- 158 [side=L] + 158[label=<158
0.734924251943539>]; + 158 -- 156 [side=L] + 156[label=<156
0.710110660084087>]; + 156 -- 155 [side=L] + 155[label=<155
0.2959097323390557>]; + 155 -- 154 [side=L] + 154[label=<154
0.23060113716089548>]; + 156 -- 157 [side=R] + 157[label=<157
0.04398748527099361>]; + 158 -- 159 [side=R] + 159[label=<159
0.09047000528918914>]; + 160 -- 162 [side=R] + 162[label=<162
0.7216878041963218>]; + 162 -- 161 [side=L] + 161[label=<161
0.6871202472393689>]; + 163 -- 165 [side=R] + 165[label=<165
0.3886140063494328>]; + 165 -- 164 [side=L] + 164[label=<164
0.3870484684485387>]; + 165 -- 166 [side=R] + 166[label=<166
0.3476475192762013>]; + 167 -- 168 [side=R] + 168[label=<168
0.8169397159175148>]; + 169 -- 172 [side=R] + 172[label=<172
0.9747928133504129>]; + 172 -- 170 [side=L] + 170[label=<170
0.846452976104617>]; + 170 -- 171 [side=R] + 171[label=<171
0.3121690933042578>]; + 172 -- 230 [side=R] + 230[label=<230
0.958355558453681>]; + 230 -- 187 [side=L] + 187[label=<187
0.957557676245447>]; + 187 -- 180 [side=L] + 180[label=<180
0.92710438449752>]; + 180 -- 174 [side=L] + 174[label=<174
0.7049973940003331>]; + 174 -- 173 [side=L] + 173[label=<173
0.152023809588824>]; + 174 -- 179 [side=R] + 179[label=<179
0.6715227532708304>]; + 179 -- 176 [side=L] + 176[label=<176
0.6621862385446002>]; + 176 -- 175 [side=L] + 175[label=<175
0.1248086920689816>]; + 176 -- 178 [side=R] + 178[label=<178
0.5713418767827186>]; + 178 -- 177 [side=L] + 177[label=<177
0.5560171098718876>]; + 180 -- 183 [side=R] + 183[label=<183
0.9250644230760526>]; + 183 -- 182 [side=L] + 182[label=<182
0.6824354777265715>]; + 182 -- 181 [side=L] + 181[label=<181
0.012508171868127804>]; + 183 -- 184 [side=R] + 184[label=<184
0.4823271793225655>]; + 184 -- 185 [side=R] + 185[label=<185
0.3841022310929997>]; + 185 -- 186 [side=R] + 186[label=<186
0.18775042542247533>]; + 187 -- 203 [side=R] + 203[label=<203
0.8944186382789656>]; + 203 -- 194 [side=L] + 194[label=<194
0.878541152511799>]; + 194 -- 190 [side=L] + 190[label=<190
0.6762694909925744>]; + 190 -- 188 [side=L] + 188[label=<188
0.3829541869540283>]; + 188 -- 189 [side=R] + 189[label=<189
0.20943675668859407>]; + 190 -- 192 [side=R] + 192[label=<192
0.5817469625147841>]; + 192 -- 191 [side=L] + 191[label=<191
0.09503744303386963>]; + 192 -- 193 [side=R] + 193[label=<193
0.3644771285875493>]; + 194 -- 197 [side=R] + 197[label=<197
0.7948407869124952>]; + 197 -- 195 [side=L] + 195[label=<195
0.7942811285510138>]; + 195 -- 196 [side=R] + 196[label=<196
0.5627582929517205>]; + 197 -- 202 [side=R] + 202[label=<202
0.6971384514391066>]; + 202 -- 198 [side=L] + 198[label=<198
0.6927264474372884>]; + 198 -- 200 [side=R] + 200[label=<200
0.6455091049085492>]; + 200 -- 199 [side=L] + 199[label=<199
0.5952913724552451>]; + 200 -- 201 [side=R] + 201[label=<201
0.02134082793304981>]; + 203 -- 222 [side=R] + 222[label=<222
0.7905661844403327>]; + 222 -- 221 [side=L] + 221[label=<221
0.7344461814842598>]; + 221 -- 218 [side=L] + 218[label=<218
0.710158738001777>]; + 218 -- 214 [side=L] + 214[label=<214
0.6681641416928006>]; + 214 -- 210 [side=L] + 210[label=<210
0.6445674840025054>]; + 210 -- 204 [side=L] + 204[label=<204
0.4613335241960753>]; + 204 -- 207 [side=R] + 207[label=<207
0.4534069998012402>]; + 207 -- 205 [side=L] + 205[label=<205
0.3958801765835097>]; + 205 -- 206 [side=R] + 206[label=<206
0.11317604266906478>]; + 207 -- 208 [side=R] + 208[label=<208
0.15215468537761012>]; + 208 -- 209 [side=R] + 209[label=<209
0.1517155863611125>]; + 210 -- 213 [side=R] + 213[label=<213
0.5254528847170963>]; + 213 -- 212 [side=L] + 212[label=<212
0.3831362875816451>]; + 212 -- 211 [side=L] + 211[label=<211
0.05056020282973139>]; + 214 -- 215 [side=R] + 215[label=<215
0.5009367015686823>]; + 215 -- 216 [side=R] + 216[label=<216
0.10901874828554337>]; + 216 -- 217 [side=R] + 217[label=<217
0.05646524838685241>]; + 218 -- 220 [side=R] + 220[label=<220
0.674411240175005>]; + 220 -- 219 [side=L] + 219[label=<219
0.14299197003272757>]; + 222 -- 223 [side=R] + 223[label=<223
0.6736901076540927>]; + 223 -- 226 [side=R] + 226[label=<226
0.6137254504515176>]; + 226 -- 225 [side=L] + 225[label=<225
0.42057192814517086>]; + 225 -- 224 [side=L] + 224[label=<224
0.15459807255670532>]; + 226 -- 227 [side=R] + 227[label=<227
0.3240860179195383>]; + 227 -- 229 [side=R] + 229[label=<229
0.1917962317572811>]; + 229 -- 228 [side=L] + 228[label=<228
0.09544487292662296>]; + 230 -- 231 [side=R] + 231[label=<231
0.9537855788342208>]; + 231 -- 234 [side=R] + 234[label=<234
0.8201857812416328>]; + 234 -- 233 [side=L] + 233[label=<233
0.38950247492509926>]; + 233 -- 232 [side=L] + 232[label=<232
0.3117950672088875>]; + 235 -- 245 [side=R] + 245[label=<245
0.9606326065278836>]; + 245 -- 243 [side=L] + 243[label=<243
0.9010055124673463>]; + 243 -- 237 [side=L] + 237[label=<237
0.8906258722253291>]; + 237 -- 236 [side=L] + 236[label=<236
0.699210568923407>]; + 237 -- 239 [side=R] + 239[label=<239
0.8460173468831691>]; + 239 -- 238 [side=L] + 238[label=<238
0.11026801706799916>]; + 239 -- 242 [side=R] + 242[label=<242
0.8439586286718704>]; + 242 -- 240 [side=L] + 240[label=<240
0.6602788030770246>]; + 240 -- 241 [side=R] + 241[label=<241
0.5119345141518413>]; + 243 -- 244 [side=R] + 244[label=<244
0.7247536554274525>]; + 245 -- 246 [side=R] + 246[label=<246
0.5721754588545217>]; + 246 -- 247 [side=R] + 247[label=<247
0.5181752052426042>]; + 247 -- 249 [side=R] + 249[label=<249
0.07619775425067954>]; + 249 -- 248 [side=L] + 248[label=<248
0.03123446276525388>]; +}