We had our second term test on Wednesday. Thanks to Diane, Danny, and Mike, the test was not cancelled. Overall, I think the second midterm is harder than the first one: the first question tests our knowledge about binary tree; the second and the third question asks us to write functions on binary search trees and linked lists. And I think it is harder than the first one mainly because of the last two questions.
The first question is not very tricky, one can figure out the minimum and the maximum of the height of a tree just by drawing pictures. I forgot the definition of pre-order traversal during the test, but I assumed it went in the order: data -> left -> right. I was quite lucky that I made this assumption and it gave me the right answer. The second one is more complicated. We need to use the properties of binary search tree to find out the even numbers that is within a given range of numbers, visiting as few nodes as possible. This isn't much of an obstacle to me because we have seen similar examples both in class and in labs, and I did a question from past test the night before the exam which is essentially the same question (except that on does not ask you to check even numbers). The third question is the hardest one in this midterm. As I mentioned in a previous slog, I found methods and functions on linked lists quite tricky, but I feel more and more comfortable implementing them as I practice more about it (mainly from labs and occasionally past exams). I proceeded the question in the following order: 1.figure out the corner case(s) and the general case; 2.draw graphs representing corner case(s) and a general case; 3. write the code for corner case with the help of the graph I drew; 4.write the code for general case with the help of the graph I drew; 5.see if I can incorporate the two cases together; 6.check if all instances are updated properly(front, back, size). With this procedure, I think I gave the right answer (or should I say a right answer?) to the third question.
As to the material we learnt this week; we only had one hour of class this week, and the announcement took almost one third of the class time (as always), so we briefly talked about the insert and delete method of binary search tree. These two methods are not quite different from the methods/functions on binary (search) trees we learnt before, so I am not going to talk much about them. One difficulty about delete is that when we try to delete an interior node with some children, how should we decide which node or value should take place of the deleted node as a child of the deleted node's parent? In class, Diane gave us a solution; promote the leaf that is the closest to the middle to that position. It is not hard to check that this action will not break the properties of BST. I also find this week's lab enlightening: it illustrates how the order matters when you insert a list of number into a binary search tree. If you just insert the list [1,2,3...500] in order to a BST. The resulting tree will have height 500; all the interior nodes only have left child. In this case, the BST does not actually reduce the search time compared to the original list. But if we shuffle the original list, the height of the tree can be reduced as low as 8 (if my calculation is not wrong), which increases the search efficiency.
Lots of effort was put into this slog blog, well done!!!
ReplyDeleteThank you!
DeleteThis comment has been removed by the author.
ReplyDeletesorry I happened to post the same comment due to technical issues.
Deletegood job! you have discussed the tests a lot, which is a good idea that I did not make up.
ReplyDeleteYes, partly because I think retrospection is a very good way to both learn more things and to solidify what has been learnt. Thanks for commenting!!
Delete