Set and UFDS Flashcards

1
Q

2 implementations for sets

A
  1. HashTable -> if don’t have to union or intersect
  2. Union-Find Disjoint Sets (UFDS)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2 Key Ideas of UDFS

A
  1. Each set is modelled as a tree, thus a collection of disjoint sets form a forest of trees
  2. Each set is represented by a representative item, which is the root of the corresponding tree of that set
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Main Implementation of UFDS

A

Arrays for Parents and Ranks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Time Complexity of findSet

A

O(a(N)) -> Recursively visit p[i] until p[i] = i, then compress the path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Time Complexity of isSameSet

A

O(a(N)) -> Check if findSet(i) == findSet(j)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Time Complexity of unionSet

A

O(a(N)) -> If i and j are of different disjoint sets, we can union the two sets by setting the representative item of the taller tree to be the representative item fo the new combined set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the Union by Rank heuristic

A

We use another integer array rank where rank[i] stores the upper bound of the height of tree rooted at i. It is an upper bound as path compressions can make trees shorter than its upper bound and we don’t want to waste effort maintaining the correctness of rank[i]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the Inverse Ackermann Function - a(N)

A

If both Union by Rank and Path Compression heuristics are used, then UFDS operations run in O(a(N)) time. We can assume it as O(1) for practical values of N.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly