Total Pageviews

Tuesday 3 December 2013

Different Sorting Algorithms + Last SLOG!

This is the last week of this Slog. I really liked this course. Was really interesting but also hurt my pride quite a bit. CSC 108 was so much easier than this course. I felt like the top of the world during that course. But this course I realized how big the competition is in computer science. There were many peers who were way beyond my level. They knew so much more programming than I ever did. Some already know around 5 different languages. And in lectures there were discussions at times that totally did not make too much sense but some students seemed to know a lot and were always raising their hands. I realize after taking this course how much of a long road computer science entails.

Now on to the sort methods. Lets discuss three different sort methods and their efficiency. First we begin with Selection Sort!

Selection Sort required n-1 passes in order to completely sort the list. During each pass the largest number is compared to numbers ahead of it until a number is found that is greater than it or it reaches the end of the list. Then the number is either placed before a bigger number or is placed at the end of the list if its the biggest number. During the first pass the biggest number is placed at its proper position and then during the next pass the 2nd largest number and so on.
Selection Sort is in big O of N^2
The problem is that as the list becomes bigger and bigger it takes too long for the list to be sorted. It is for this reason that selection sort is not very good for sorting really big lists.

Merge Sort is a recursive sort algorithm which recursively splits the list in half until two halves are split or in some cases there is a single number on left on its own (base case). In this case the list is already sorted. The two halves are sorted together and then the pieces keep joining together until the whole list is sorted. Merge sort is in big O of nlogn.
Selection Sort is more efficient than selection sort with it comes to larger lists. nlogn insures that every single number does not need to be sorted one by one. Instead the splitting makes the job much faster

Quick Sort is similar to Merge Sort but instead of splitting in half it finds a pivot value and then
uses the pivot value to split the list recursively. Quick Sort for the most part is more efficient than Merge Sort but if the pivot does not properly splits the list, then the efficiency of the sort is hindered.

Quick Sort was the best out of these three sorts from the examples I saw from lecture.

After looking at all the different sort methods I think Quick Sort is one of the harder ones to understand. It takes a while to get used to the idea of how quick sort works.
Merge Sort and Selection Sort are explained so easily and for educational purposes I like these two sorts way better.




Wednesday 27 November 2013

The new major requirement!

Now that the CSC major requirements have been changed I have to work extra hard now to get the best marks.

This did come as a shock to me because it happened so unusually. Usually I would expect such changes to occur starting next fall instead it happened midway this year.

I have been pretty paranoid these couple days. My mark in csc 148 is around the minimum required and as a result I have to really pick up my game and study all out for the final exam.

Tuesday 19 November 2013

What is the point of Trees anyways?

This is a question that has come to my mind a lot when learning about tree structures. They seemed too weird,useless and pointless to me until I did a simple google. Apparently they are used in 3D video games to determine what objects need to be rendered. Tree structure are also used to organize information in database systems.

These answers still do not satisfy my curiosity but they do make me happy because now I know that I  didn't learn something that would be useless or only useful as "learning tools". Theres is actually important uses for these trees!!!

With binary trees it makes things very easy when dealing with big data. Being able to insert, remove or search becomes relatively fast. This way data can be recorded without taking too much space.

One way why this would be useful is when trying to use a quick way to sort data. You would insert data into a binary search tree at O(log(n)). Then traverse the tree in order to sort them. With binary tree's the left child is always less than the root and the right side is greater than the root. This really helps when sorting. 

Though I did get the impression that binary tree's are the most useful trees and that other basic tree's are not that practical to use. Tree's that use BSTNodes are (from what I read online) not relevant anymore aside from being used as learning tools. 


Sorry that I missed last week's deadline. That is why this week you get you enjoy a double entry :)

Post Midterm Thoughts + other languages

Before the midterm I was very nervous about recursion and tree structures. It seemed like an up hill battle. But after writing the exam I realized how my persistence finally worked out in the end. The midterm was quite easy for me and I felt really happy being able to easily set up the recursive functions.

Believing in the leap of faith was hard at times. Because trusting your programming to run when you do not fully understand it can be rather daunting. But I can finally say that I believe in this leap of faith.

In other news I have been looking forward to a course called csc 207. We learn Java in that course (which I have no experience on) and it seems that a bunch of my class mates already know how to do Java/C++ etc. Furthermore throughout  csc 148 I have heard about how much different Java is to Python.

I hope that Java does not present to be too much of a challenge. But at the same time even though the languages are different I hope that my learning of python benefits me when I am learning other languages like Java.

It is going to be interesting to learn how Java deals with whites space, recursion, tree structures, loops than compared to Python. A senior student was telling me that Python is easier to learn and is not that strict. Other languages are way more strict. Sounds kind of scary....but the fact that plenty of students I know from csc 148 have some background on C++ or Java does show me that it may not be as hard as it seems.

Monday 4 November 2013

Assignment 2 + Bloated Code + New Tricks

Wow! Assignment 2 has sure been a crazy ride. I was certain this time that I would be able to work with 2 partners. But the unexpected happened as both my partners simultaneously dropped out of the course because they found the assignment 'too hard'. Now being stranded like this is rather annoying and depressing. But I was already working on the code and do not feel as bad as I would have if I had hardly began.

Although I must say that having the partners would have increased my chances of getting a really good mark.

Either way I must deal with this on my own :)

And speaking of crazy rides ... lets talk about bloated code. My code for assignment 2 is bloated like crazy. What I mean by bloated is that there is too many lines of codes. There are so many helper functions that it is making my head spin. I wish I had my partners so that perhaps I could have worked on it. But I do not have enough time and will have to hand in what I have.

If my program had been at its most efficient it would only be using one function but I guess I am not that good of programmer at the current moment to quickly come up with the best possible code.

But on the bright side this assignment once again got me to think really really hard. I learned new
tricks in python that I either did not know or was too lazy to know.

One such trick was a string method.
If you want to put a variable or an output inside a string here is how you do it:

example: A function f(x) return the number of hours you need to study give the course load x.

If I want to express the output in a string I can use this great method..
return 'I have to work {} hours'.format(what ever the output should be)

I always saw everyone else using this method but never tried it myself. But when I have
such a difficult assignment such as this I start getting practice on methods I would not normally use.
Now that I have practice in that method above I cannot live without it when coding in python.

Monday 28 October 2013

More recursion + assignment 2

Still working with recursion.......and recursions....... and recursions.......

But it looks like things are paying off. One of the biggest problems I had with recursion was that I would try
really really hard to think like the computer. Instead of thinking too much about the recursive steps that the computer takes, it is better to just understand how to properly write a recursive function.

I have yet to begin assignment 2 but do plan on working with a partner tomorrow. Hope the assignment is not as long as assignment one.


Friday 25 October 2013

Recursion

Try to Google "recursion"!!! Trust me!... it is going to be fun!

Recursion has been my main weakness so far. I usually understand what the exercises are telling me to do, but I always seem to be getting the structure of the recursion wrong. A lot of the time I get the base-case right but not the recursion step. I will try to do more examples of recursions and hopefully everything works out in the end.

If anyone has any advice do let me know :)