Month: January 2006

There are many differences between firefox and IE in terms of parsing CSS file and rendering web page.

When I built this site, I suffered the pain, that when I designed a HTML page with a CSS style, it looks pretty fine in Microsoft’s IE but terrible in Firefox. Here is an example, people often use nested “<div>” tag in their HTML file and so do I. If you also do such things and hope people have good experiences when browse your website using Firefox you should be careful with your CSS style design.

It is really complicated, I think, at least for me! I havn’t learnt CSS before, therefore, it took me lots of time to change the default CSS style to the current one.

Here is some useful site that I visit on a regular basis :

456 Berea Street
A personal blog that concerns CSS. W3Schools
Huge resources including CSS tutorial with examples, quizzes, references in this offical site.HTML dog
HTML and CSS Tutorials, References. This is the first site I refered to when I plan to study HTML and CSS.

I just find a website host service called dreamhost by accident when surfing on the internet. I am not using their service at present, but I think I will plan to transfer my site to dreamhost. (update: I am using their service now) The “Crazy Domain Insane!” level hosting cost $7.95/mo–as I know, it is not expensive，If you enter a promotion code when you sign up, the price will be much lower!

MovableType is a very popular blog platform and having seen lots of publishing system, finally I choose this one.
It tooks me about 3 hours to install the Movable Type in my Windows xp machine while it just took me much fewer time in Linux. I’d like to record the steps for other’s reference. It is also a good resource for myself if I need to rebuild the server.

Binary search tree is a binary tree in which each internal node x stores an element such that the elements stored in the left subtree of x are less than or equal to x and elements stored in the right subtree are greater than or equal to x. The following code is the class of binary search tree designed by me. I use a function pointer m_visit to construct the tree and visit the nodes of the tree.

Let’s walk through the procedure of searching a given key in the above binary search data structure.

The procedure begins its search at the root and traces a path downward in the tree, and for each node it encounters, it compares the keys. If the searched key is bigger than the current key of the node, it goes down to left subtree. If the searched key is smaller than the current key of the node, it goes down to right subtree. If two keys are equal, the search terminates.

The structure of a binary search tree allows us to determine the In Order successor of a node without ever comparing keys. The following procedure returns the successor of a node x in a binary search tree if it exists, or NULL if x has the largest key in the tree.

An element in a binary search tree whose key is a minimum can always be found by following left child pointers from the root until a NULL is encountered, thus the procedure of finding the maximum element is symmetric.

To insert a node into a binary search tree, we use a node pointer x which begins at the root of the tree and traces a path downward. The pointer x traces the path, and the pointer y is maintained as the parent of x. These two pointers to move down the tree, going left or right depending on the comparison of the key to be inserted with x->data, until x is set to NULL. At that time, we use y to help us to insert the key. Insert2 is a recursive version of the insertion procedure.

However, removing a node from a binary search tree is a bit more complex. Which node is actually removed is depends on how many children the node to be deleted has. If the node has one child then the child is spliced to the parent of the node, which means that we should remove the node itself. If the node has two children then its successor has no left child; copy the successor into the node and delete the successor instead. The following figure shows deleting a node z from a binary search tree. (a) z has no children, we just remove it. (b) z has only one child, we splice out z. (c) z has two children, we splice out its successor y, which has at most one child, and then replace z’s key and data with y’s key and data.

template<typename T>
void BSTree<T>::Delete(BSTreeNode<T>* z)
{
if(!z)
return NULL;
//y is the node should be removed, and x is the child of y
BSTreeNode<T> *y, *x;
//if z has 2 children, we should remove its successor
if(z->left && z->right)
y=Successor(z);
else//if z has 1 or no child, z itself should be removed.
y=z;
//Let x be the y's child and if y is the successor of z,
//notice that x has at most one child
if(y->left)
x=y->left;
else
x=y->right;
//begin to remove y from the tree
if(x)
x->parent=y->parent;
if(!y->parent)//if y is the root, let x be the root
m_root=x;
else
{
if(y==y->parent->left)
y->parent->left = x;
else
y->parent->right = x;
}
//if z has 2 children and we split out its successor
if(y!=z)
z->data=y->data;
delete y;
}

Finally, Here is the piece of code to test out my little binary search tree. The function print() visits the data of the tree node. The rand() function can generate random integers ranges from -999 to 999 approximately.

The ith order statistic of a set of n elements is the ith smallest element. For example, the minimum of a set of elements is the first order statistic (i = 1), and the maximum is the nth order statistic (i = n). The asymptotic running time of the simple problem of finding a minimum or maximum is Θ(n). Yet select the ith smallest element appears more difficult but it also only need Θ(n) time.

Binary Tree is the most often used Data structure in the programming world and is also the basis of other complex data structures. So as a Computer Science student, it is very important to understand it thoroughly. The following paragraph is quoted by Standford Univ.’s Website explaining Binary Tree:

A binary tree is made of nodes, where each node contains a “left” pointer, a “right” pointer, and a data element. The “root” pointer points to the topmost node in the tree. The left and right pointers recursively point to smaller “subtrees” on either side. A null pointer represents a binary tree with no elements — the empty tree. The formal recursive definition is: a binary tree is either empty (represented by a null pointer), or is made of a single node, where the left and right pointers (recursive definition ahead) each point to a binary tree.