This
week we discussed more on BST. One thing that I found interesting was the
deletion of data from BST root at node. First is a simple case, which is when
the item wanted to be deleted has no children. Then the base case would be if
children is equal to None. In this first case, when the data to delete is less
than that at node, then delete from left, which leads to a recursion function,
and also return this node. When the data to delete is greater than that at the
node, then delete from right of the Binary Search Tree and also return that
node. The harder case is actually deleting a node that is equal to the node and
that node has one or two children. If the node has either no left child or
right child, then just replace the node by right or left child. If that node
has both children, then replace the node with either the right-most child on
the left subtree or the left-most child on the right subtree, as shown on the
figure below. And here comes a point that I didn't fully understand in the
lecture. That is, replacing by which one is actually correct? Since replacing
either of them could be correct.
Also, we discussed about the efficiency of
BST searching. Since BST allows us to eliminate the left or the right subtree,
nearly half of the efficiency is improved in the case of a well-balanced BST.
The running time for binary search is actually clog(n), where c is a constant
and n is the size of the input. Another thing I learned from lecture is that
the running time only depends on the highest order. For example, the running
times for 0.23n^2 + 100n and 5n^2 increase at same rate when the input n is
increased.

No comments:
Post a Comment