Data Structure Flashcards

1
Q

Disjoint set - operations and what they do(3)

A

1) make set - create a new set with one element (O(1))
2) Union - combine two set
3) find set - find which set is in for the given element and return the representative of that set

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

Disjoint set - when to use (2 for now)

A

1) finding cycle in a undirected graph

2) Kruskal’s algorithm (fund minimum spanning forest)

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

Stack - find next greater element of the whole array

A

1) push first element into the stack
2) iterate through all remaining elements
- if the stack is empty, push the current element
- else, keep popping the element when s.top() is less than the current element and mark the current element as answer for popped els
- push the current element
3) mark all remaining elements in the stack as not found

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