Sunday, 23 March 2014

Week 10

Week 10

Ten weeks class means five sixths of the course is over! I shouldn't think of this too much, as it will only distract me. (For example, I almost forgot to write this slog.) Now turning to the actual course, this week, various sorting algorithms were reviewed. Some, I already knew from CSC108 such as selection, bubble, and insertion sort. Others, such as quick and merge sort, were new to me. When these were explained in class, I felt that I could understand them fairly well. I found the card demonstrations to be helpful, as sometimes I am a visual learner. In addition to the method, the run times of these sorting algorithms were analyzed. Although I am less confident with run time analysis, once it was explained, I think I understand why merge and quick sort have the run times they have.

Outside of class, I worked on A2 part 2, and I started studying for the second test. I had finished most of A2 part 2 the week before, so this week was mainly for revision (and there were many revisions to be made!). In the end however, I believe I have a working program. To study for the next test, so far, I have been doing the old labs, starting with week six. When re-doing the labs, I find that they are much easier and straightforward. For example, to write a function that took my partner and I forever in the lab only took a fraction of the time at home. I also plan to look over in class examples and old tests. After doing the labs, I feel that I better understand linked lists and binary trees, but on piazza, it was also mentioned that big O would be on the test. This makes me nervous, as I do not feel that well about big O. I remember doing of run time analysis in CSC108, but it was only a little bit near the end. I hope to get more practice with this by doing the old test question on it (but I would also like the answers to check my work!). I should probably work on old examples to make sure I really understand them too.


The address of the first slog I randomly picked is http://codezerda.tumblr.com/. This person basically summarized binary search trees. I agree with what this person has to say, as it is mainly objective. In the “about me” section of the slog, the person mentions about being a computer science student and wanting a job coding video games (which could be cool in my opinion). I know I said this in a previous slog, but right now, I'm not CS student. I'm taking this class from family tradition. But as the semester comes to a close the time begins to chose a POSt. Among a few other things, I'm actually considering CS, but I need to think about it more before! Onto the next slog: http://bighairyleg.blogspot.ca/ (eww, big hairy leg). This person only has one post, that is, week 3 on object oriented programming. So, I can only comment on this post, but it will be fun looking back. This person (at least in week 3) didn't feel very confident on object oriented programming. I can relate, as in CSC108, when we did this at the end, I wasn't confident either. When I figured out this was the first topic of CSC148, I thought oh no! On top of a not so great feeling, I hadn't touched it at all during winter break. I too, was worried those first few weeks. But as we learned harder things like recursion, object oriented programming suddenly didn't seem so bad. A good example of this was A2 part 1. This was basically OOP: designing classes, using inheritance. Many people, including me, didn't think this was so bad. I don't know when OOP “clicked” for me, but it must have at some point, and I hope this person also feels the same way now.

Sunday, 16 March 2014

Week 9

Week 9

