Monday, April 6, 2015

Binary Search Tree: Speeding up the searching

The second midterm of CSC148 has taken place this week. Comparing with T1, T2 seems to be harder to handle, because of the vary of Data Structures are like a water fountain keeps injecting water into my low-capacity head. I'm like eating a meal without chewing, swallowing everything and get stuck when digesting.

Here comes another piece of food: The Binary Search Tree. After the exam, I had a one-hour lecture digging on Binary Search Tree deeper and deeper. In CSC108, after we've done sorting, there was a peek on binary search, which was comparing target with the one in the middle of a sorted list, in order to get rid of half of the useless value.

As for BST, everything are well sorted when they are added to the tree, with the smaller value on the left, and bigger on the right. This inspires me in those recursion functions. After learning BST, I now realized that I can use those if statements to eliminate the steps, like putting a precondition in the very beginning of the code, to prevent the function from running when the value inputted is not eligible, and hence speed up my function.

No comments:

Post a Comment