Mandatory Questions

advertisement
King Saud University
College of Computer and Information Sciences
Information Technology Department
IT212: Data Structures
First Semester 1434/1435
Tutorial # 8
Mandatory Questions:
1. Draw a Binary Search Tree that shows the result of the tree after:
a) Inserting the following keys (from left to right): The tree initially is empty. key ={17, 9, 26, 12, 11, 7,
30, 20, 21, 10}
b) After the key 17 is deleted.
2. Give four different orderings of the search keys 10, 5, 6, 13, 15, 8, 14, 7, 12, 4 that would
result in the least balanced tree if they were added to an initially empty binary search
tree.
3. What ordering of the search keys 10, 5, 6, 13, 15, 8, 14, 7, 12, 4 would result in the most balanced tree if
they were added to an initially empty binary search tree?
4. Implement the method getEntry iteratively.
5. Write an algorithm that returns the second largest value in a binary search tree containing at least two
nodes.
Idea: Find the largest value v. The second largest value is either the parent of v or the largest in v’s left
subtree.
6. Consider a Binary Search Tree of Football Teams Information in Riyadh. Each team has:Team Name,
Team Code and Team Goals Average (the average number ofgoals of theteam in one month). The Binary
Search Tree is ordered according to the Team Code.
public class TeamInfo
{
private String tName;
private String tCode;
private int
avgGoals;
private listInterface<String> PlayersNamesList;
public TeamInfo (…) { … } // constructor
// assume set and get methods for all data members exist as well
//as toString method.
}//class TeamInfo
1
a) Add to the TeamInfo class whatever is missing to make it usable in such a BST.
b) Write a statement that declare and create a binary search tree of teams.
c) Write the code for a method that displays the names of all players given team code.
Extra Questions:
1. We can sort a given set of n numbers by first building a binary search tree (using add entery repeatedly to
insert the numbers one by one) and then printing the numbers by an inorder tree walk. What are the worstand best-case running times for this sorting algorithm (expressed in Θ notation)?
2. If a node x in a binary search tree has two children, then x's successor has no left child. Explain why this is
true, in an English sentences, and pictures if you wish.
3. Find if a given Binary Tree is a Binary Search Tree
4. EX: 8, 9, 12, 13 and 20 in your text book
2
Download