Wednesday 2 April 2014

Sorting and Efficency

Sorting and the algorithms/ techniques that have been developed to sort, are useful in computer science. Essentially sorting, as the name suggests, is sorting elements of a collection in a certain way. These ways vary, and can be sorted alphabetically, by length ect. The algorithms used for these different collections of elements are chosen to sort a specific collection either because they are the most efficient(relative to the number of elements being processed)/quickest run time, or are appropriate for the collection. To choose the most efficient algorithm, we compare them all to see which one took the least amount of steps/ switches. The algorithms are; bubble sort, selection sort, insertion sort, shell sort, merge sort, tim sort, and quick sort.

Thursday 27 March 2014

week 10

I found assignment 2 part 2 hard, mainly is_regex and figuring out how to work with the different trees. I spent a lot of time on it and learnt more about recursion and making base cases for the simplest cases, as well as breaking bigger problems up into simpler ones. I learnt about not wanting to set a parameter to an empty list, because it gets very complex. Rather to check if there is a list already and if there isn't, then to make one. Also, in the lab this week it was about linked lists and binary tree. What I found difficult about this was manipulating individual nodes and accessing different parts of the lists.

week 9

I find the binary search tree interesting as well as the method to implement it. It seems so simple but gets a bit complex for myself when coding in regards to deciding if a node is smaller than the next node and how to place it. I will keep going over this until it clicks for me. I do appreciate that the Tree class can be expanded into more complex codes and structure, that use its basic structure of data which connects to a left and right subtree. I learned from the exercise that a preorder and in order traversal can give you enough information to make a tree. I didn't exactly understand the algorithm performance and behaviour part or how it co-relates to how fast an algorithm will run or how to read the informations given for this?

week 8

I used to confuse the idea of linked lists, with them being one item like a list. Now I realize they are individual items that can be connected, but in a way are still individual. It was useful for them to be explained as either a value with a list connected to it (as if there are only two "items" or as individual objects referring and connected to other objects. I don't understand the point of a wrapper function or more specifically how you use it? I find linked lists interesting and I will keep reviewing the slides, codes and and practice exercises I find, to grasp a better understanding of them. I felt that part a of assignment 2 went well and actually bettered my understanding of tree's, their class and traversal. I was worried before that I wouldn't get a good opportunity to really understand them, but the assignment helped break them down. Even though the assignment was troubling in understanding what it wanted in the beginning or even grasping what regex was. After spending some time with the handout for this assignment, I felt I got the picture.


week 7

I find it interesting that tree and lists and recursion can all be combined to create linked lists. Do nodes the hold data, if they contain cargo? Can there be more then one thing of data in a node? Why is the empty list represented by None, why does there have to be something in the linked list, is it because it has a certain structure, where certain elements have to go? For the second part in a linked list of "a node that contains a cargo object and a reference to a linked list", does that mean the cargo object is referring to the list ? or that the node takes on this recursive structure and acts like a linked list? Are nodes and cargo the same thing, because "the string representation of a node is just the string representation of the cargo" and nodes contain cargo data? I find it interesting that the lists can be looked at by themselves and as a unique list with its own memory address, then they can also be intertwined with other lists to create a bigger list and structure. I also find it interesting that this linked list structure has similar properties of a tree structure. I tried the code on the reading for week 7, to make sure I get the grasp of it (while looking back at the reading to understand what i'm doing). I now realize that the point of None is to show where the list ends and that every Node needs None set for self.next, because of the case where it actually is the end of the list. For list collection, I don't understand how the computer would know what the first node refers to and why you only need to put it in as a parameter to print_list. Is it because it is linked via self.next, to the other nodes? Yet, it says that "there is no variables that refers to the other nodes. We have to use the next value from each node to get to the next node". How do you specifically use next value from each node and where do you use it in the function? For the function "print_list" and "print_backward" I don't understand why they say they can't have a method? I don't understand how you can't use None in a method? What's the real difference then between a function and a method? I learned that you can use wrappers and helpers to divide up operations of what you want a method to do.

Thursday 27 February 2014

Recursion slog

Recursion can seem strange or confusing at first, but once it is understood, it can be quite useful. Recursion is essentially a repetition within a function where the function calls itself. This is generally used to break up the process of solving a problem into easier steps or for clarity purposes. It is used when the problem has a sub-problem which repeats the format of the problem in one way or another. Instead of typing up the same code again to solve this sub-problem, the function would be called within itself so that this sub-problem is treated as if it were the main problem. A good way to understand this process is tracing. Some examples of problems with similar formatted sub-problems are loops, nested lists, and Trees. Also, the Tower of Hanoi problem is  a good example. The pattern here is that these examples have repetitions within themselves, similar to recursion, which is why recursion is so useful. To add to this, since recursion has the ability to  infinitely repeat itself, an important piece to stopping this is a base case, where the function and or recursion continues until the base case is met.

Tuesday 4 February 2014

week 4




  •  I learned that you can use recursion to solve smaller problems, and that a function can call itself. 
  • Does this mean the function defines itself before you finish writing the code?
  • I thought that fractal were interesting, with the ability to draw something. I thought it was interesting that a fractal was like recursion in the fact that it can call itself, to be defined and can  have image(s) on both sides, that are similar to itself. I find it interesting that it almost is a visual of recursion along with this theme of repetition.
  • The part about drawing koch fractal starting at order 3, using smaller orders confused me because of the multiple lines each order produces with the addition of placing those smaller orders in one large picture. I had to re-read this part and go through it looking at the image then the "instruction", and almost imagine the construction of the drawing in my head. I started to understand this better also when I traced it.
  • Recursion and fibonaccis sequence reminds me of when I learned it in high school calculus as well as induction, which I learned in university math.
  • the part on recursive directories and files confused me, I will re-read this again through the week to gain a better understanding
  • the pygame part was hard to understand, but was interesting in terms of the real world application for creating a visual object or playing around with it, which was fun 
  • I'm going to try the exercises because I understand most of the things that were said on recursion, but the questions including drawing a shape looks like they would better enhance my understanding of fractal and the exercises in general look like they would allow me to better grasp these topics
  • I learned that recursive definitions are useful for expressing complex data structures
  • I found it interesting and potentially helpful when learning this new way or organizing what test cases to use although I think I have a general understanding for test cases, from csc108
  • I want to review the unit test part to make sure I properly have an understanding of it
  • I learned that you need base case in recursion (function), so it can tell the computer and or code when to stop