Sunday, 5 April 2015

Final Week!

It's finally here! The end of classes for this semester! Time went by super fast and finals are so close now (next week, actually)! I'll start off my blog post with just talking about the last week of classes and then I'll look back at some of the things we've done in this course!

The last week of class wasn't too hectic. We didn't really learn too many new things except for big-oh notation which we've looked at a lot more in depth in CSC165 so it wasn't too hard.  The last class we looked at some examples with big-oh notation, and discussed some key concepts we've looked at in the course. This is pretty awesome since my first final is actually next week so if we learned anything too hard or intensive I wouldn't have that much time to prepare for finals.

We also got our tests back and I unfortunately made some mistakes on the last question. It was a question using linked lists and I wasn't too careful and forgot 1) to reduce the size of the linked list when I was finished, and 2) the case in which I was using the function at the front of the linked list. I forgot that I'd have to re assign the front of the linked list to the second node if that was the case. I really have to be a lot more careful with these things, but now that I know my mistake so hopefully I'll be more aware of this.

The last assignment was also due on Friday and it was a lot easier than the other assignments. My partners and I chose option B, which is to complete the body of the functions in the starter code the professors had given us. It was a lot faster than the first two assignments. Each function and method we had to implement was a lot shorter than the ones we did in assignment two, especially much shorter than the suggest_move for minimax. For assignment one it was probably faster because we had to design how we'd implement each method and attribute for the class designs.

Looking back on the course now, I would say, it wasn't so bad. It's a big thing to say since I'm not doing outstanding, but really, it wasn't so bad. I've gotten so used to dealing with these things that they just seem so much easier. It's similar to how I look back at everything in high school and think how I could have done better because it was so easy. Learning it was hard, especially figuring it out, but once you actually get it, you don't even know how you could have missed it. It's like with recursion, easily the hardest thing I found in this course. At first I didn't really get it, and what I was really doing at all, but once I started to practice and just think about those types of problems more I got the hang of it. Finding the base case and finding the connections between smaller instances to bigger instances just came so much faster as well.

I've really learnt a lot of different things from this course, including linkedlists, tree structures, and much more. I'm excited to continue on and learn so much more in computer science! Thanks to all the TAs, professors and friends who have made this one awesome semester!


Sunday, 29 March 2015

Revisiting old posts! Week 4 Recap visit!

Hey all! Second last blog post for this year! Time sure does go by super fast. For this week's blog post I'm going to be looking at a previous blog post I had written and write my reactions to it, things such as whether I agree with myself, or maybe perhaps something I may have done differently to approach the problem.

I decided to go with my blog post titled 'My Week 4 Recap, Including Tracing Recursion!'. The reason why was because I feel this is when we started to get into CSC148 material. It was the week when we started to actually look at recursion. Previously a lot of the things we've talked about were actually introduced in CSC108 such as object-oriented programming. We looked at it a little more in depth and our first assignment relied heavily on that but it wasn't anything we've never seen before. However in week 4, we were introduced to recursion. We mainly focused on tracing recursion for week 4, which is what the blog post was supposed to be about, but I talk a bit more about actually writing a recursive function that was at the end of our lab for that week.

Re-reading my blog post, I still mostly agree with myself. In the post I seemed to have talked about how tracing recursion is still pretty straightforward. I know exactly what it's supposed to do when I see the function, and the theory behind it makes sense. Especially since when you see the body of the functions the instructors have given you, you can easily read it. You just look at it step by step and you can see what the final output would be. Although, I did overestimate it because on the first test  I lost marks on the tracing recursion section. I got the final answer correctly but I over expanded when I was writing out the steps. The lab itself for that week wasn't too challenging to figure out the output but I'm pretty sure that overconfidence of knowing the final answer made me pretty sloppy with actually writing out the steps, hence me losing marks on my test. My initial feeling towards the last part of the lab (writing a recursive function) is a bit different. It still is something I'm not always 100% confident on,  but now with a lot more practice using recursion I can actually do that question a lot faster.

Reading a couple of my other classmates' blog posts on week 4 was also pretty interesting. A lot of us had some similar feelings towards tracing recursion initially in which it was pretty easy. The blog, http://slogsbysidra.blogspot.ca/, seemed to have the same thoughts that I did initially regarding tracing recursion in which it was straightforward, although unlike her who seemed to have done well on that quiz, I'm pretty sure that's the quiz I didn't exactly do well on. Another blog I have read was http://theslogofmarie.blogspot.ca/. Her reactions to the lab were also very similar to mine as well. The last question especially the last question for me. It really did help me get used to thinking in a certain way to write recursive functions much faster. http://mysuperslog148.blogspot.ca/ was another blog that I read since she seemed to be a lot more experienced than I, since she already had some exposure to recursion whereas I had none. Her reaction to it was interesting though because since I didn't really have much background in computer science, I had almost no initial reaction to it when I heard that we were learning about it. Although she found tracing recursion to be as simple as well and something I really wish I had done that she had mentioned in her blog post was not to over complicate things with recursion.

