!!!Chapter 8 The Disjoint Set ADT

本文深入探讨了并查集这一数据结构,包括等价关系的定义,动态等价问题,基本数据结构,智能合并算法,路径压缩,以及在最坏情况下的性能分析。并查集用于解决元素间关系的问题,通过Find和Union操作来管理元素的等价类,通过路径压缩和按秩合并优化性能,广泛应用于各种场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Disjoint Set: 不相交集,并查集

8.1 Equivalence Relations

A relation R is defined on a set S if for every pair of elements (a, b), a, b ∈ S, a R b is either true or false. If a R b is true, then we say that a is related to b.

An equivalence relation is a relation R that satisfies three properties:

1. (Reflexive自反性) a R a, for all a ∈ S.

2. (Symmetric) a R b if and only if b R a.

3. (Transitive) a R b and b R c implies that a R c.

8.2 The Dynamic Equivalence Problem

Given an equivalence relation ~, the natural problem is to decide, for any a and b, if a ~ b.

The equivalence class(等价类) of an element a ∈ S is the subset of S that contains all the elements that are related to a.

The equivalence classes form a partition of S: every member of S appears in exactly one equivalence class.To decide if a ~ b, we need only to check whether a and b are in the same equivalence class.

The input is initially a collection of N sets, each with one element. This initial representation is that all relations (except reflexive relations) are false. Each set has a different element, so that Si ∩ Sj = ∅; this makes the setsdisjoint.

There are two permissible operations:

1. Find: returns the name of the set(The equ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值