Friday, November 29, 2013

Sorting

Selection Sort:
I think selection sort is the most intuitive of the sorting algorithms, there's something natural that makes sense with this one that I don't immediately find in the other sorting Algorithms. I think if before I encountered this if someone were to ask me how I'd sort a list it'd be something similar to this. I can see why it's not the most efficient but its intuitiveness is nice.

Quick Sort:
Is definitely an application that someone who naturally thinks recursively would come up with. I've seen this sorting algorithm before this class on a Youtube channel I'm quite fond of called Computerphile:
http://www.youtube.com/watch?v=kgBjXUE_Nwc
This is the episode where they explore a few sorting algorithms.

Merge Sort:
Again I'm always surprised about how other people think through problems, I'm sure it's just because our knowledge bases are different. I imagine that once my knowledge base grows with time the things I'll be able to think of will be equally impressive to someone currently in my position now.

Saturday, November 16, 2013

Term Test II

I know I didn't do so well on the term test, I starting working on the first problem and thought I was making some reasonable headway by the time I got to the third problem I realized I was making a crucial mistake, so I backtracked and redid the first problem then I tried correcting the second problem but by that time I was running out of time. I figured cross out what I put on the last question and write "Did Not Know" to salvage some marks and I ended up leaving the second question incomplete. Wasn't my finest moment in examination history to be honest.

Saturday, November 9, 2013

Assignment II

Finished my Assignment II, didn't completely finish it. I finished the first half with some major redundancies and threw together a knowingly constrained second half. I'm still having issue with recursion and I haven't applied the effort needed to fully comprehend and take advantage of it. As such, doing part one of the assignment was pretty rough and I could barely conceive of a way to do part two.

def regex_match(r, s) -> bool:
    '''Unfortunately, unfinished.
    '''
    if isinstance(r, RegexTreeNode):
        if s == '':
            s = 'e'
            return str(r.symbol) == s
     
    if isinstance(r, StarNode) and len(s) == 2:
        return r.children[0].symbol == s[0]

Basically my part two takes care of a bit of the star node cases in order to scrape out a few marks, not the best but better than nothing, I was also considering a random True or False generator to see if I'd be able to trick the marker but then I thought better of it.

Saturday, November 2, 2013

Exercise 6

So I've finished Exercise 6:

    def __contains__(self, item):
        """(BST, object -> Boolean
        Check to see if obect is contained in BST
        """
        #traverse the BST
        parent, current = None, self.root
        while current is not None:
            if item == current.item:
                return True            
            elif item < current.item:
                parent, current = current, current.left
            else:  # item > current.item
                parent, current = current, current.right  
        return False

I'll just talk about my technique for solving the first portion, I set a while loop that basically traverses the BST and compares the values with the item until it either finds it or terminates at the bottom of the list. Looking at the code it seems saving parent was unnecessary. I could have just set current to current.left or current.right dependently? I wonder why I found it necessary to create the parent class? Maybe I thought I needed it at some point also I'm sure I could have compacted this code even more so. That's something I'll sit down an look at.