Union-Find - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Union-Find

Description:

... d c b a e Find(a) ... datastructures avl binarysearchtrees trees recitation Created Date: 1/1/1601 12:00 ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 15
Provided by: acil150
Category:

less

Transcript and Presenter's Notes

Title: Union-Find


1
???? ??????
  • Union-Find

????? ?? ???? ?? ????? ?????
2
???? Union-Find
  • ???? ?????? ?????? ?? ??????? ?????
  • ????? make-set(x) ????? ????? ??? ???? x
  • ????? union(x, y) ????? ??????? ?? x ?-y
  • ????? find(x) ????? ?????? ???? x ????, ??????
    ????? ?????? (representative) ?? ??????

5
5
11
7,11
7
7
????? ?? 3 ?????
???? ?? 11
????? ?? ???' ?? 7 ?-11
3
????? Union-Find
  • ????? ?"? ?????? ???????
  • ?? ????? ???? ????? ??????
  • ????? ??? ?????? ???? ???? ????? ???????
  • ????? ???? ??? ??????
  • ????? ?"? ????
  • ?? ????? ?????? ??? (???? ??????? ???? ???)
  • ????? ?????? ?? ????? ??? ?? ?????? ???
  • ????? ?"? ????? ??? ???? (????? ??? ?? ????)
  • ????? ?"? ????? ??? ?? ?????

4
????? Union-Find
  • ?? ?????? ????? ?????? ?"? ?????
  • ????? ????? ??? ?????? ???????. ????
  • ??????? ????? ?????
  • Union By Rank

Rank0
Rankx
Rankx
Rankx1
5
????? Union-Find
  • ?? ?????? ????? ?????? ?"? ?????
  • ????? ????? ??? ?????? ???????. ????
  • ??????? ????? ?????
  • Union By Rank ???? ?? ??????? ?? ????? ????
    O(logn)
  • ????? ??????? (Path Compression)

??? (a)
6
????? Union-Find
  • ?? ?????? ????? ?????? ?"? ?????
  • ????? ????? ??? ?????? ???????. ????
  • ??????? ????? ?????
  • Union By Rank ???? ?? ??????? ?? ????? ????
    O(log n)
  • ????? ??????? (Path Compression) ???? ??
    ??????? ?? ??????? ?? ???? n ?????? ????? (?????
    ??) ?-f ?????? ????? ???? ??????
  • ?? ?? ????? ?? ??? ?????? ?????????? ?? ???? m
    ?????? ????

??' ??????? ??' ?????, ?? ?' ????? ??? ??? ???...
???? ??? ???????? ?? union-find ???? ??? ?-4
?????? ?????? http//mathworld.wolfram.com/Ackerm
annFunction.html
7
????? 1
  • ?????? ???? ?????? ?? union-find (????? ??
    ???????? ?? union by rank path compression),
    ????? ???? ?? m ?????? (make-set, union, find)
    ??? ?? ?????? ?-union ????? ???? ?????? ?-find.
    ???? ??? ???? ?????? ???? ?? ??? ??????, ?????
    O(m)
  • ?????
  • ??? ???? ???????
  • ????? ????? ????

????? ?????
????? ????
???? ???????
8
????? 1
  • ????? ????? ????
  • ??? ????? ?? m ?????? ???? ??? O(m) ?? ?????
    ????? ????? ???? ????
  • ??????? ?????? ????? ?? ??????
  • ?? ?? ??????? ???????
  • make-set
  • union
  • find

9
????? 1
  • ????? ????? ???? (????)
  • ???? ???? ?? ?-path compression ???????? find
    ????? ??????? ??????
  • ??? ????? make-set ???? ???? ????? ??????? ?????
  • ?????? find ???? ????? path compression
  • ?? ???? ????? ??? ??? ????, ???? ????? ???? ????
    ?? ??????

Find(a)
??"? m ?????? ??? ??? ???? O(1) amortized
10
????? (-) 2
  • ?????? ??? G(V,E), ???? ?? ????? ??????? ?? ????
  • ???? ???? ????? ???? ?????? ????? ???? ??? ????
    union-find
  • ??????
  • ???? ?-make set ?? ?? ????? ?? ????
  • ????? ?? ?? ?????? ???? ??? ???? ?-
  • union(find(u),find(v)) ???? u ?-v ???? ????
  • ?? ?? ????? ??????? ???? ??? ???? ?????? ????
  • ????????

11
????? 3
  • ????? ???? HEX ?? ??? ??????, ?? ???? ???? ?????
    ????? ????/???? (???? ?????). ???? ????? ??????
    ???? ????? ?? ??? ?????? ???
  • ???? ????? ??????? ?? ???? ???? ?? ???? ?????? ??
    ??? ???? O(log n) ????? ???? ?? ??? ??????? ?????

12
????? 3 - ?????
  • ????? ???? union-find ??? ???? ????? ????????,
    ???? ???? ????? ??? (??? ?? ????)
  • White-right
  • White-left
  • Black-top
  • Black-bottom
  • ??? ??? ????
  • make-set(X) ?? ?-X ????? ???? ?? ?????
  • union ?? X ?? ?? ??? ????? ?? ????? ??? (??? ??
    ?? 6 ????? ??? ?????)
  • ????? ?? ???????? ???? ?????
  • ?? ???? ??????
  • find(W-R)find(W-L) ??? ???? ????
  • find(B-T)find(B-B) ??? ????? ????
  • ??"? ??? ???? O(log n) ????, ?????

13
????? 4
  • ???? ???? ?????? ?-union-find
  • ?? ????? ????? ?????? ??????? ??-???????, ??
    ????? ????? ????? ????? (????) ?????? ?? ??????
  • Find ????? ????? ??????? ????? ?????
  • Union ?????? ??' ???? ?????? ??????? ?? ?????
  • ??? ??? ???? ???? m ?????? ???? ????? ????? ?? n
    ?????? ????? ??? ??? (?? ???)? (?????? mgtn)

14
????? 4
  • ?????? find, make-set ?????? ??? ????, ??? ?????
  • ???? ????? ?? ????? ??? ?? ?? ??? ?????? ?????
    ???? ?????? ????????
  • ???, ??"? ????? ???? ?????? O(n log n) ?????
  • ???? ???, ?????? ?-union ?????? ????? ????? ?????
    ??????
  • ??"? ?????? O(m n log n)
Write a Comment
User Comments (0)
About PowerShow.com