68
Algorithm Analysis Advanced Data Structure Chung-Ang University, Jaesung Lee

Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis

Advanced Data Structure

Chung-Ang University, Jaesung Lee

Page 2: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue, Heap and Heap Sort

2

Page 3: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Max Heap data structure

3

Page 4: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Representation of Heap Tree

4

Page 5: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Representation of Heap Tree

5

Page 6: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Representation of Heap Tree• Let us consider the following elements arranged in the form of array as follows:

6

Page 7: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Representation of Heap Tree• A heap tree represented using a single array looks as follows:

7

Page 8: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Operations on heap tree• Insertion

• Deletion and

• Merging

8

Page 9: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree

9

Page 10: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree

10

Page 11: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• The algorithm Max_heap_insert to insert a data into a max heap tree is as follows:

11

Page 12: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

12

Page 13: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

13

Page 14: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

14

Page 15: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

15

Page 16: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

16

Page 17: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

17

Page 18: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

18

Page 19: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Insertion into a heap tree• Insert 40, 80, 35, 90, 45, 50, 70

19

Page 20: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Deletion of a node from heap tree• The algorithm for deleting root node is as follows:

20

Page 21: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Deletion of a node from heap tree• And the algorithm for “adjust” function is as follows:

21

Page 22: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Deletion of a node from heap tree

22

Page 23: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Merging two heap trees

23

Page 24: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Applications of heap tree

24

Page 25: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort

• (Step 1) Build a heap tree with the given set of data.

• (Step 2-a) Remove the top most item (the largest) and replace it with the last element in the heap.

• (Step 2-b) Re-heapify the complete binary tree.

• (Step 2-c) Place the deleted node in the output.

• (Step 3) Continue Step 2 until the heap tree is empty.

25

Page 26: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• A Heap Sort Algorithm

26

Page 27: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• A Heap Sort Algorithm

27

Page 28: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• A Heap Sort Algorithm

28

Page 29: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Time complexity

29

Page 30: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

30

Page 31: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

31

Page 32: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

32

Page 33: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

33

Page 34: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

34

Page 35: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

35

Page 36: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Example

36

Page 37: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Priority queue implementation using heap tree

37

Page 38: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Heap Sort• Priority queue implementation using heap tree

38

Page 39: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Binary Search Trees

39

Page 40: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Binary Tree Searching

40

Page 41: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Why use binary search trees?

41

Page 42: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Why use binary search trees?

42

Page 43: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Why use binary search trees?

43

Page 44: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Why use binary search trees?

44

Page 45: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Why use binary search trees?

45

Page 46: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Why use binary search trees?

46

Page 47: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Inserting nodes into a Binary Search Tree

47

Page 48: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Deleting nodes from a Binary Search Tree

48

Page 49: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Deleting nodes from a Binary Search Tree

49

Page 50: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Deleting nodes from a Binary Search Tree

50

Page 51: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Deleting nodes from a Binary Search Tree

51

Page 52: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Priority Queue• Deleting nodes from a Binary Search Tree

52

Page 53: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Dictionary• Dictionary

53

Page 54: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Dictionary• Dictionary (Example)

54

Page 55: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Dictionary• Dictionary (Example)

55

Page 56: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Dictionary

56

• Get operation

• Put operation

• Remove operation

Page 57: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Relation between Dictionary and Set

• A set is an unordered collection (possibly empty) of distinct items.

• We can implement a set as a bit vector over the universal set.

• We can implement a set with a list structure (with insertion constraints).

• A multiset or bag is a set without the uniqueness constraint.

• Basic operations of a multiset: Search, Insert, Delete.

• A basic data structure that accomplishes these operations is dictionary.

• Sometimes we need to dynamically partition some n-element set into a collection of disjoint sets.

• Sometimes we need to take the union or intersection of sets.

57

Page 58: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Set and Disjoint Set

• Disjoint Set Operations: Union and Find

58

Page 59: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Disjoint Set Union (example)

• �� = {1,7,8,9}

• �� = {2,5,10}

• �� ∪ S� = {1,2,5,7,8,9,10}

59

Page 60: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Find (example)

• �� = {1,7,8,9}

• �� = {2,5,10}

• �� = 3,4,6

• ����(4) = ��• ����(5) = ��• ����(7) = ��

60

Page 61: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Set Representation (example)

• �� = {1,7,8,9}

• �� = {2,5,10}

• �� = 3,4,6

61

Page 62: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Disjoint Union

62

Page 63: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Find

63

�� �� ��

Page 64: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Union and Find Algorithms (example)

• For the following sets, the array representation is as shown below.

64

Page 65: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Algorithm for Union operation

65

Page 66: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Algorithm for Find operation

66

Page 67: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Analysis of SimpleUnion(i,j) and SimpleFind(i)

• For example, consider the sets:

67

Page 68: Algorithm Analysis Advanced Data Structuremi.cau.ac.kr/teaching/lecture_alg/W05P.pdfAlgorithm Analysis / Chung-Ang University / Professor Jaesung Lee Disjoint Set Operations •Relation

Algorithm Analysis / Chung-Ang University / Professor Jaesung Lee

Disjoint Set Operations• Analysis of SimpleUnion(i,j) and SimpleFind(i)

• The sequence of Union operations results the degenerate tree as below.

• Time complexity is � ∑ ����� = � �� .

68