Starting from:
$29.99

$23.99

Assignment 6 Solution

1.   (100 pts) Write a program to check if a binary search tree is a subset of another binary search tree. Implement the function issubset() given below

 

int issubset(node *tree1, node *tree2)

 

 

This function should return 1 if all the elements of the rst tree appear in the second tree and 0 otherwise. Note that depending on the insertion order of elements, two trees with same set of elements can have very different shapes. Consider the binary search trees given below. They contain the same set of elements but have different shapes.



 

 
 
 
 
 
6
 
 
 
4
 
 
4
7
2
 
 
6
2
5
 
1
3
5
7
1
3
 
 
(a) First Tree
 
(b) Second Tree
 


 

 

 

Sample execution is given below

 

fox01assign6

 

Enter the set of numbers for the first tree

 

4 2 6 1 3 5 7

 

Enter the set of numbers for the second tree

 

6 4 7 2 5 1 3

 

First tree is a subset of second tree

 

 

Insert the numbers into the trees in the order they are listed. Once you build the trees, use the issubset function to check if rst tree is a subset of second tree.

 

More products