Algorithm quick-union
Initialize
union ( a, b )
i = Root(a)
j = Root(b)
V[ i ] = j
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
![]() |
union ( 3, 7 )
union ( a=3, b=7 )
i = Root(a=3) => i = 3
j = Root(b=7) => j = 7
V[ i ] = Root ( j )
V[ 3 ] = Root ( 7 )
V[ 3 ] = 7
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 1 | 2 | 7 | 4 | 5 | 6 | 7 | 8 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |
union( 2 , 5 )
union ( a=2, b=5 )
i = Root(2) = 2
j = Root(5) = 5
V[ 2 ] = 5
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 1 | 5 | 7 | 4 | 5 | 6 | 7 | 8 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |
union( 2 , 3 )
union ( a=2, b=3 )
i = Root(2) = 5
j = Root(3) = 7
V[ 5 ] = 7
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 1 | 5 | 7 | 4 | 7 | 6 | 7 | 8 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |
union( 3 , 6 )
union ( a=3, b=6 )
i = Root(3) =7
j = Root(6) = 6
V[ 7 ] = 6
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 1 | 5 | 7 | 4 | 7 | 6 | 6 | 8 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |
union( 1 , 4 )
union ( a=1, b=4 )
i = Root(1) = 1
j = Root(4) = 4
V[ 1 ] = 4
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 4 | 5 | 7 | 4 | 7 | 6 | 6 | 8 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |
union( 8, 1 )
union ( a=8, b=1 )
i = Root(8) = 8
j = Root(1) = 4
V[ 8 ] = 4
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 4 | 5 | 7 | 4 | 7 | 6 | 6 | 4 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |
union(4, 7)
union ( a=4, b=7 )
i = Root(4) = 4
j = Root(7) = 6
V[ 4 ] = 6
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Parent | 4 | 5 | 7 | 6 | 7 | 6 | 6 | 4 |
| v[1] | v[2] | v[3] | V[4] | v[5] | v[6] | v[7] | v[8] | |
![]() |

.png)
.png)
.png)
.png)
.png)
.png)
.png)