0% found this document useful (0 votes)
27 views2 pages

Worksheet CS165: Binary Search Trees: Stepwise Build A BST From 80, 20, 100, 10, 40, 90, 30, 50, 35

1. The document discusses building a binary search tree from a list of numbers and performing various tree traversals and searches on the resulting tree. 2. It provides code for a binary search tree node class with methods for searching and traversing the tree. 3. The document asks the reader to implement various operations on the binary search tree like adding and removing nodes.

Uploaded by

Raymond Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Worksheet CS165: Binary Search Trees: Stepwise Build A BST From 80, 20, 100, 10, 40, 90, 30, 50, 35

1. The document discusses building a binary search tree from a list of numbers and performing various tree traversals and searches on the resulting tree. 2. It provides code for a binary search tree node class with methods for searching and traversing the tree. 3. The document asks the reader to implement various operations on the binary search tree like adding and removing nodes.

Uploaded by

Raymond Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Worksheet

CS165: Binary Search Trees







1. Stepwise build a BST from 80, 20, 100, 10, 40, 90, 30, 50, 35















2. Give the pre-order, in, and post order traversal of the tree






3. Implement the search algorithm for a binary search tree, given the following node.

class TreeNode<E> { public search(E element) {
E element; TreeNode<E> current = root;
TreeNode<E> left;
TreeNode<E> right;

public TreeNode(E o) {
element = o;
}
}









3. Show how the breadth first traversal of the above tree is implemented using a queue:


Queue Output
Init [80] -





















4. The above tree is a binary search tree (BST). Redraw the above BST after 95 is added and
20 is deleted. Show both possible results.

You might also like