CSC 216/s08/do right: Difference between revisions
Chronomega1 (talk | contribs) |
Chronomega1 (talk | contribs) |
||
Line 27: | Line 27: | ||
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. | 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. | ||
[http://courses.ncsu.edu/csc216/lec/001/video/t3/BinaryTree. | [http://courses.ncsu.edu/csc216/lec/001/video/t3/BinaryTree.swf Flash link Click Here] | ||
===The script=== | ===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. | 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. |
Revision as of 19:51, 20 April 2008
Special Notes about Binary Search Trees
- the left subtree of a node contains only values less than the node's value;
- 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.
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.