October 26, 2013.
With the midterms over, the amount of work has calmed down in a sense. Though the complexity of the homework and exercises only seemed to grow more difficult. This week as we learned of the function helper call in class methods, it helped understand how different parts of the class parameters are called in different ways. If it is anything I had gained a clearer understanding of this week was that class parameters, when already defined, can take additional parameters if they contained recursive properties. For example:
__init__(self, left, right):
to
[inside a function method call]
self.left.node
self.right.right.left.node
This method also gave me a clear understanding of writing certain helper code to certain method calls. In the case of the exercise 5, I found it helpful to define a helper inside set_depth function which recursively accounted for counting all the nodes within a binary tree. That goes without saying that, for this exercise, I had the trouble of figuring out how to recursively assign variable statements if the variables were defined with different names. I realized the idea of this part of the exercise. Here is an example of what I mean.
if X:
return 1 + sum(self.item.set_depth(4))
vs.
if X:
return 1 + sum(self.item.left.left.set_depth(3)...)
If I were to say the most challenging of the exercises so far, it would be this one.
Another key idea I have came to learn this week was tuple unpacking. Understanding that tuple can be seperated by "," it gave me a clearer understanding (and a better method) of how assignment statements would work in a much simpler format.
As the coding of concept gets more complex, I hope to gain a better knowledge of how to properly translate my ideas of solving an algorithm to code.
Cheers!
Saturday, October 26, 2013
Sunday, October 13, 2013
Week Five
October 13, 2013
----------------------->
Topics: [Recursion and Trees]
When I saw the diagram of the trees in the slides as I walked into the lecture room, I was just itching for a smile. Doing a double major of Computer Science and Linguistics, I was well aware of the notion of the hierarchical tree and the concept of nodes and paths (or "branches" as we linguistics say), though in a more grammatical concept. While in CS I learned this week that there are the three different traversal types - pre-order, in-order, and post-order, the material was review in terms of being introduced to the tree structure. So when the directions of the trees were being shown on the slides I was able to follow them pretty easily. Left subtree, root, right; Left subtree, right, node, etc.
The only lingering questions which I thought was that how would recursion work in this way necessarily? For I was under the impression that recursion called inside functions were used in order to create a wanted value or outcome for an inner part of the given parameter. In terms of the given tree of numbered nodes, would the recursion be the repeated two's, in this case?
Other Notes:
This week I would say I came to better understood recursion through the labs that were required to write recursive functions. Recursive functions need a base case, and they generally need to pass an argument of a parameter that is not the full "object" itself. Otherwise, a maximum recursive depth error would occur.
ex. reverse_string(s: str).
......
return reverse_string(s)
vs.
for n in s:
return reverse_string(n) + ....
And another note is pertaining to the "one line" return statements. Punctuation of return statements are key - [] would return the code, whereas () would cause the code to generate a "generator object"
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line ?, in __main__.reverse_string
Failed example:
reverse_string('clock')
Expected:
'kcolc'
Got:
<generator object <genexpr> at 0x000000000310F870>
In terms of recursion concept, I think I have it fully grasped. All that is left is making sure I am able to properly put the concept into coding usage :3
Wednesday, October 9, 2013
SLOG Entry One
October 9 2013.
------------------------------>
Topic: [OOP]
Object-Oriented Programming, something which I was introduced to in the previous 108 course, is what I have come to know as a way to create object type classes. Inside each class are its methods, which would be the rules which the object were to follow.
Having been familiar with the basic information on OOP (such as string formatting, arbitrary "self" header), the first month helped me to further develop the intuition that just like functions, code explaining rules and outcomes are written inside the methods. And after completing parts of the first assignment, I have come to find that OOP is useful for computer scientists, because it helps them to create an object which will be later used for a program in the larger scale. By creating an object in form of a class, everything about the object (the shape it takes, rules, properties) are all stored into one convenient place.
Topic: [Recursion]
Another major topic discussed during the lectures is recursion, which is essentially the "reuse" of a particular order or call in order to help solve problems involving little to massive repetition. The first time this concept was introduced through code and in words, I had trouble understanding how exactly it was used. It was through a brief introduction of recursion through embedded sentences in linguistics, and later through the labs that it was understood that recursion could be used as many times as wanted, and modified to act differently but for the same purpose.
The reason why I think computer scientists find this concept useful is because for it allows them to accomplish what their intended function or program intends to do, and simply because the tasks can be accomplished in a much faster way. It saves their code from becoming too messy with all the repetitive code they would have have to write if they were to manually enter the repetitive bits.
For obviously even computer scientists would have a hard time reading another's code if they were to find millions lines of code for just one rule of the program.
----------------------------->
Student: g2flora
Subscribe to:
Posts (Atom)