Tuesday 1 April 2014

Life Problems: It Takes Time To Sort Things Out

    Wow, time flies, especially when its a good case scenario for sorting. Its already the end of the term, and CSC148 is coming to an end. One week of classes remain, and then it's time for finals. Looking back at all the concepts we've learned, sorting was quite complex. There were many sorting methods; bubble, insertion, selection, merge, quick. It was also possible to combine multiple methods, dictating which sorting algorithm to use depending on the condition (i.e. length of list, length of segment being sorted, etc).

    The earlier sorting algorithms we touched upon (bubble, inserting, selection) were the less complex sorting algorithms, usually having a run time of O(n^2), were easier for programmers and coders to re-create on their own, and could handle small arrays of items to sort with ease. The problem is when the array of elements becomes too large. For example, using bubble sort, given the worst case scenario, on a list of 10000 elements means that we'd have to compare the first element (position 0) with the remaining 9999 elements, moving it over each time until it reaches the end of the list. Then the new first element at position 0, must be compared and move with the remaining 9998 elements... Repeat this until we reach comparing the first element with none, since the rest are sorted. Bubble sort takes a run-time of O(n^2) meaning it'd take 10000*10000 steps to sort the worse case scenario list of 10000 elements.

    To solve the problem of taking hours or days to complete the sorting, programmers and coders had developed more complex, but stronger sorting algorithms, such as merge sort and quick sort, which have O(n log(n)) for worst case scenarios. Comparatively, merge or quick sort takes significantly less time to sort larger arrays of elements than bubble, insertion, or selection sort since the big O comparisons are n*log(n) against n^2.

    Some people may say that sorting methods and algorithms are redundant, since there is no need to sort the elements if you can just dive into the array and search for your desired element. However, sorting an array can help provide further insight on the elements and certain properties of the array, and can also help detect a possibility of a pattern in the elements. Sorting an array can also reduce consequent run-time of searches because you can narrow your range for searching in a sorted array since you know approximately where to find specific elements.

I've had some friends tell me that computer science isn't something you could easily apply to other courses or situations in life, but I've proved them wrong with sorting! Finals are approaching... I can leave all my notes unsorted and spend an extended period of time every time I wanted to find a certain note to study from, or I can spend a small amount of time to sort my notes in chronological order. this way, when I want to find a note from somewhere between mid-February and early-March, I know I can spend less time looking for it by looking only between the first quarter and the middle of my notes since that would correspond to the notes taken within that time frame!

HAH, take that non comp-sci friends! Computer science is everywhere!... Now, lets determine how long it will take me to use insertion sort to organize my notes.... Will it be in the minutes or hours....

Sunday 2 February 2014

Recurse on Recursion So I can Recurse on Recursion

So in the latest week of CSC148 lectures and labs, we've dealt with analyzing recursion as well has making our own sub-classes of Exceptions.

I have had previous experiences in applying recursion in my own programs before enrolling in this class, but combined with new concepts we learned in the previous lectures, recursion seems slightly hazy for me. It might also be due to the fact that I never properly learned recursion, aside from its concept and brute-force recursion to only catch stack-overload errors in my programs. I feel it's necessary to go over the material times to even begin to understand it. It's like I got to do recursion for learning recursion in real life. Mind is almost blown.

Errors/Exceptions were like a straight-jab when I was expecting an upper-cut... I have never done Errors nor Exceptions (custom or pre-made) in any of the past programming languages I have dealt with. The try-except was more familiar as I used the equivalent try-catch in Java, but I used it only simply knowing that when my code in try failed it completed what was in the except block. With our most recent lab (third lab) I was able to understand the try-except concept and its relation with errors and exceptions.

Lucky for me, we will still be dealing with recursion in the upcoming lectures, so I have time to catch up on recursion before it explodes in class.

try:
    to leave
except:
   you have to stay.

maybe

Until next time,

Raymond

Thursday 23 January 2014

Starting Afresh In Life

It's January 2014, new year, new start, and my second university term has started for about 3 weeks. We've covered Object Oriented Programming pretty nicely in CSC148 (computer science cource at UofT), even touching upon making our own classes. I'm someone who's highly interested in programming, so I already knew about user-defined classes, instances, and attributes in OOP languages (such as Turing, VB6, Java).

However, CSC148 was quite a big change for me. I have learned new things about classes and instances of user-defined classes, mainly about manipulation between the two. The initial example the professor had shown to the class, about the class Turtle, showed me how applying methods and variables to the class (i.e. doing Turtle.neck = "green") would cause said methods and variables to be applied to all instances of that class, including previously created instances. Additionally, I have learned about __methods__ other than __init__, which have proven to be useful and more efficient than creating my own versions of those __methods__.

Lastly, I had touched upon inheritance in Java, but with the introduction of composition, the two have becoming slightly fuzzy to my understanding. It may be a lack of understanding of inheritance, or just prolonged period of time with no presence of inheritance in my own programs, but inheritance and composition feel no different to me, which is wrong since there would only be one if they were the same.


I should do small side projects outside of the assigned exercises and labs require for this course to strengthen my understanding of whatever programming concepts seem blurry to me.


This isn't the end, this is just the beginning,
See you all next week -

Raymond.