This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Commit 6ae4c8f
committed
fix(KTrussAnalyzer): correct off-by-one in truss-number assignment
Per Cohen (2008), an edge's truss number is the maximum k such that the
edge belongs to a k-truss. The peeling algorithm removes an edge at
iteration k when its triangle support drops below k - 2, which means
the edge survived the (k - 1)-truss but cannot be in the k-truss.
Therefore truss(e) = k - 1, not k.
The previous implementation set trussNumbers.put(e, k) at peel time,
which over-reported truss numbers by one. It also pre-assigned k + 1
to currently-active edges ("tentative") which compounded the error
when those edges were never peeled.
Symptoms in KTrussAnalyzerTest:
- testSingleEdge_noTriangle expected 2, got 3 (an edge with no
triangles must have truss = 2; it is peeled at k = 3 because
support 0 < 3 - 2)
- testGetKTruss: 3-truss leaked the appendage edge C-D because its
inflated truss number satisfied >= 3
Fix:
- Record trussNumbers.put(e, k - 1) at peel time.
- Tentatively assign trussNumbers.put(e, k) to active edges each round
so still-surviving edges end with the highest k they made it through.
Tests: KTrussAnalyzerTest 9/9 passing (2 previously-red cases now green).
Full suite: 4604 run, 23 failures + 8 errors (down from 29F/8E baseline);
all remaining failures are pre-existing and unrelated.1 parent 3121220 commit 6ae4c8f
1 file changed
Lines changed: 18 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
| |||
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
179 | | - | |
| 183 | + | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
| |||
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
198 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
199 | 205 | | |
200 | | - | |
| 206 | + | |
201 | 207 | | |
202 | 208 | | |
203 | 209 | | |
204 | 210 | | |
205 | | - | |
| 211 | + | |
206 | 212 | | |
207 | 213 | | |
208 | 214 | | |
| |||
233 | 239 | | |
234 | 240 | | |
235 | 241 | | |
236 | | - | |
| 242 | + | |
237 | 243 | | |
238 | 244 | | |
239 | 245 | | |
| |||
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
289 | | - | |
| 295 | + | |
290 | 296 | | |
291 | 297 | | |
292 | 298 | | |
| |||
319 | 325 | | |
320 | 326 | | |
321 | 327 | | |
322 | | - | |
| 328 | + | |
323 | 329 | | |
324 | 330 | | |
325 | 331 | | |
| |||
0 commit comments