It has been a while and we will be combining all of what we've learnt so far, we will be talking about the different contents learnt throughout the weeks as well as listing all ADTs (Abstract Data Types) we've used along with a final impression of the course.
Week 6-7
Week 6 has been my introduction to trees, although I did not entirely comprehend the concept of a tree due the limited time after the test we had, with time I have finally been able to grasp the idea behind it.
A tree is an abstract data type that has two important parts: the root and the branches. It would be rather referred to as "value" and "children" in this case. Let us explain what each of these are in the case of the regular Tree class.
Each instance of a tree is called a node, a node is the entity that has both value and children.
The "value" is the data contained within the node, it can be any type of data.
Children, in the case of the regular tree refers to a list containing all sub-nodes or sub-trees attached to the said tree.
Creating a tree is really easy in Python.
Suppose the Tree class had already been imported from the tree module in the following way:
>>> from tree import Tree
>>> sometree = Tree()
In that case we would have created a blank tree, is has no node data and no children.
We could use of the methods available in the Tree class but for now we will modify it using regular python commands or known methods.
(If nothing is bound, the default values for both are None for sometree.value and [] (the empty list for sometree.children)
>>> sometree.value = 6
The node's content become the int 6.
>>> sometree.children.append(Tree(7, Tree(3)))
>>> sometree.children.append(Tree(1))
With this, we've added two children to the tree, a tree with node value (int 1) and no children, and another tree with a node value of 7 and a tree having three as a node and no children as a child.
We could even add a third children, fourth, fifth and so on... the list can be expanded to the user's liking, so long as it stores data in a way that is as efficient as possible.
We could have also used some of the methods to count the number of nodes (4 in this case), the branching factor (2 branches), the listing of all nodes, among others.
Most of these methods require the use of recursion, which we will talk about next week.
Week 7-8-9
We've been introduced to trees themselves, while it is easy to create one, using one is a completely different story. During these few weeks we will learn about recursion, call tracing and binary trees.
First, let us talk about recursion. It's a very simple principle that involves calling a function within itself. As our goal in computer science is to solve problems, recursion is generally the solution when it comes to functions or methods requiring recursive calls.
Suppose we were to do such on a function that allows to calculate the factorial of a given n number:
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)
Note how we call factorial within itself. In order to comprehend the work of this, we can do a function call tracing, meaning we will be tracing each and every of the steps taking place here.
>>> factorial(4)
Let us work through the steps of it.
We know 4 isn't 1, so we return 4 * factorial(3) (4-1=3)
We do not have a complete answer since python still has to call factorial(3). Let us a complete tracing.
>>> factorial(4)
24
Tracing:
return 4 * factorial(3) # 4 not equal to 1, thus the result
return 4 * 3 * factorial(2) # 3 not equal to 1, thus the result
return 4 * 3 * 2 * factorial (1) # 2 not equal to 1, thus the result
return 4 * 3 * 2 * 1 # 1 equal to 1, thus 1 is returned at the very end
return 24
Recursive calls at the return statement allow us to treat some data that needs to pass through the same function over and over again with ease and that, thanks to the conditions (if, else statements).
Recursive calls can also be used in methods within classes, we will address this when we talk about traversal orders.
But for now, let us mention binary trees.
Binary Trees are Trees (an ADT with inherited attributes) that have one particularly. Aside from having their nodes containing data, they may have no child, one child or two children.
Though, aside from number of children, what differs between this type of tree and the binary tree?
Binary trees can be used for efficient binary searching, which means a left one's content is always less than a right one. This allows for easy traversal, we will mention this in the next portion.
Week 10-11-12
A final abstract data type was introduced to us in the final weeks, link lists and two topics were boarded: traversal order, efficiency. We will first talk about link lists.
Unlike trees, link lists do not really have any branches when it comes to storing data, it is just one branch, a continuous line.
What link lists have data in their value but that they point to the next node which itself may have a value and a linked node.
We've also learned here that the order in which instructions are inputed when making changes to the link lists is important, as storing the current node before replacing the next one is different than doing the operation the other way around.
Recursion is also used with link lists, in here we learned about traversal order for binary trees. We have four types: inorder (from left to right up to down), postorder (from the bottom nodes to the upper nodes, starting from end nodes), preorder, levelorder.
Efficency refers to how efficient the program is, in other words, giving us a result with a minial amount of memory and time used on the computer's side. For that, we not only take into the consideration the amount of steps a certain algorithm goes through, but also do as estimate how to the minimal and maximal amount of steps an algorithm can perform with the use of Big Oh and Big Omega (See CSC165 Slog.)
ADTs and final thoughts
Stacks, Trees, Binary Trees, Link List are all the abstract data types.
So far, this course has been enlightening when it comes to solving problems in programming as simple algorithms can only go so far.
The amount of abstract data type we were taught about also opened a lot of possibilities when it comes to storing, treating and searching data types. It also taught me or rather further reinforced my skills on making algorithms simplier and less memory consuming and the basics of creating a full program (game, arrangement software.)
As for this SLOG, I can't really say if it affected my style of writing notes, information down as I always do things the same way. Vaguely talk about subjects and interpret information so that common folk and computer scientists alike understand.
Badis' CSC148 SLOG
My SLOG for CSC148, just read the content, won't spoil anything about it but the fact it's about a Computer Science Course at U of T.
Friday, April 17, 2015
Tuesday, February 24, 2015
Week 1 to Week 6
Although I'm supposed to write one post per week, I prefer waiting for content to accumulate to be able to have quite the pack of content to explain and talk about. I just enjoy it that way.
Week 1
Quite the soft week as we were introduced to Computer Science in general and how different it was from just computer programming (CSC108) and the whole concept of solving problems using our acquired programming knowledge.
A few things that were discovered or clarified over the course of this week:
------------------------------
The work of objects and memory addresses. Objects being equivalent does not mean they are the same object. For instance. Assume two lists for the following scenario:
>>> L1 = [1, 2, 3]
>>> L2 = [1, 2, 3]
We declared two identical lists, however, if we were to use some Boolean operators, we'll find out how these two lists are different.
>>> L1 == L2
True
What we did in there was to check whether both lists are equal or rather "equivalent" as in, they have the same content.
>>> L1 is L2
False
The two objects may be equivalent and have the same content, but they are not the same object! Their memory address is not the same, thus False being returned.
Applying this in a context, we can compare the lists to boxes have objects in. The boxes are of same size and have the same content, they are equivalent, but the boxes are not the same one box. They are two different boxes having the same content in them.
Week 2
This week was a deeper introduction to ADTs, abstract data types are objects we create and modify and mold to our needs to solve certain problems.
One ADT we've learned about this week is the Stack. A stack is basically a list of objects where the only directly accessible item is the item on the top, thus the notion of stack. We add an element to the stack (on top of it) or remove the top element in question. The stack itself is created through the use of class implementation and the adding and popping the/to the stack is made through method within the function.
It is also good to implement other method for classes or ADTs that are the following:
__eq__: Method that allows the use of the == Boolean operator.
__str__: Method that allows a string representation of the object.
__repr__: Method that allows a representation of the object when called.
This was pretty simple, although one tends to set aside crucial notions such as these, which may be fatal later on.
Week 3
This week introduced us how classes inherit from each other. We will be talking about parent classes, child classes or superclasses, subclasses.
When we create a certain ADT, we can create other ADTs that inherit attributes, methods and others!
For instance, suppose we create a class:
class SomeClass():
def __init__(self):
attribute1 == []
attribute2 == {}
def some_method():
...
Suppose we want to implement a subclass, using the first one as a template.
class SomeOtherClass(SomeClass):
def __init__(self):
SomeClass.__init__(self)
...
The subclass SomeOtherClass inherits of all the superclass' attributes as well as methods in that case and can have additional methods to make it more unique in functionality or fit a certain case of a problem.
Here comes two issue at this point, although using classes and subclasses can be useful, there are cases where you want to make sure certain class attributes or methods cannot be used or modified by the local interface or in some other classes, cannot be used with the superclass and requiring a subclass to function.
------
In order to prevent a certain method to be used with the superclass, we raise an exception error at the method in question and design the method as it should work in the subclasses.
def some_method():
raise ExceptionError("Needs a subclass.")
-----
When wanting to prevent methods from being modified, we had the __ before their name in the definition.
def __some_method():
...
Many of these have to be taken into consideration as we do not want the user to temper with the functionality of the ADTs.
Week 4
Recursion was introduced to us this week. To explain what is recursion, it is the act of recalling a certain function or method within itself for a specific looping condition. We mostly learned how to trace the call at each iteration to obtain the wanted result or obtain a result. The tracing part is extremely important and required quite the practice as failure on a single iteration might generate a false result.
Week 5
Test week! No real content taught in here, though the test was quite manageable, I could have done better if only I knew how to recall the inherited __init__ method, added doctstring, traced well one recursion and placed an attribute in the parent class instead of the child class.
Week 6
Although a very difficult week for me, we were introducted to trees. An abstract data type that takes an object followed by another tree or nothing on top of using them for recursion problems.
Week 1
Quite the soft week as we were introduced to Computer Science in general and how different it was from just computer programming (CSC108) and the whole concept of solving problems using our acquired programming knowledge.
A few things that were discovered or clarified over the course of this week:
------------------------------
The work of objects and memory addresses. Objects being equivalent does not mean they are the same object. For instance. Assume two lists for the following scenario:
>>> L1 = [1, 2, 3]
>>> L2 = [1, 2, 3]
We declared two identical lists, however, if we were to use some Boolean operators, we'll find out how these two lists are different.
>>> L1 == L2
True
What we did in there was to check whether both lists are equal or rather "equivalent" as in, they have the same content.
>>> L1 is L2
False
The two objects may be equivalent and have the same content, but they are not the same object! Their memory address is not the same, thus False being returned.
Applying this in a context, we can compare the lists to boxes have objects in. The boxes are of same size and have the same content, they are equivalent, but the boxes are not the same one box. They are two different boxes having the same content in them.
Week 2
This week was a deeper introduction to ADTs, abstract data types are objects we create and modify and mold to our needs to solve certain problems.
One ADT we've learned about this week is the Stack. A stack is basically a list of objects where the only directly accessible item is the item on the top, thus the notion of stack. We add an element to the stack (on top of it) or remove the top element in question. The stack itself is created through the use of class implementation and the adding and popping the/to the stack is made through method within the function.
It is also good to implement other method for classes or ADTs that are the following:
__eq__: Method that allows the use of the == Boolean operator.
__str__: Method that allows a string representation of the object.
__repr__: Method that allows a representation of the object when called.
This was pretty simple, although one tends to set aside crucial notions such as these, which may be fatal later on.
Week 3
This week introduced us how classes inherit from each other. We will be talking about parent classes, child classes or superclasses, subclasses.
When we create a certain ADT, we can create other ADTs that inherit attributes, methods and others!
For instance, suppose we create a class:
class SomeClass():
def __init__(self):
attribute1 == []
attribute2 == {}
def some_method():
...
Suppose we want to implement a subclass, using the first one as a template.
class SomeOtherClass(SomeClass):
def __init__(self):
SomeClass.__init__(self)
...
The subclass SomeOtherClass inherits of all the superclass' attributes as well as methods in that case and can have additional methods to make it more unique in functionality or fit a certain case of a problem.
Here comes two issue at this point, although using classes and subclasses can be useful, there are cases where you want to make sure certain class attributes or methods cannot be used or modified by the local interface or in some other classes, cannot be used with the superclass and requiring a subclass to function.
------
In order to prevent a certain method to be used with the superclass, we raise an exception error at the method in question and design the method as it should work in the subclasses.
def some_method():
raise ExceptionError("Needs a subclass.")
-----
When wanting to prevent methods from being modified, we had the __ before their name in the definition.
def __some_method():
...
Many of these have to be taken into consideration as we do not want the user to temper with the functionality of the ADTs.
Week 4
Recursion was introduced to us this week. To explain what is recursion, it is the act of recalling a certain function or method within itself for a specific looping condition. We mostly learned how to trace the call at each iteration to obtain the wanted result or obtain a result. The tracing part is extremely important and required quite the practice as failure on a single iteration might generate a false result.
Week 5
Test week! No real content taught in here, though the test was quite manageable, I could have done better if only I knew how to recall the inherited __init__ method, added doctstring, traced well one recursion and placed an attribute in the parent class instead of the child class.
Week 6
Although a very difficult week for me, we were introducted to trees. An abstract data type that takes an object followed by another tree or nothing on top of using them for recursion problems.
Thursday, January 22, 2015
Why do Geeks need to know how to write?
Now, I do not consider myself a geek, but before I point this out in the end of this pseudo-essay, pseudo-debate, or just to make it simple, blog post, let us start by answering the question that's on the title slot of his blog post. "Why do Geeks need know how to write?"
First, let us define three important "terms" or "words in that sentence.
As know, Geek is the coined term that designates person with a deep love and integration of and into the Geek Culture which mainly focuses around electronics, programing, software, science fiction, etc. We may often think of said people as dehumanized because of their close relationship with devices and machines and said science fiction, and because of that, we may also think that writing is not something they do at all or are good at. Truth be told, that is not the case, in fact, writing is a major necessity for them. In the next couple (?) of paragraphs, we will debate this.
So, Geeks need to know how to write, but why? Because verbal communication is not always available to people at certain times! This the kind of argument that applies to every human being, not just geeks, as technically speaking (physically that is), Geeks are still human beings, their style of life do not determine their species. But back to our point, verbal communication is not always available. So when it comes to communicating results, important messages, Geeks need to know how to write in a language that is understandable by people who are being talked (written) to.
If a Geek needs to know who to write to communicate with others, he also needs to know how to write to communicate with himself, just like the most of us. How so you ask me, well here's the answer to that. Keeping notes or track something can help us review material, fix or improve it. Now, Geeks, as they are human beings, tend to solve series of problems they need to keep notes (and track) of. Problem is however, if one is not to understand his own notes and language, how are things done?
This is about all I have to say. Though, I do not qualify myself as a geek. I may like programming and game-making and games, doesn't mean I'm too much into the culture.
First, let us define three important "terms" or "words in that sentence.
As know, Geek is the coined term that designates person with a deep love and integration of and into the Geek Culture which mainly focuses around electronics, programing, software, science fiction, etc. We may often think of said people as dehumanized because of their close relationship with devices and machines and said science fiction, and because of that, we may also think that writing is not something they do at all or are good at. Truth be told, that is not the case, in fact, writing is a major necessity for them. In the next couple (?) of paragraphs, we will debate this.
So, Geeks need to know how to write, but why? Because verbal communication is not always available to people at certain times! This the kind of argument that applies to every human being, not just geeks, as technically speaking (physically that is), Geeks are still human beings, their style of life do not determine their species. But back to our point, verbal communication is not always available. So when it comes to communicating results, important messages, Geeks need to know how to write in a language that is understandable by people who are being talked (written) to.
If a Geek needs to know who to write to communicate with others, he also needs to know how to write to communicate with himself, just like the most of us. How so you ask me, well here's the answer to that. Keeping notes or track something can help us review material, fix or improve it. Now, Geeks, as they are human beings, tend to solve series of problems they need to keep notes (and track) of. Problem is however, if one is not to understand his own notes and language, how are things done?
This is about all I have to say. Though, I do not qualify myself as a geek. I may like programming and game-making and games, doesn't mean I'm too much into the culture.
Subscribe to:
Posts (Atom)