Summary Lecture Exercises Programming Exercise

J.E.D.I Figure 1.76 An Example Using Weighted Rule for Union and Collapsing Rule for Find

5.6 Summary

• Trees may be ordered, oriented or free • Link allocation can be used to represent trees. Trees can also be represented sequentially using arithmetic tree representation. • Zero or more disjoint trees taken together are known as a forest • An ordered forest may be converted into a unique binary tree and vice versa using natural correspondence • Forests can be traversed in preorder and postorder • Forests can be represented sequentially using preorder, family-order and level- order sequential representations • The equivalence problem can be solved using trees and the union and find operations. The weighting rule for union and the collapsing rule for find aid in better algorithm performance.

5.7 Lecture Exercises

1. For each of the forests below, FOREST 1 FOREST 2 Data Structures 97 J.E.D.I FOREST 3 a Convert into binary tree equivalent b Give the preorder sequential representation with weights c Give the family order sequential representation with degrees d Using preorder sequential representation, show the internal array used to store the forest with ltag and rtag sequences 2. Show the forest represented below using preorder sequential with weights: a b c d e f g h i j k l m n o 5 2 1 2 1 4 1 3. Equivalence Classes. a Given the set S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and equivalence pairs: 1,4, 5,8, 1,9,5,6, 4,10, 6,9, 3,7 and 3,10, construct the equivalence classes using forest. Is 7 ≡ 6?Is 9 ≡ 10? b Draw the corresponding forest and resulting father vector of the equivalent classes generated from the elements of S = {1,2,3,4,5,6,7,8,9,10,11,12} on the basis of the equivalent relations 1 ≡ 2, 3 ≡ 5, 5 ≡ 7, 9 ≡ 10, 11 ≡ 12, 2 ≡ 5, 8 ≡ 4, and 4 ≡ 6. Use weighting rule for union.

5.8 Programming Exercise

1. Create Java class definition of level-order sequential representations of forests. Also create a method that will convert the level-order sequential representation into its linked representation. Data Structures 98 J.E.D.I 6 Graphs

6.1 Objectives