Friday, 8 November 2013

Test: Round Two

And so begins the second round of Tests. I think the things that killed me the first time all amounted to me not reading the question right so I going to make sure that I do that. A2 went well, I worked with a partner this time so it was nice to bonce off ideas with someone. A2 took a lot less time, partially I think because it was easier,  but also because I spent a lot more time considering the most basic cases before I wrote anything. More time thinking = Less time writing code = Less time doing homework overall.

One of the things on the test will be binary search trees. The most complicated thing to do with trees seems to be deleting nodes so Ill now explain that here:

- first check if this is a child of a leaf (ie None). In that case we didnt find the item we wanted to delete in this branch so return None. This is the simplest case
- Then check if the item to delete (ITD) is smaller then the current Node. If that is true the ITD is in the left subtree so look in there.
- Then check if the ITD is greater then the current Node. If that is true the ITD is in the right subtree so look in there.
- If the ITD is not smaller or greater and the Node is not None, that means we have found a match. And should remove it
- We can do this by first checking if either child is None, and if this is true then we can replace the node with the other child
- If neither child is None then we can either replace the node with the largest item from the left subtree or the smallest item from the right subtree. We then need to delete the original item we just moved.

No comments:

Post a Comment