Writing this blog post was quite interesting! Especially to see how my reactions have changed over time. I did eventually get better at what I struggled with and also learnt to be too overconfident approaching a task. Reading other bloggers reactions was also interesting to see that their reactions to this was very similar to mine as well. It's been a lovely semester so far and last week is the final post! It's nice that I have this blog post so I can actually see what I thought about over the term and how I changed. Well, that's all for this week! Have an awesome last week of classes!

Sunday, 22 March 2015

Week 9 Recap!

Hey readers! This week we didn't actually learn that many new things because the test was on Wednesday! The test itself didn't have any question that was too particularly challenging although I was super tired from studying for this course, and the two tests I had the day after. I was so tired I was just sort of slow the entire morning during the test so I'm not exactly sure how I did. It may have made sense in my head but I may have missed some details similarly to how I didn't read a question properly on the first test and ended up skipping something in the question. Hopefully things go okay. The marking scheme in this course is something I'm pretty happy about because the better of my two tests will be weighted more.

Anyways, moving on to things I learnt! This week we only had Monday's class where we looked at mutating methods for a binary search tree, specifically insert and delete. The two methods weren't too hard to implement because we already looked at the binary search tree last week and I already know what the node value had to be relative to its left and right sub tree, which is that the node has to be greater than the values in the left sub tree and less than the values on the right sub tree. With tutorials and everything cancelled I wasn't exactly sure if I was doing the lab correctly so I had to work together with my assignment partner to get everything done! For insertion, the contains method in the lab seemed to check every single node in the tree which isn't really that efficient. We can just search part of the tree because it's in a pretty specific order. For the deletion method I was wondering if there was really anything important in keeping a balanced binary search tree and according to google, there are multiple applications of it such as for priority queues and sets.

That's all I have for this week! The end of the course is coming near and it's almost time for finals,which means its time to go into hardcore study mode! See you readers next week!

Sunday, 15 March 2015

Week 8 recap!

Hey readers! This week has definitely been a stressful one, especially with the second assignment due and everything. It definitely was a lot harder to do than the first assignment. The first assignment, although the design of it was a something big, once we actually knew what we were fully doing it was pretty easy writing out the functions, especially since we dealt with how to implement certain things already in CSC108. This assignment was using a lot of the new concepts that we learnt which includes using recursion for the minimax strategy. That one took a really long time to figure out for my group because we had a hard time understanding how to keep track of all the scores and how to match it up with a certain game state. Took my group awhile but we got it eventually by creating a helper function to actually do the recursion part and return  the scores associated with each move.

Anyways, moving on to things we learnt in week 8! Week 8 we were introduced to the topic of linked lists. It's a linear sequence of nodes with a reference to the front or head. The back of the sequence is called the tail. The lab questions this week actually took me less time than last weeks. I'm a pretty visual learner so drawing out the linear sequence was a bit easier for me than picturing a big tree structure. Drawing out the linked list made things a lot easier since I knew exactly what I had to keep track of, especially in the last couple of functions where I had to keep track of 2 nodes rather than one, such as in insert_before. Overall the new material wasn't too challenging for me so I'm pretty confident in it, which is pretty great, since the test is next week. I can just focus on doing some practice for it. 

Also from last week, I ended up looking at some past tests in preparation for next week's test and to be a bit more familiar with some binary tree structures, and this has definitely helped me. It does really pay off to actually sit down and write the code out by hand since I end up being a lot more careful about what I write rather than just typing it up casually on Wing and making silly mistakes all the time. 

Anyways guys, that's all for this week's blog post! See you next week!

Sunday, 8 March 2015

Summary of Week 7!

Hello blog readers! For week 7 we were introduced to binary trees in class! Binary trees are pretty much the tree structure we've looked at earlier in week 6 but specifically with only two children, which we usually refer to as the left and right sub tree. I learnt about the 3 different ways that you can traverse through binary trees as well. They are in-order (visiting a node between its children), post-order (visiting a node after its children) and pre-order traversal (visiting a node before its children). I also learnt about binary search trees in which at a specific node, the value for it is greater than all values in the left sub tree and less than all the values in the right sub tree.

The material was pretty easy to understand at first but implementing it definitely wasn't easy. When I first started looking at the lab questions, I kept thinking about how hard it would be because of how many limitations there were on certain things, such as the two branches for binary trees in the first couple of questions and the value restrictions for binary search trees later on. When I actually started to think about it more the conditions don't actually make it that much more complicated. The binary trees only have the two branches and I check the left and the right sub tree, and the binary search trees for the later on functions such as list_between actually can be easier because now instead of checking the entire tree for values between certain values, you can know because the left sub tree and right sub tree will have values less then and greater than its parent. However, I'm still not entirely confident on being able to write these concepts on a test, mainly because it took me a bit of time to figure this out, and on a test with really limited time, I'm not too sure I'd be able to think of a way to solve problems with this that fast. I'll look at some past tests for sure with some binary trees so I can have a bit more practice with this, and hopefully with more exposure I'll be a bit more confident in the material.