Another week completed means another slog to be written, so here it is. This week in class, more on binary search trees and running time analysis were covered. For binary search trees, we further looked into the methods that can be performed on them, the importance of ordering, and how ordering can be preserved. It was also mentioned that searching a BST was most efficient when the tree was balanced, so half of the values could be ignored upon every completion of a search round. This began the transition into run time analysis, where the next questioned posed was, given a well balanced BST, how would the run time be described. The answer, as it turns out, is logarithmic, (which is efficient). In addition, the big O notation was introduced, which is used to described run times. Apparently, big O was introduced in CSC165, but I am not taking that (I'm not a CS student), so this is new to me.

Outside the lecture, the main things I worked on were exercise 3 and assignment 2 part 2. I actually finished exercise 3 last week, but I had some careless mistakes that caused a failure in my auto test report. Also, I think there was a mistake in the auto test, where the test for sum to deepest had an invalid input. This was mentioned on piazza several times, but I think the person doing the auto test fixed that, as I did not get that error again. So, after fixing my errors, I worked on A2 part 2. Because I had midterms in other classes to study for, I did not start part 2 until Thursday. When I started working on it, I read that we only had to write four functions. Initially, I thought that if I write two functions a day, I could finish this by Friday (tomorrow). As it turns out however, even though there are only four functions, they were much more difficult than they seemed. Writing one function and getting it to work was very time consuming for me, so I realized that two functions per day was too much. I then decided to write one function per day. When working on the assignment, I found the piazza forum very helpful, as many of the questions I had were already answered there. I have now written three functions, and I plan to write the last one (the one that makes a tree from the regular expression), later today.

The first slog I chose to read comes from “The Angry Student” at http://angryprogram.blogspot.ca/. (What makes this student angry anyway?) I usually look at the most recent post, but this time, I decided to look at some of the earlier ones. In one entry, this person writes about Project Euler. I have not done any problems on this website, but I have heard about it. A few years ago, when I did not know anything about programming, one of my older siblings wanted me to do it in order to teach me programming. But, as I was lazy and not interested, that never worked out. Now, however, I do know a little and would like to see if I can solve these problems. Maybe one day, when I have more free time, I will try it. Anyway, moving on to the next slog: http://pythonisnotasnake.wordpress.com/ (I picked this based on the funny title). The first sentence in this was “Wow I need to post more often on this blog!”. When I read this, I checked to see how many entries this person had, and there were only three, so I guess that statement was right after all. Aside from that, the most recent entry had to do with recursion. Three laws (obtained from a web site) were mentioned. I agree with these, but in my opinion, the first two about the base case are saying almost the same thing and could be combine into one. Having three laws also reminds me of Newton and physics.

Sunday, 9 March 2014

Week 8

Week 8

Eight weeks into the class means two thirds of the course is finished! Since there is no assigned topic, I will write this in my usual format. This week, there were two main topics, linked lists and binary search trees. Linked lists were reviewed last week, but this week, they were implemented differently by using a wrapper and a helper. A wrapper and helper are essentially two parts of one function in that the helper does one part of the function, while the wrapper calls the helper and completes the function. As a result, only the wrapper is called directly, and the helper is called when the wrapper is implemented. Having learned this, I can see how it would be useful as it makes the program easier to follow. The other topic of the week was binary search trees. A binary tree is like the trees we have been reviewing, but what is special about these is that they only have two children per node. A string method was written in class, showing the use of wrapper and helper methods.

Outside of the lecture, I worked on the lab, assignment two part one, and exercise three. This lab dealt with linked lists like last week. After working through this lab, I feel much more secure about linked lists than I did last week. I felt that I was better able to understand what I was supposed to do and why I was supposed to do it. The second thing I worked on was A2 part 1. With this, I had several designs and could not decide which I thought was the best. So, after several changes and adjustments, I think I have something I think is okay (and I hope the grader thinks so too). Last, I worked on and finished exercise three early so I have many opportunities to get autograder feedback before the due date. I thought this exercise was harder than the first two, and I had to spend much more time thinking about how to solve the problem than I thought I would. I also had to draw some pictures, which is something that was not necessary for the first two exercises.

The first SLOG I picked to read is http://confabulatingastringofcontrivances148.blogspot.ca/. This log begins with the quote “In order to understand recursion, one must first understand recursion.” I thought this quote was humorous in that not only is the quote itself recursive, but it doesn't help someone who is trying to understand recursion that much. One thing this person wrote was “How can we write our function in a way to use a value, before we even know what the value is going to be?”. He/she was describing a source of confusion many people have when first learning recursion. I can relate to this, as I actually wrote about having the same thought in my own slog entry on recursion. The rest of the slog is a straightforward example on how to solve a recursive problem, (and has an interesting name). The second slog I picked is http://everyonelovesaslog.blogspot.ca/. This log mentioned the Fibonacci sequence, something I also mentioned in my recursion entry. The slog also mentions that in order to write a recursive function, one must know the base case. I think this is true, as when I write recursive functions, the first part I write is the base case. That way, once I know that my function does, I can build from that with the recursive calls.

Sunday, 2 March 2014

Week 7

Week 7: Recursion

There is an assigned topic for this week's slog: recursion! To begin, a simple definition of recursion would be a situation where, in a function body, the function itself is called. A function body, however, cannot contain only recursive calls as this would lead to an endless recursion loop. This problem is solved by having a base case, which is a piece of non recursive code that the function implements under certain conditions.

Over the past four weeks since recursion was introduced, the most common case I have seen in which recursion is used is nesting. For example, the first recursive function written in class was to find the sum of a nested list. Since then, we have written more functions for nested lists, and have been introduced to various other recursive structures. That includes trees, linked lists, and search lists from the lab, which are recursive because they may contain other instances of themselves nested within them. Another case where recursion is used, and this is where I was first introduced to the concept of recursion, is in a mathematical function, where the result is dependent on the previous result(s). For example, the week five reading mentioned the Fibonacci sequence, and the function M(n) used to find the minimum number of moves required for moving n number of cheeses from A1 use recursion. Last, an additional use of recursion could be drawing pretty fractal pictures.


When this topic was first mentioned, I thought it was strange that the function could call itself again without finishing its original call. But now I understand that in order to finish the original call, the function needs to call itself in order to solve the “sub-problem” and use that result in finishing the first call. The first time I wrote recursive function, I was overly concerned with my base case because I was worried about the endless loop, but as I got more practice, I was better able to write an effective solution with considerable confidence and with a better understanding of how the function is implemented. Also, I now see why this would be useful. For example, in the case of nesting, it is much more simple and efficient to write recursive code than to write non recursive code. That is because for a large degree of nesting, one would need to write a large number of repetitive code segments in order to deal with each degree of nesting while writing a recursive call only would take up one line. Reading that one line is also easier to understand than numerous lines of repetition. Overall, I find recursion to be an interesting topic.