Thursday, 28 November 2013

More Binary Trees

Today in the lab we worked on an interesting new approach to binary trees. Rather than using a separate class for each node in the tree we kept track of every item using the built-in Python list class. There's one condition with using this technique and that is the tree must be fully complete, the items fill up the levels one by one from left to right. For example if your tree contained these items [1, 2, 3, 4, 5, 6] the tree would always look like this:
But it could never look like this:

Every level must be filled left to right no matter what. This implementation is interesting because the only information you have about each node is it's index in the list. This means that in order to find its parent or child nodes you need a formula that takes the nodes index and outputs the index of the parent/child. I was able to find this formula by writing out the the first 4 or 5 cases and looking for a pattern. For example, the index of the left child 'j' of a node at index 'i':
 i      j 
0 -> 1
1 -> 3
2 -> 5
3 -> 7
Then using this data I tried to find a pattern. In this case j = (2*i)+1, so the index of every left child of a node at index 'i' is equal to (2*i)+1. After finding the patterns for navigating the index's for parent and child nodes you could put them into methods and basically use the same techniques for solving inorder, max_sum, etc. 

Thursday, 14 November 2013

Term Test 2

So yesterday we had our second and last term test. I think I did alright, I have a feeling I messed up the first question but I know I did the other two correctly. Two of the questions were on binary trees and one was on binary search trees and linked lists. I was expecting to see some Big O questions on it but there weren't any. Hopefully when I get this test back I can also pick up my first test because I still haven't gotten around to it. I don't even know if they would keep it for this long, at minimum I'll find out what mark I got on it.

No classes or labs this week because of the fall break in combination with the midterm.

Tuesday, 12 November 2013

Term Test 2 Coming Up

This week we got today and yesterday off for fall break and remembrance day. Tomorrow is our second term test, time to get studying! I feeling slightly less confident about this one because its not completely review for me, a few things are new concepts. I'll probably read over all the lecture slides then finish the labs I missed or didn't complete and hopefully I should be ready after that.

Thursday, 7 November 2013

Assignment 2

So I didn't go to any lectures the last two weeks. Probably wasn't the best choice but I'm finding it no problem keeping up with the material being covered. I went to the lab today but unfortunately missed the one last week. Today we had to implement certain methods that worked around binary trees and linked lists which I found to be challenging at first because of how new I am to linked lists.

Our second assignment was due a couple days ago, we had to implement regex and match them to strings. Regex are completely new to me but after reading over the outline a few times then checking piazza for how hints I was able to quickly throw together something that ended up working. There were a couple bugs in my code that I took some time to work out. For example, when a DotNode is in a StarNode my code would return false when matching the regex to a string. The error was the way my code checked to see if a StarNode matched the string, it iterated through every single character and matched it to the StarNodes child. I realized the reason this was giving me errors was because with a DotNode the string is more than just one character long, I had to find a new way to match StarNodes. I was able to solve this issue and then used all the test cases posted on piazza to make sure that everything worked properly.