2013年12月6日星期五

The merge sort

I am reviewing for the knowledge we've learned this semester, and preparing for the coming final exam. Now I want to collect some useful information about the merge sort we've learned before. 

Merge sort is a recursive algorithm that continually splits a list in half. If the list is empty or has one item, it is sorted by definition (the base case). If the list has more than one item, we split the list and recursively invoke a merge sort on both halves. Once the two halves are sorted, the fundamental operation, called a merge, is performed. 

Binary Research Trees

A binary search tree relies on the property that keys that are less than the parent are found in the left subtree, and keys that are greater than the parent are found in the right subtree. To implement the binary search tree, we will use the nodes and references approach similar to the one we used to implement the linked list, and the expression tree. However, because we must be able create and work with a binary search tree that is empty, our implementation will use two classes. The first class we will call BinaryResearchTree, and the second class we will call TreeNode.