Today I had a discussion with someone about the Kruskal Minimum Spanning Tree algorithm because of this slide page.
The presentation author said that if we implement disjoint sets using a (twice) linked list, the performance for Make and Find will be O (1) and O (1), respectively. Operating time Union (u, v) min (nu, nv) , where nu and nv are the sizes of the sets storing u and v.
I said that we can improve Union (u, v) time as O (1) by making a representation pointer of each element, indicating a locator that contains a pointer to the real representation of the set.
In Java, the data structure will look like this:
class DisjointSet { LinkedList<Vertex> list = new LinkedList<Vertex>(); // for holding the members, we might need it for print static Member makeSet(Vertex v) { Member m = new Member(); DisjointSet set = new DisjointSet(); m.set = set; set.list.add(m); m.vertex = v; Locator loc = new Locator(); loc.representation = m; m.locator = loc; return m; } } class Member { DisjointSet set; Locator locator; Vertex vertex; Member find() { return locator.representation; } void union(Member u, Member v) { // assume nv is less than nu u.set.list.append(v.set.list); // hypothetical method, append a list in O(1) v.set = u.set; v.locator.representation = u.locator.representation; } } class Locator { Member representation; }
Sorry for the minimal code. If this can be done, than the run time for each operation with a disjoint set ( Make, Find, Union ) will be O (1) . But the one with whom I spoke cannot see improvement. I would like to know your opinion on this matter.
And also what is the fastest Find / Union performance in various implementations? I am not an expert in data structure, but, quickly browsing the Internet, I found that for this there is no constant data structure or time algorithm.
source share