algorithm - Union-Find: retrieve all members of a set efficiently -


i'm working union-find algorithm. in first part of program, algorithm computes partition of big set e.

after that, want retrieve members of set s, contains given node x.

until now, naively, testing membership of elements of e set s. yesterday reading "introduction algorithms" (by clrs, 3rd edition, ex. 21.3-4), and, in exercises, found that:

suppose wish add operation print-set(x), given node x , prints members of x's set, in order. show how can add single attribute each node in disjoint-set forest print-set(x) takes time linear in number of members of x's set, , asymptotic running times of other operations unchanged.

"linear in number of members of x's set" great improvement problem! so, i'm trying solve exersice... , after unsuccessful tries, i'm asking on stack overflow!

recall union-find implemented upside-down tree, each set s = {v1, v2, ..., vn}, have vn - 1 edges, have same root (or sink).

now, whenever add edge (vi, vj) tree, add edge (using new attribute) (vj, vi). , when remove node, remove attribute well.

note new edge separated old one. use only when printing elements in set. , modify whenever original edge modified in original algorithm.

note attribute list of nodes, total number of elements in lists combined still n - 1.

this give second tree, not upside down. now, using root, , doing tree-traversal (using e.g. bfs or dfs), can print elements.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -