-->
当前位置:首页 > 题库 > 正文内容

程序填空题:Union / Find

Luz4年前 (2021-05-10)题库610
Please fill the array with the results after the following union/find operations.

```
union( find(2), find(7) )
union( find(3), find(5) )
union( find(0), find(2) )
union( find(5), find(7) )
union( find(5), find(6) )
```

Note: Assume `union-by-size` (if two sets are equal-sized, the first root will be the root of the result) and `find-with-path-compression`. `S[i]` is initialized to be $$-1$$ for all $$0\le i\le 7$$.

| `i` | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|:--:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|`S[i]`| $$2$$ |$$-1$$ |@@[-6](1)|@@[2](1)|$$-1$$ |@@[2](1)|@@[2](1)| $$2$$ |





答案:
第1空:-6

第2空:2

第3空:2

第4空:2

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。