Without access to TAs, computer science labs have become much more boring. I no longer have someone to joke about code with as I write it, or ask question after question to as I just can't seem to get a program to run. The TAs in CS tutorials are an anchor, and we get to choose how far we float away before we tug on the rope and they pull us back to logic and reason.
Not only have labs become boring, they have become harder. At first glance at lab08 i started day dreaming as I normally do when I approach any math/cs problem. I day dream different routes to complete the task, and then without skipping a beat I try to disprove myself in every way possible. As a maths student, this is how I have to think to create proofs and critique other theorems. Logic dictates all and I approach CS in the exact same way. I imagine all possible outcomes and then evaluate how to achieve it.
As I believed I was nearing a solution for insert, I came up against a wall. The fact that a node could be inserted in to many different parts of a binary search tree while maintaining it's properties. For example (I hope the formatting doesn't get screwy when I publish this post), the following tree:
10
|
----------------
8 12
is a Binary Search Tree. Now let me show two different possibilities for inserting the number 9 into the tree.
10
|
----------------
9 12
---------
8 None
Or we could have the following:
10
|
----------------
8 12
---------
None 9
Both of these trees are Binary Search Trees, and both are the result of inserting the number 9 into our original tree.
In addition to this confusing property. What if the node 9 already exists in the tree? Do I just do nothing since it is already there? Can I add it to the left OR right branch? Is there some prior protocol on inserting it to the left or right that serves some purpose I can't fathom at the time being.
This is what my daydreams have come to, a sort of skewed nightmare. So I wish the TAs were back so I could get mine to wake me up out of this nightmare and talk some sense into me.
Indeed, my Thursday mornings have been boring too without having 30 code monkeys to train! ..I mean, future computer scientists.
ReplyDeleteSo to comment quickly about your BST dilemmas up there: the default node insertion behaviour in BSTs is to insert a new node as a *leaf*. So even though your two methods above produce valid BSTs, the second one is the correct one -- according to default BST behaviour. Once you hit (8), you ask the question, is (9 > 8)? Answer is Yes => move to right_tree, and so on.
As for your second question about duplicate nodes in BSTs: it depends on how the tree characteristics are defined. If no duplicates are allowed, for example, then once you find the same value you just return nothing and leave the tree unchanged. If the tree is defined as: "left children are <= parent; right children are >= parent", for example, then you insert a duplicate to the left. Hope this helps! Good luck with your exam.