CSAS 2126 Data Structures and Algorithms
Priority Queues, Tree, and Disjoint Sets
Questions
1. Priority queue [20 points]
Complete the exercise from textbook 6.18 (page 285)
2. Tree [10 points]
Complete the exercise from textbook 4.15 (page 184)
3. Disjoint Sets [20 points]
Consider the set of vertices A-P, and the relationships {(D, A), (B, E), (C, P), (I, J), (L, N), (O, D), (K, L), (L, A), (F, M), (G, M), (H, P), (L, G), (E, K)}. Show the final
forest if
a) The tree for the right element is always pointed at the left element.
b) The smaller tree is always pointed at the larger tree, pointing right at left if of equal rank.
c) The smaller tree is always pointed at the larger tree, and path compression is used.
In each case, give the total number of pointers followed in searching and the number of pointers added or changed during the algorithm. Then, for each
forest, give (1) the maximum depth of a node, and (2) the cost of searching, averaged over the 16 nodes. [Remember that a search starts at the node and
runs to the root. Do not use path compression on those searches.]
Instructions
• For all the questions, either you can write a clear pseudocode/Algorithm or C++ programming language.
• There are 3 questions and try to complete the first 2. For problem statement 3 –after the Monday session (April 11’ 2022), you can start doing the
assignment
CSAS 2126 Data Structures and Algorithms
Priority Queues, Tree, and Disjoint Sets
Questions
1. Priority queue [20 points]
Complete the exercise from textbook 6.18 (page 285)
2. Tree [10 points]
Complete the exercise from textbook 4.15 (page 184)
3. Disjoint Sets [20 points]
Consider the set of vertices A-P, and the relationships {(D, A), (B, E), (C, P), (I, J), (L, N), (O, D), (K, L), (L, A), (F, M), (G, M), (H, P), (L, G), (E, K)}. Show the final
forest if
a) The tree for the right element is always pointed at the left element.
b) The smaller tree is always pointed at the larger tree, pointing right at left if of equal rank.
c) The smaller tree is always pointed at the larger tree, and path compression is used.
In each case, give the total number of pointers followed in searching and the number of pointers added or changed during the algorithm. Then, for each
forest, give (1) the maximum depth of a node, and (2) the cost of searching, averaged over the 16 nodes. [Remember that a search starts at the node and
runs to the root. Do not use path compression on those searches.]
Instructions
• For all the questions, either you can write a clear pseudocode/Algorithm or C++ programming language.
• There are 3 questions and try to complete the first 2. For problem statement 3 –after the Monday session (April 11’ 2022), you can start doing the
assignment