Sunday, March 30, 2014

Sorting and Efficiency - Week 11

#You know when you have a lot of rocks and always wanted to sort them from smallest to largest or you must organize books in alphabetical order? It looks like you need some sorting algorithms. OMG WHAT IS THAT? I'll tell you what it is, it is a revolutionary concept. For only $29.99 that you just paid for looking at this blog.#

Okay past this nonsense that I have posted, sorting algorithms are methods that can be used to organize piles and piles of junk in the correct order that are needed to be sorted such as ascending from smallest to largest, visa versa, alphabetical order like my example above, anything needs to be rearranged can go through a sorting algorithms and become sorted. Now here are some sorting algorithms to get you started on your journey through the many different ways to sort, merge sort, bubble sort, quick sort, insertion sort, selection sort, heap sort, and many more. All of these use different ways to sort:

1. Insertion sort - Good for small lists/sorted lists
Method: Sorts the list from left to right placing with each item it moves onto moves the chosen item in its correct place in the sorted portion leaving the left side of the list sorted and right side unsorted.

2. Selection sort - Same as insertion but worse
Method: Searches through the whole unsorted portion of the list looking for the lowest value in the unsorted list. Once the lowest value has been found it swaps it with the first item in the unsorted side of the list.

3. Merge Sort - a very stable (the element order) and popular sort
Method: The Divide and Conquer algorithm. In simple terms, it takes the list and splits it in two and continues to split it in half until it reaches only piles of two. It then splits each pile of two and the compares the two of them and places them in order. It then proceeds to merge them back together placing them in order comparing with each pile next to it.

These are just some basic examples. Quick sort though is one of the most interesting because out of all of these sorts it uses a pivot (a chosen item). From the chosen pivot (some use the last item in the list or the middle item in the list, this can change how efficient it can be) it sorts everyone lower than the pivot on the left and everything greater than the pivot on the right. These groups are unsorted the only item that is definitely in the right place of the list is the pivot. It then chooses a new pivot on the left group (middle or last, depends) repeats until it everything is sorted left and right. This is done for the whole list.

I hope you enjoyed the basic explanation of sorting algorithms and how they can affect efficiency.

Quick Sort - Versatile

Monday, March 24, 2014

The Random Midterm

Writing in the middle of the night for a blog at 2:30am is not a good thing. I write this simply out of the fact that I am not tired and may have some sleeping issues. This also may be related to the stress of the midterm that is coming up on Wednesday. This midterm to a lot of people seems to be very misplaced considering that in the coming weeks is the long awaited final exam. Assuming that this midterm is covering most of the topics that have been covered in labs and lectures means the test will ask questions pertaining to helper functions, linked lists and possibly sorts (sorry if I may be missing something). Last weeks lab left a lot of people troubled considering it took most of the tutorial to do just step 1-2. It is very troubling not knowing what is going to be covered and if its everything we have done since the first midterm then I feel screwed :(. Oh well its cram time, no screw ups, buckle down for storm that is coming because its going to be a rough one.



Wednesday, March 5, 2014

Recursion - Week 7

Recursion is the process to repeat something over and over again in a similar way. Such as the idea of mirrors facing each other to repeat something indefinitely. In computer programming, recursion allows for programs that can require paragraphs of lines of codes to simply a single line of code. With just an if statement the code checks each time the method is run and when the recursive process arrives at the condition it needs to be then it returns an item ending the recursive function and going all the way back through each recursive depth until it reaches back to the first one.

Here is an example of a recursive program:

def f(i):
    if i > 0:
        return f(i-1) + i
    else:
        return 0

This program will return the sum of the sequence of i to 0 such as i = 5 so 5+4+3+2+1 = 15. Otherwise, this program will return 0 (anything <= 0). This can be done through other methods, but it is simpler and more efficient with recursion.

Now for my above explanation I apologize, it may be confusing for two reasons.
1. Recursion can be a very confusing concept and,
2. I am very bad at explaining things.

Everyone in class is at the point where they are able to trace recursion somewhat easily, but the hard part is to visualize it for a problem presented before them is still hard. Granted I am still trying to make this process easy through practice and just from seeing other recursive solutions. Recursion will be one of the best things you can find to do many hard things, easier! The Fibonacci sequence is one of the problems you can easily figure out using recursion. It makes programming way easier than hard coding it. It would take forever to be able to hard code the Fibonacci sequence using only for loops. Its a good thing you know recursion because (photo):

Tuesday, February 11, 2014

Operation Meltdown

My need to write right now is only equal to my need to do assignment 1. IT IS CRUNCH TIME. Something that most will call operation meltdown. The cheeses are melting off their stools because of the nuclear bombs that are going off everywhere. It will be difficult but having someone else to figure it out with is a good thing to do. Discussion with another peer is good for you and him/her because this causes both of you to look it at a different perspective and learn from each other. Just make sure to not get lazy and make your partner to do all the work because that is not good for you as you will learn nothing from this assignment, let alone this is unacceptable. 

Thursday, January 23, 2014

Object-Oriented Programming - Week 4

Object-oriented Programming. What is it? Is it something you eat or throw? Maybe it is something you use in sandwiches. NO. It is one of the most essential programming methods that is learned when you take Computer Programming. You use it to store lists, dictionaries, all sorts of data fields and maybe add a one or two hundred methods into there make your class nice, fancy and productive. Did you know that you can do math using your computer? You can do it in python as well. You can also make it so that 1+1 = "fish", you know the teachers were wrong now you can make it a reality; isn't programming fun.

Personally my experience in this class so far has been pretty enjoyable. I have had almost no trouble with most of the classes discussed in the lectures. Exceptions is not a brand new concept, have used it before in Java, but did not know how to do it in python. Making your own exceptions is a pretty cool thing. Recursion is one of the trickier subjects that I have confused myself with before. It is not hard though.

The way Professor Heap prepares his lectures is very nice he has slides, example classes/programs and discussion. It is a phenomenal teaching approach that I prefer over the video lectures, seems like a better way to go when using the time for these lectures. It also helps when I do not need to watch a whole video on any information I need, it is accessible from the organized notes that have been provided. I have mostly enjoyed the fact that he constantly says programming is about being lazy, which is a joke, reminds me to make it simple from always using a loop to just 1 line of code.

Taking from what I have learned from a friend in this course, it is a good thing to make most methods or classes simple enough to reuse them in future projects. Being able to use something over and over would help me save time and I would know for sure it would be reliable. 

Some people may say this is just an introduction class, but the first step is the most critical of them all. Without this where will you be next year? You would go into a 200 class and know nothing about "Object-oriented Programming" which is very important.