Friday 6 December 2013

Types of Sorting Algorithms.

Selection Sort
The selection sort, makes only only exchange for every pass through the list. In order to do this, a selection sort looks for the largest value as it makes a pass and, after completing the pass, places it in the last location.

Quick Sort
Basically, we partition the list into two, based on the pivot(which is always the one on the front of the list, L[0] in our case), on one side we put things greater than the pivot and on the other less than the pivot. Than, we perform the recursion of itself, on both sides to keep partitioning. and putting things into order, in the end, we merge them.

Merge Sort 
The online reading states that, "Merge sort is a recursive algorithm that continually splits a list in half. If the list is empty or has one item, it is sorted by definition (the base case). If the list has more than one item, we split the list and recursively invoke a merge sort on both halves. Once the two halves are sorted, the fundamental operation, called a merge, is performed". This in short in lecture is clarified such that, divide the list in half, (merge) sort the halves, then merge the sorted results. We use a helper function merge, to put it in order, as well as connect them together.

W9: Sorting

In class, we have learned about all sorts of sorting, and even online reading had different types of sorting as well. However, the coding presented in the online reading gave much more difficulty when trying to understand the code step by step. The code for sorting algorithms, given by the professor were so much more clearer and concise, as well as short!. Great use of recursion was seen in these codes, and to be honest, i was fascinated on how someone would think of these types of sorting codes..The online reading however, gave concise explanation on HOW the algorithm works. It had great representative diagrams as well.
Big-Oh and running time analysis, seems a bit vague to me still. Sudden appearance of math alike structure kind of gave me a scare i guess.

Thursday 5 December 2013

Trees Trees All sorts of Trees.

     This week we go in depth about trees, specifically Binary Trees. At lecture, I was just staring at what the prof was doing, and once I got home and started looking at the code, I realized how complicated it was... even more so than the tree.py file. The Binary Search Tree file was..just.. wow. I knew the deleting process would be very very complicated, but I didn't know it was going to be so hard to follow. It took me a long time to understand it, again using examples, but now I worry.. How I'm going to program all this by myself, or in tests.. Feeling very frustrated again. I read the readings the prof posted for trees, but It seemed to be just the review from last week's preorder, inorder, post order stuff.

Linked Lists

       I have read what prof posted about Linked Lists, and thought it was very straight forward after actually trying to code some of the linked lists exercises.
       In the tutorial, we had to implement class Queue. It was a bit tricky at first, but once I realized that I needed to go about from both front and back direction, the coding became a lot easier to do.
      The tree.py code posted took a long time to get my head around though.. the nested functions were very unique, and on top of that the nested functions had a recursion of itself. I don't know if it's just me, but I couldn't do all that in my head.. so I had to draw and follow everything using a set of examples. I put it in the visualizer.. but wow... it makes it so confusing, or should I get used to that, I'm not sure. But once I got it, it was a very good feeling :).

Tuesday 3 December 2013

Week 6: Term Test One!

Term Test one was this week, I felt that some questions were very similar to that of what we did in tutorials. Thankfully. But, question number 1 got me, and using len on Tuples was very unclear.. Probably got that one wrong. I felt that I needed to learn to think faster, since it was only a one hour test.. Only way to establish that is to have a lot of practice. The recursion problem was somewhat same as what I did in  tutorial, but if it was something I have not seen yet, I think it will take quite some time for me to figure out the correct code for it.

Object Oriented Programming / Recursion.

Object Oriented Programming    
  I read about Object Oriented Programming from the week 1's required materials. I read from openbookproject.net that, "It was developed as a way to handle the rapidly increasing size and complexity of software systems, and to make it easier to modify these large and complex systems over time".  Object Oriented programming's focus is on the creation of objects, which contain both data and functionality together. (I'm still confused about the idea of objects, what it really means, and... it seems just a bit ambiguous to me right now). Stated on the same website says, "Usually, each object definition corresponds to some object or concept in the real world, and the functions that operate on that object correspond to the ways real-world objects interact.", I thought about this sentence, and got me to ask myself..hmm what kind of real-world object interactions would represent the for or while loop.. and actually put my mind into a while loop that couldn't be solved..
  
Recursion
      Recursion. I heard many of my friends in the upper years in programming say that it is the beauty, the blossoming flower of programming for some reason.. I didn't know what they were talking about back when I was in csc108, but, when I saw how it can be used to put a repetition to an end, and put in into few lines of code, I realized why they said that. For me at the moment, recursion does not come easy. Actually, it is pretty hard. I know how to go about doing things in the looping way, but than converting the loops and repetitions into a recursive method doesn't come automatically to me right now. A function inside a function, I don't know if I lack brain power, but I have to write everything down draw it, or look using the visualizer to understand every piece of my code when using recursion. (but, the visualizer, is really hard to work with when doing recursions..).
Clearly, I think I need a lot of practice doing recursions.
Also, some say that recursion is less efficient than using iteration in forms of for and while loops. But when I asked the professor, he commented that, it is in the old days, when computers were not powerful enough, but nowadays, using recursion is a much more efficient method to coding.

Week 5

This week, A1 was due. It was very hard for me to look at someone else's code and implement my code on top of it. It took me so long to understand their code, and how one relates to each files.. Maybe because my understanding of classes and subclasses weren't so perfect. Also, The tour.py file really got to me..I didnt know what to do for that part, and was frustrated staring at the question. I think I should seek for help when I am stuck, and start early, so I have a chance to think. I felt that if I try to cram for a computer science programming, I will not be able to solve it. It requires a lot of thinking and brainpower unlike the csc108.
Also, trees were introduced this week, and I didn't understand what was what really, so I actually googled about it, and found a nice picture explaining how the pre-order, post-order, and in-order traversal works.