演算法›Ch4 圖論演算法第 3 題/共 111 題
3. Union-Find、Disjoint Set、Amortized Analysis
#AL-04-003中Union-FindDisjoint SetAmortized Analysis
Consider the linked-list representation of disjoint sets, where: (1) Each set is represented by a linked list; (2) Each element stores a pointer to the set's representative; (3) UNION(x, y) appends the shorter list to the longer list (union by size); (4) FIND-SET(x) runs in time. Suppose we start with singleton sets and perform any sequence of UNION and FIND-SET, using union by size. Which of the following statements is correct?
參考答案與解析
答案 (E):這是 union-by-size 的經典攤還分析結果——每次一個元素所屬串列被合併進更大串列時,該串列大小至少變成兩倍,所以任一元素的代表指標最多被更新 O(log n) 次;對 n 個元素加總,所有 UNION 操作重新指派代表指標的總時間為 O(n log n)。
📄 台大115
▤完整推導請見《WH 資工筆記 · 演算法》Ch4 圖論演算法