Sunday, March 30, 2014

Week 9 -- Binary Search Tree

In computer science, a binary search tree (BST), sometimes also called an ordered or sorted binary tree, is a node-based binary tree data structure which has the following properties:

  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • The left and right subtree each must also be a binary search tree.
  • There must be no duplicate nodes.
Because of the special structure of the binary tree, it's easier for us to search an element which is in the tree. We just need to make a recursion: if the element is greater than the root, we search the right tree in the same way; if the element is smaller than the root, we search the left tree.

Thursday, March 27, 2014

Week 8 -- linked List

There are two ways to represent linked list. One of which is as lists made up of an item (value) and the remaining list(rest), the other way is as objects (nodes) with a value and a reference to other
similar objects.

For the first type, the class for LinkedList is initialized like this:










And for the second type, a class call LListNode is defined first to represent the objects in the linked list:








Linked list makes each elements related(linked) one by one.













For this example, the nodes will be linked like this:
_images/link2.png