Wednesday, March 12, 2014

Binary search

Binary search is a neat algorithm that finds a certain key in an array of keys in a dictionary.  We have already been introduced to this in CSC108 and it is refreshing to come across something familiar every now and then.  However, my knowledge as it turns out is very basic.  The example we did in class was a little confusing but I think after writing it down on paper it has become much clearer.   From now on, pen and paper it is!

Thursday, March 6, 2014

Trees and Linked Lists

This week we learnt about the concept of linked lists which has certainly been one of the most challenging topics to grasp.  I found the lab assignment quite difficult to do although I had been quite confident of my knowledge of trees, which I thought were similar to linked lists.  Apparently, I wrong.  Thanks to the clear explanation posted under title of "Binary Search Trees and Linked Lists" on http://courseblog148.blogspot.ca/ I am now a little more confident of my knowledge about both principles.

A binary trees largely resembles a regular tree, or a family tree.  The top part of a binary tree is called "the root" in regards to the tree analogy, or the "parent" when considering a family tree.  Each "box" in a binary tree has certain features.  It has a "cargo", "left", and "right".  Each box branches off to point to the other boxes, if available.  Left and right are the children pointing to the following boxes.  The default value of the left and right children is None; when no preceding boxes are found.  When left and right are both None, the whole box "child" is said to be a leaf.

Diagram of a binary tree.


What might be confusing to some, myself included, is that linked lists largely resemble binary trees in their arrangement and general structure.  However, linked lists do not have left and right children; they occur when a parent only has one child to point to, which is in the form of a list.

 Diagram of a linked list.