During the ninth week of our CSC148 course, our second midterm was coming up. I did fairly well on my first midterm and I hoped to do just as well. Unfortunately, that was not the case. I spent a great deal of my time on the third question only to realize that I had been incorrectly writing my code. My code would return a list instead of return NoneType. Therefore, I spent about 20 minutes of my 60 minute exam on something absolutely pointless. I quickly scratched it all off and rewrote the proper code on the back of the question paper. Luckily, I had enough time to finish it and I was still able to confidently answer the first two questions with many less mistakes. The first questions were rather straight-forward and simple for me; they were basic comprehension questions on trees and their lengths. The second question, on the other hand, was slightly more difficult and the third question was even worse. I feel as though the biggest difficulty factor for this midterm was not the questions but was the time, instead. With only sixty minutes to answer all the questions, there was barely any room for error.
On a side note, during the week, we learned about Binary Search Trees (BSTs) and how they are very efficient when it comes to search for a number amongst all of the nodes. The assumptions in the BSTs (smaller numbers to the left and larger numbers to the right), allows the programmer to drastically cut his search time by not needing to visit every single node in the tree. For example, take this tree (rotated 90 degrees counter clockwise):
12
10
5 9
2
1
In this case, 5 has kids 2 and 10; 10 has kids 12 and 9 and 2 has only 1 as a child. If a function was search for the number 12, the function would have to visit every node before it until it finally reaches it. (for example, 5 -> 2 -> 1 -> 10 -> 9 -> 12, of course it depends on which order it is done in) On the other hand, using a BST, the function already knows that 12 is larger than 5 and so immediately goes into the right subtree where the root is 10. It then repeats and goes to the right subtree of 10 because 12 is larger than 10 and thus reaches its target value.
If it already makes a considerable difference, you can just imagine how much difference a BST makes when used in such a larger scale.