Thursday, 26 February 2015

week 7

Recently in class we've been focusing a lot of time on recursion. What it is, where it is found, and what uses it can serve. The first thing that stuck out to me with the concept of recursion was how it tackles a problem that is very unique, but also common in computer science.

Recursion is essentially a way of repeatedly accomplishing a task until the task at hand is solved or becomes the most simplified form that it can be. The term for this simplified form is the base case. The process which a recursive function works is that it looks at a given state of a task, runs itself to check to see whether or not the current state is the base case; if not, the process will perform a function to simplify the task by 1 step, and then calling on the function again to repeat the same process on the task in its new state. This will continue to loop infinitely until the task becomes it's base case, in which it is solved.

An example of this can be seen by this function in python that looks at every element of a list, and adds them together.

def listsum(numList):
   if len(numList) == 1:
        return numList[0]
   else:
        return numList[0] + listsum(numList[1:])

the important things to note to understand the process of recursion are the names of the function itself and it's input to run, the base case conditions, and the non-base case task.
This example takes an input of a list. This list can vary in complexity from being of length 1, to any other length. It's base case is when the list only contains 1 item in the list. If the list isn't 1 item in length, it will look at the first number in the list, and add to it the return value of the same function, on a list that has taken out the first value.
The function first examines the list and has an if statement to see if it is the basecase. if it isn't, the function takes the first number in the list and adds it with listsum(numList[1:]). So the function repeats itself until the basecase condition is met, and the sum of the entire list is returned.

. A nice part about recursion is that if designed correctly, it doesn't matter how complex the situation or problem is. It repeatedly examines the input and only compares it to see if it is equivalent to the base case, so it doesn't look at a problem a set amount of times.What makes this so useful is because it significantly reduces the amount of code that is needed to look at specific problems. It simplifies solutions while also making them more intricate and optimized

Wednesday, 18 February 2015

CSC148 week 5

This week we had only one hour of class due to our first midterm being on Wednesday. Class consisted of material covering how Unit Tests should work and how to import and execute them. The Unit test works by testing functions you've written in python and makes sure they have the desired outcome

The Midterm consisted of material mainly from the first few weeks related to Classes and Subclasses to create a student profile that could account for grades, and eligibility to graduate. Overall the test was not bad, and quite enjoyable.

The next days lab we learned and made another ADT, looking at how to make and use queues in the form of a list in which you can only modify the bottom and top of the stack with pop() and append(). Learning and making this class was relatively simple but also useful because of how often queues are used in everyday life.

Monday, 16 February 2015

Week 6

This week Heap introduced a system of data in the form of a tree. This data consists of leaves which, implied by the name, are branches off from the base bit of data. These branches of leaves can go to various levels and aren't necessarily dependent on each element in the level below which makes it interesting but confusing to comprehend and think about how it might be executed in python.

I'm kinda struggling with it both in class and trying to execute the various functions in Lab 6 which had to do with listing leaves of data by level and the lengths of strings for the longest branches in the data type. Overall not a huuge fan on this ADT and I don't really recognize how often and where to find this kind of data type being used.

Sunday, 1 February 2015

CSC 148 Week 4

This week has been rather rough compared to previous ones. This happens pretty naturally as we get further into the course so I can't really complain, but a lot of stress has been put on me on due to the Assignment 1 which was due just a few days ago. Learning and comprehending the material in class has been a nice curve that isn't too steep for me. That being said; the main reason this week was so tough was because my closest buddy in Comp Sci actually decided that there was too much that he couldn't figure out, and dropped the course before the first assignment was due.

Overall the course itself is going okay, the concept of recursions while complex, makes sense. Thinking about how a recursive function actually executes itself can make your head hurt but overall its a really neat idea. The other concepts we've done recently has to do with establishing classes and subclasses in python which has been interesting but useful.