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.

Friday, October 25, 2013

sLog Struggles

I'm sure complaining about sLogs is also part of the sLog process. I dislike sLog's greatly, I think they're a waste of time for me. I actually quite hate them, I actually hate the whole idea of many tiny assignments holding our grades hostage. I think courses should just be two to three big assignments/examinations, I feel like this idea of constant engagement arrests the creativity of students. Imagine a course where someone just lay out all the information and says "This is what you need to know and demonstrate that you understand under novel situations to be considered proficient" then they proceed to give you certain dates certain things are due. Imagine the time the student would have? An industrious student would be able to say "I'll learn all this at my own pace, doing somethings early and doing others at my own schedule." Heaven forbid they could even be given this knowledge beforehand? I think this system is outdated and personally frustrating.

When you think about it, adding up the exercises, exams, assignments, labs, slog entries: are marks are distributed between 31 separate events. I think there's a much lower and reasonable number.

Friday, October 18, 2013

Recursion pt. II

I decided to write another post on recursion, since it's been giving me so much trouble. I think it's just a matter of syntax but I struggle with implementing it correctly. It's as if I understand it logically but I just can't get it to do as I desire. So I find my self working from an iterative perspective for most of my code even though I'm told that recursive methods are much easier and more powerful. I'm hoping that before Test II I'll have a much better grasp on recursion because I find it's the only portion of the course I'm struggling with. The main issue I have is in turning a problem into a recursive implementation, for example a fully parenthesized equation. I understand doing the idea of recursively solving portions but I wouldn't understand how to use the parenthesis to control that process. It'd make more sense to me to work through the equation front to back using the parentheses to control the iterative process, like I said something I'll just have to devote more study time to. I guess.

Friday, October 11, 2013

Object Oriented Programming\Recursion

Object Oriented Programming:

A programming method that has an "object" type representation of data. This is very useful, I have programmed PLCs in the past and those are clearly clearly not object oriented, more like objective oriented. Exposure to PLCs were actually the reason why I got into programming, I enjoyed the idea and practice of programming so much that I decided to go into Computer Science. What makes object oriented programing so useful is it allows for a more conceptual representation and manipulation of data, while PLCs were more straight logic. There are things you could do in OOP that you wouldn't even try to attempt in ladder logic unless you had a serious propensity towards self flagellation.

Recursion:

Is a method where you solve a problem by repeating steps of the problem that are essentially smaller instances of the original problem within the original problem. This differs from looping and while loops in a crucial way, there are some problems you just need to tackle recursively. Recursion is very useful because it allows you to tackle problems of indeterminate size that have the same property. How would I search a nested list with loops? I would need to know the depth of nesting (I would, maybe there's a solution someone else has where you wouldn't), while in recursion it doesn't matter the depth of the nesting, whether it be 2 nests, 5 nests, 10000000000000...., etc, recursion could handle it the same way and that's very useful.