Sunday, January 13, 2013

Finish assignment 1

I just finished assignment 1. The assignment 1 is not as hard as I thought. We create parent child sibling (PCS) tree. We just play with the pointer. Drawing in the paper helps a lot. The most challenging part is calculating the level of the tree.

In calculating level at the insert method is not difficult. In the insert method of the tree, after I insert a node to the tree, I have to calculate the level of tree. What I did is I calculated the level of node I insert by traversing its parent, then compare with the numLevel. So the complexity of the insert is the depth of the node.

For the remove method, I recursively remove its child until it has no child anymore, then I delete the node. Each time I iterate, I compare that node level to the numLevel. If the node level >= numLevel, I have to traverse the whole tree to find the numLevel. Based on my analysis, the worst case is when I remove the root. The complexity is n^2.

No comments:

Post a Comment