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, 29 March 2015
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!
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!
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!
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!
Subscribe to:
Posts (Atom)