Well, that's all for this week folks! I'll see you guys next week in my next post!


Sunday, 1 March 2015

My summary of Recursion!

For this week's blog post I'll be talking about recursion. During the past couple of weeks we've been learning about recursion and discussing different ways on how to implement it. We've learnt how to trace recursive functions, write some basic functions that use recursion, as well as use it within tree structures. I'll first be talking about what recursion is, some examples of ways we've used it within this course, and my experience dealing with it in the course.

In computer science, recursion is a way of thinking in which you break up a larger problem into smaller instances of itself. You will have 1) a base case, something you can easily solve without recursion and 2) a set of rules which reduce all other possible cases towards the base case, which is the recursive portion of the code.

An example would be:

def get_max(l):
    """(int or arbitrarily nested list of int) -> int
   
    Return the maximum element within l.

    >>>get_max(1)
    1
    >>>get_max([1,[2,3]])
    3
    """
    if isinstance(l, list):
        return  max([get_max(x) for x in l])
    else:
        return l

For the first example in the doctest, we see that it is only an integer, so it goes to the else condition and returns its value immediately. This is the base case that doesn't require recursion. For the second example, we see that it is actually a nested list and so therefore it would use the recursion part of the code. It would generate a list in which it would call get_max on each element within the list and then eventually get the maximum value of all of those integers.

-> max([1, get_max([2,3])])
->max([1,3])
->3

In this course, one example of a structure that we've used in this course using recursion is the tree! A tree is essentially a set of nodes can be connected with each other by edges, which connects the parent and child node. An important node is the node at the top of a tree which is called the root. You can access the nodes at the very bottom by recursively calling the children of each node and then calling the children of that node and so on until you get to the very bottom, as each child will have the exact same structure as its parent.

During this course I found recursion to be bit challenging to grasp at first. When we traced the code I was able to understand it as well, but when it actually got to writing the code, I struggled. I didn't really know what I was really doing by constantly calling the function over and over and it often resulted in an infinite loop. When I actually started to think about what I was actually doing by calling it (which is to eventually get smaller and smaller to a particular base case), it started to make a lot more sense.

So that's my post for this week! Hopefully you readers can take something away from my summary on recursion!

Sunday, 15 February 2015

Summary of Object-Oriented Programming Concepts!

For this weeks post I'll be summarizing object-oriented concepts! In CSC148 we've been using python and it's a very object-oriented language. The course has definitely been helping me understand it a lot more because we've been using it so much in all of our lectures, labs, assignments and tests. I'll first be introducing objects and classes. I'll talk about some important terms related to them, talk about the public interface and then I'll move onto some inheritance.

Object oriented programming is essentially based around objects. An object bundles together data  as well as the methods that can be applied to it. They're stored at a location in memory. In order to actually create an object, we will need a class, which is considered a blueprint for making objects. Each class has attributes (data associated with the class) and methods (or operations). To create an instance (a specific realization of any object) of a class, I have to instantiate it by using the special method __init__ in python. There are many other special methods in python (certain methods available when you use a particular syntax), although in this course we've specifically looked at __init__, __repr__, __eq__, and __str__. We can also override these and define them ourselves if we'd like. In class methods, you always have the parameter self, and this self refers to that specific instance upon which you are calling to use those methods on.

Now that we know what those terms mean, we can now talk about the public interface, which is essentially the features of the class that other code may use. Specifically in python, there's no notion of attributes being private and so it's possible for them to be changed outside of the classes in the client code (the code that runs the classes), which is something we don't want. Something we've learnt in lectures is to use the property mechanism to avoid this by using a specific method to set the value and another to get the value.

Now lets talk about  inheritance. Perhaps we want to create more specific class that has some features of the another class. It would be a bit redundant to retype the entire class again and this can also allow for more room for errors. Instead of doing this, we can create a sub class of the parent class in which the subclass inherits all the methods and attributes that we've assigned for the parent class. It can be thought of as a hierarchy system, with the parent class being a lot more abstract and the sub classes being more specific. For certain attributes you can extend upon them in the sub class and for certain methods you can extend or completely override it if you can't find a way to reuse the code from the parent class.

So here is my short summary of object-oriented concepts. We used it heavily in our first assignment especially when we had to design a program using different classes to handle different games and strategies. I got really good practice because of it by trying to figure out specifically what methods and attributes we had to have and how to organize the program from a more abstract level in the parent class to a more specific one in the sub class. I find it's a pretty neat way of organizing information and very useful as well. Hopefully from my summary you readers can get a good general idea of these concepts as well!