CSC 216/s08/do right

From Expertiza_Wiki
Revision as of 02:47, 20 April 2008 by Chronomega1 (talk | contribs)
Jump to navigation Jump to search

Special Notes about Binary Search Trees

This is an example of a binary search tree
  1. the left subtree of a node contains only values less than the node's value;
  2. the right subtree of a node contains only values greater than or equal to the node's value.

Formatting Resources

Formatting Help Guide from MetaWiki

Learning how Binary Search Tree Works

The problem

Teaching the students how to insert and delete nodes from Binary Search Tree.
Insertion
Insertion begins as a search would begin; if the root is not equal to the value, we search the left or right subtrees as before. Eventually, we will reach an external node and add the value as its right or left child, depending on the node's value. In other words, we examine the root and recursively insert the new node to the left subtree if the new value is less than the root, or the right subtree if the new value is greater than or equal to the root.
Deletion
There are several cases to be considered:

   * Deleting a leaf: Deleting a node with no children is easy, as we can simply remove it from the tree.
   * Deleting a node with one child: Delete it and replace it with its child.
   * Deleting a node with two children: Suppose the node to be deleted is called N. We replace the value of N with either its 
     in-order successor (the left-most child of the right subtree) or the in-order predecessor (the right-most child of the left 
     subtree).

Participants and props

Students can do this on their individual computers or on in groups. Only thing that is needed from the users computer is flash loaded on it.

Flash link coming soon.

The script

Video animation, teaches students how to insert and delete from a binary search tree. Also has a built in game that allows players to insert and remove nodes from a binary search tree.