algorithm - Union-Find operations on a tree? -
can please explain answer in bold? how it's done?
below sequence of 4 union-find operations (with weighted-union , full com- pression) led following up-tree. last 2 operations?
answer: union(d,a), union(b,c), union(d/a,b/c),find(b/c).
the notation used because of sets.
let apply 4 operations:
union(d,a)
leads following tree:
d /
union(b,c)
leads following tree:
b / c
now union(d/a,b/c)
means because d , belong same set, not matter first argument is, can d
or can a
. because b , c belong same set, not matter second argument is, can b
or can c
, the result same.
the result after third operation:
d / \ b \ c
now because compression allowed, find(c)
operation result in tree:
d /|\ b c
if fourth operation find(b)
, tree remain same, because when apply compression after find operation, make nodes encountered in path upto root immediate child of root, since not encounter c
, not able make c
immediate child of d
, in final tree.
correct answer
the correct sequence of 4 operations is:
union(d,a), union(b,c), union(d/a,b/c),find(c).
Comments
Post a Comment