Tuesday 1 April 2014

SORTING!!!!

This post will be in regards to the sorting algorithms. For the most part, the sorting algorithms are relatively easy to comprehend. The bubble sort, insertion sort, and selection sort, are all sorting algorithms that were covered in CSC 108, they are simple and effective methods at getting the sorting job done without much thought. These are obviously not the only sorting methods out there. The new ones that were introduced consist of shell sort, merge sort and quick sort. The shell sort is by far the most confusing, i have little to no understanding on the way it works, and ive been trying to wrap my head around it, i am probably going to just try staring at it and doing examples on my own of it until i get the understanding on it. Its use of some gap system to make incomplete sorted lists that slowly make it better is just confusing and seems horribly inefficient. The merge sort is pretty interesting within itself, it was a bit confusing at first but when you see it drawn out and shown graphically the understanding is much easier. Basically it makes sense that if you keep splitting things up until they are in pairs and you sort all the pairs then go up until you end up with the final sorted list just seems logical. And finally there is the quick sort. The quick sort was also very confusing and frustrating to understand, however after going over it a few times and really drawing it out i came to understand how it works. The use of a pivot point to create two sorted lists of values greater than the pivot and lesser than the pivot, then sorting those both seems to be pretty fast and more efficient than the merge sort in terms of divide and conquer strategies. In sum, with the sorting algorithms for the most part were fairly easy to grasp, and my difficulties lie with the quick and shell sort, ive been trying to understand them better but im still working on it, either way i will continue just practising both sorting methods till my understanding is more concrete.

Thursday 27 February 2014

Hello all, and welcome to my post about recursion. Now for those of you who aren't in the know, recursion is simply put, the definition of something by itself. In other words, its to when something uses its own self to define itself. Now although that concept may seem pretty vague and strange, but when it is applied to programming, it leads to some of the most interesting and really effective code you'll be writing (at my current level of programming). When recursion is applied in programming, it basically means that a method or function can call itself during its own execution. Take that in for a minute and really absorb the insanity behind that. You can basically call a function on itself to get to the results you want in a more user friendly way. For example, lets say you want to count the number of occurrences of a number within a list, now that list also contains sub lists, and even those sub lists contain sub lists of sub lists. Now that's a lot of sub lists, you could run the function multiple times on each individual list of sub lists and then add it up, or using recursion, you can write yourself up a function that will not only do the counting of occurrences for you, but also do the count inside of each sub list as well. Now in that specific case, let's say you make your accumulator for the occurrences of n, now for each item within the list L, if item is the number you're looking for, we add to the accumulator and we leave happy, otherwise, if L is an instance of list, then what you do is you call the function or method you are defining on the item and add it to your accumulator, that way it will make its own accumulator, check each item within, if the item is n make its own count, if its item is a list it will go again even deeper. Now like this, you'll be able to go into how ever many lists and sub lists you want, of course you will also need to make sure the function returns the accumulator so that when its called recursively, it has a value to give to its superior's own accumulator. So that is the simple definition of recursion, as well as a simple example of when and how you would implement it. Recursion can also be found at various different levels, including the case of Trees in CS, a tree is a recursion in its own rights, each node branches to two other nodes, that branch till their own nodes, with the exception of the leafs. Writing a Tree, or to display a Tree in python would absolutely require recursion, that way you could check each nodes value, and their children's value until you can't go any lower, and then it would move on to the next node.

So that is the quick rant of the week, about the Inception like recursion, this is something that can be confusing at times but is really effective when you start thinking recursively. As always this is merely my definition and if it is at all wrong I apologize. Thank you for reading.

-Just a CS student

Tuesday 4 February 2014

Exceptions

So this post is a little bit late... I had intended on posting it last week, but life gets in the way and other assignments take up more of my time. Anyway, last week we had to do an assignment as well as a lab in which we utilized a wonderful class known as exceptions. Now for those of you reading and who don't know what an exception class is, to put it simply, its errors. An example of an exception class that I think is the easiest to picture, would be the "ZeroDivisionError". This is an exception class that is flagged whenever the function for division encounters a denominator that is equal to zero. Now the really interesting and cool things about the exception class, is that like any other class, you can make your own! Now it probably doesn't seem that cool at first, but, through making your own unique exceptions, you can put in a few new levels of depth to any of the functions that you write. For example, lets say that you make a function that prints a "happy x birthday!" string. Naturally you would just have the user input an x and concatenate it to the string. Let's say somebody tries to mess around and inputs a negative number. Now it is impossible to have a negative age, so you can create your own exception, let's call it "NegativeAgeError", and raise it if x<=0. Now should someone try to input a negative number, not only will it not be accepted, but the user will be given information, in the form of an error (with a message if you so choose to add one, because you can), as to what they did in order to trigger an error. One last point about the exception class that I absolutely love, is that you can make your function work around the errors so that your program doesn't crash. Lets go back to the "ZeroDivisionError" just because its easy and I wish we could divide by zero. Anyway, let's say your function takes in user inputs for a denominator, and applies it to a specific numerator, and let's say the user chooses 0 as his denominator. Normally, this would cause the error to be raised and exit the program, however, if you so please, you can utilise the except command with the "ZeroDivisionError" as its argument in order to make it so that if that error should be triggered, your function ignores it and acts like nothing happened. Personally I love the idea of just pushing problems right under the rug.

Well that's it for what was supposed to be my rant last week on the exception class, which is by far now my favourite class(so far).

- Just a first year CS student.

Thursday 23 January 2014

Blog purpose, and OOP

Hello all!
I am a CS student studying at the University of Toronto. Now, I've never written a blog before, I hardly ever been on a blog either, so this is very new to me. Nonetheless, it has been required by my Professor for my Introduction to Computer Science Course to write a blog of my very own!

Now for most of the time, I'll probably just be ranting about my lack of understanding of some material. I may even write about how I spent 3 hours the night before my assignments are due, trying to write a single method. However there will be three posts where I will be specifically writing about one key element of programming in python, indicated by my Professor. So without further ado, let the inaugural blog about my CS class begin with one of the three mandatory ones, Object Oriented Programming! (OOP)

So to begin with, what exactly is Object Oriented Programming? (OOP, is how I will refer to it from now on, as I am too lazy to continuously write that out) Simply put, it is a method of programming, where instead of just creating code that serves a single purpose to any arbitrary piece of data, you create entire objects that have their own unique data that can only be explicitly modified by the methods within the constraints of the Class of the object. In a sense it's like fusing both code and data into one entity that can't be modified by some arbitrary code. This however doesn't mean that once you create an object, it is completely separated and isolated from all of it's object peers, it is possible to also extend an object through the use of "combining" it with another object, in a sense of sub-classing the object. In this manner you create objects that have their own individual meanings and constraints, but have the capacity to be accessed and be manipulated by superiors, or super-classes of the object. OOP is a great method that allows clear and concise programming which can be easily maintained and tracked through the exclusivity of each independent object, allowing one to also have a greater understanding of their work, due to the creation of every object and of the decisions related to sub-classing all managed by the programmer himself. In short, OOP is a simple and effective method of programming that is capable of evolving the most minor of programs or objects, into grand and elaborate, yet simple to understand programs.

This is what OOP is to my knowledge, if any of this is wrong I apologize to my readers, I am a first year student after all.

That pretty much wraps it up for my inaugural post. Hope you guys enjoyed reading, and cringed for less than half of the post.

-Just a first year CS student.