Impressions of week 8
Due to being really sick I missed a few classes which was very unfortunate since the second term test is on the 11th. Week 8 assignment 2 was due on the 5th. In lab 7 we covered linked lists. A linked list is either the empty list (None) or a node that contains a value and a reference to a linked list. We worked on iterative techniques and mutation to implement some functions and methods for a LinkedList class. Honestly I hate writing slogs, I don't know what to write about and I'll probably given a bad mark so I'll just write whatever for the rest. I've missed class I don't know what's happening, I just want school to be over I don't care if that's not the spirit welcome to my slog. I don't fully understand how to do stuff with linked lists but I understand what they are. So before the exam I'll actually put effort in this I just have bigger projects to be working on right now so I haven't been able to put all my effort in this class.
Tuesday, 17 March 2015
Friday, 6 March 2015
Week 8
Week 7 we finished up with trees and worked on nodes.
A Tree is a class that is allowed unlimited numbers of children per node. However, we sometimes impose a limit. A binary tree has only a left and right child. Binary trees are important because was have something similar in our Assignment 2 which was due Thursday of week 8. My group had quite a bit of difficulty, especially with minimax which worked similarly to binary trees with its 2 children. My last tutorial was in week 7 due to the CUBE strike. In that tutorial we worked with nodes. My friend and I successfully finished most of the code although I can't remember whether or not we finished the last function for the lab. Anyways, nodes and trees was what we covered. I can see how they are really useful and good to know. I'd say my knowledge in them is average. This has been my first time learning about nodes and trees so what I learned in class is all I know about nodes and trees. Also practice in tutorials and in A2 have helped with my understanding of the object types.
A Tree is a class that is allowed unlimited numbers of children per node. However, we sometimes impose a limit. A binary tree has only a left and right child. Binary trees are important because was have something similar in our Assignment 2 which was due Thursday of week 8. My group had quite a bit of difficulty, especially with minimax which worked similarly to binary trees with its 2 children. My last tutorial was in week 7 due to the CUBE strike. In that tutorial we worked with nodes. My friend and I successfully finished most of the code although I can't remember whether or not we finished the last function for the lab. Anyways, nodes and trees was what we covered. I can see how they are really useful and good to know. I'd say my knowledge in them is average. This has been my first time learning about nodes and trees so what I learned in class is all I know about nodes and trees. Also practice in tutorials and in A2 have helped with my understanding of the object types.
Sunday, 1 March 2015
Week 7
What Is Recursion
Recursion is the process of defining a problem (or the solution) in terms of (a simpler version of) itself. A function is recursive if it calls itself. Anything solved with recursion can be solved withiteration (looping) instead. However, it is not always as practical nor efficient. Unlike an iterative solution that is long, complex and inelegant, a recursive solution is concise and elegant.
- if you're home, stop moving
- if not, take a step toward home
- find your way home
Parts of Recursion
All recursive algorithms have the following:
- base case (i.e., when to stop)
- work toward base case
- recursive call (i.e., call ourselves)
To work toward the base case we make the problem simpler. The recursive call, is where we use the same algorithm to solve a simpler version of the problem. The base case is the solution to the "simplest" possible problem (e.g. the base case to adding a list of numbers would be if the list had only one number.Thus the answer is the number).
Why Recursion Works
In a recursive algorithm, the computer retains every previous state of the problem. This information is held by the computer on the "activation stack". Every function has its own workspace per call of the function.Reflection and Personal Thoughts
To me, the easiest part of recursion is tracing a recursive function that's already been written. In most cases, writing a base case is quite easy because you just have to think of the simplest case or when you want the algorithm to end. The trickiest part for me has been writing the actually recursive call. You know what the call will eventually return since you have the base case(s). Still, I believe I should practice more recursion exercises.Example of Recursion
Sum of numbers in a list:
def sum_list(L):
if not isinstance(L,list):
return L
else:
return sum([sum_list(x) for x in L])
Subscribe to:
Posts (Atom)