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.
CSC148H1 SLOG
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])
Thursday, 12 February 2015
Week 6
Summary of my Object-Oriented Programming concepts
Some of the concepts we covered in Object-Oriented Programming include classes, instances, methods, inheritance, recursion, etc...
An object in programming is a unique instance of a data structure that's defined by its class. It comprises both data members (class variables or instance variables that holds data associated with a class and its objects) and methods. A Class is a concrete ADT (abstract data type) and a user-defined model for an object that defines a set of attributes that characterize any object of the class. The attributes are data members as well as methods, accessed via dot notation. A class variable is a variable that is shared by all instances of a class and are defined within a class but outside any of the class's methods. An instance variable a variable that is defined inside a method and belongs only to the current instance of a class. In general, an instance is an individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle. Class inheritance is when you create a class by deriving it from a preexisting class by listing the parent class in parentheses after the new class name instead of starting from scratch. The child class inherits the attributes of its parent class, and you can use those attributes as if they were defined in the child class. A child class can also override data members and methods from the parent. An object's attributes may or may not be visible outside the class definition. For these cases, you can name attributes with a double underscore prefix, and those attributes will not be directly visible to outsiders. Another kind of
Some Important Methods:
- __init__ ( self [,args...] ) Constructor (with any optional arguments)
- __del__( self ) Destructor, deletes an object
- __repr__( self ) Evaluatable string representation
- __str__( self ) Printable string representation
Some Important Functions:
- issubclass(sub, sup) boolean function returns true if the given subclass sub is indeed a subclass of the superclass sup
- isinstance(obj, Class) boolean function returns true if obj is an instance of class Class or is an instance of a subclass of Class
Saturday, 7 February 2015
Week 5
This week we had our first midterm on the 4th. I think it went well. We only had one class and we covered implementation of some of the test cases in unittest and implementation of the bracket balancer. This week I'm supposed to write about my impressions of tracing recursion from week 4. I felt like tracing functions that are recursive not too hard. It's simply a matter of rewriting the function again whenever it's called. Writing a recursive function though is much harder. In our tutorial we had to write some recursive functions even though the focus was on stacks and queues. Queues, unlike stacks, are more like a lineup for coffee then a stack of papers. The first one in is the first one out unlike stack where the last one in is the first one out. Also methods for stack such as pop and push have different names for queues even though they pretty much do the same things except for with a queue. Enqueue puts an item at the front of the queue and dequeue returns and removes the last thing in the line. In our lab, one of our tasks was to create a function (one for stack and one for queue) that takes an input and adds it to the stack or queue and when 'end' is inputted, it removes and returns each element in the stack/queue. My partner and I were both successful. To wrap it up, recursion is fun to trace but not so much to do (unless you have a smart partner who knows what's up).
Thursday, 29 January 2015
Week 4
This week we focused on recursion. A function is recursive if it calls itself. Recursion is an essential tool for computer scientists because it is necessary for some problems and is provides a solution that is concise and elegant compared to iterative solutions which may be long, complex and inelegant. We also practiced tracing recursive code. To better understand recursion and how it works, it's useful to trace the function with examples of a call with the smallest possible input, with the next largest possible input and then continuing to problems of any larger size for more confidence.
Also this week, on the 29th of January, our first assignment was due. I worked on it with Tal and Adam. We had some issues figuring out how to use __repr__ and __str__ in our function. I asked in my tutorial and I received a good answer that's cleared up my understanding. __repr__ are similar in many ways which make it quite confusing. They both return strings but __repr__ returns what you chose to return as the representation and __str__ returns a string that normally gives a kind of "english" summary of what's going on.
Also this week, on the 29th of January, our first assignment was due. I worked on it with Tal and Adam. We had some issues figuring out how to use __repr__ and __str__ in our function. I asked in my tutorial and I received a good answer that's cleared up my understanding. __repr__ are similar in many ways which make it quite confusing. They both return strings but __repr__ returns what you chose to return as the representation and __str__ returns a string that normally gives a kind of "english" summary of what's going on.
Friday, 23 January 2015
Why Geeks Should Write
The Three Virtues according to Larry Wall ( who the original author of Perl programming language,) are laziness, impatience and hubris. In order to fulfill these virtues we must be efficient, and what better way to be efficient than to make sure we don't make the same mistakes. One way to do so is to keep a debugging journal. A debugging journal is just a way of recording the process you used to fix a bug you encountered. By doing so, you can be sure that the next time you come across that bug you will know how till deal with it. Also, by documenting the bug and how you fixed it will allow you to have a better understanding. Another way to be efficient and a great programmer is being good at communicating ideas. Clear comments, technical specs, etc.. allow other programmers to better understand your code. That also means that other programmers can us and work with your code instead of rewriting it. So for a group project, that is very important. Also for yourself, it makes it easier to go back or find what you need within your code. So I definitely think geeks should write.
Subscribe to:
Posts (Atom)