Saturday, 21 March 2015

Impressions on Modifying BSTrees (Week 10 SLOG)

Last week we revisited an idea that we had just touched upon: binary search trees. As I had wrote about before, these trees are unique in that each internal node has a maximum arity of two, the data in the nodes are comparable, and the data in the left node is always less than the data in the parent node, while the data in the right node is always greater than the data in the parent node. This specific structure must be conserved when we add or delete nodes from the tree. On the one hand, because humans can view the entire tree in a single instance, we can easily make decisions on which node should go where when modifications occur. Computers, on the other hand, follow a more linear path and can only look at one node at a time, therefore an algorithm must be made for different situations. For example, the algorithm for deleting a node has 5 different scenarios that must be accounted for. I agree with Heap that a good way to go about writing these solutions is to write out what you want your code to do in plain English first. Write comments as often as you can to explain what your code is doing, so that in the future others can understand your code as well. Ultimately, whatever you write in English can be expressed in code.

No comments:

Post a Comment