Thursday, 31 March 2016

This is a blog about arity of trees. Arity is the number of maximum children a node can have. It applies to trees. A binary tree have arity of 2 because it only have left and right tree. Trees can have a number of arity.

We learned that I can use a recursive method to find arity. The base case is i have no children which means that I return an arity of 0 and the induction case is that I call the function on every children of the node and append the number of children of this node. Then I call the max function on it. Eventually we will have the arity of the whole tree.

This is a blog about trees. Trees are data structures with nodes and they have children. They store a value and they we can visit their children through the nodes. This is good for storing multiple level of memory. In labs I just learned how to visit every node of the tree and I used recursion. The idea is simply calling on every children of the node and stops when the node say we don't have children anymore.

Using recursion in tree is awesome because we can visit every value and go to the every node unless the function reached a node with no children. This is good in a lot of ways. We can search every part of the tree and know how many node meet the requirement of our condition.


Slog to submit
                                                             

This week  I am thinking on binary trees. Binary tree is a structure consisting of a a parent node and have a left and right children. So we have two children in total. If the tree have no children, then the two children would be None and None. This structure can hold million of structure and it is good for both storing and searching. It is good for storing a value because it only have the address of the tree node where it is  being store and it is good because we don't have to do a lot of memory allocation because we are only adding the memory addresses. It is good for searching because we have the values lesser than the node value on the left and the values bigger than the node value on the right.

Binary tree is good for running time. For example a height of h can store nodes up to 2^h-1 nodes. Think about that and we only have to do h operation in general in order to get to the node we want that is really fast. This means our computer runs more efficiently if we use binary trees.

The recursion method is really important for accessing binary tree. So this is how it work. Our base cases would be if we reach a leaf or None. We call a node a leaf when we see that this node has no children. The condition that left and right children are none are applied. If the node is None we stop recursion. The inductive case applies when we have left or right children is not None so this means the node is not a leaf. We use recursion by calling the method on left and right child. Those will eventually will reach a leaf or None and we done recursion. That's how the topic of recursion works on the tree. The code would be like:

def findheight(Tree):
      if Tree is None:
               return 0
      elif Tree.left is None and Tree,right is None:
               return 1
      else:
               return max(list(findheight(Tree.left), findheight(Tree.right)))

That's how it is done in an example and we can see it works well.

A Tree in general is actually a node with value and a bunch of children. Binary tree only have 2 children and binary tree is much efficient for searching and adding values. Tree would have empty list if it doesn't have children unlike binary tree we have None to indicate that it have 1 or 0 children

Thursday, 3 March 2016

This week I am thinking about recursion. I have encountered functions such as max, any, all, sum. Recursion consist of a base case and a continuous case. If I reach the end of the base case I stop and recursion keep calling itself if I have the continuous case.

I learned that If I need to keep calling my function to count the sum or count I need to use sum. I return 0 if I hit None and return 1 if I have an element. Then I use the sum function to sum them up. Any function tells if there's a true. It is useful when I want to see if I have a even number in my nested list and all function is useful when I want to see if all the list is even.

Thursday, 25 February 2016

new blog

This is a new blog concerning recursion. We started learning recursion this week. Recursion is a type of function that keep calling itself. So you have to see how the thing is done only if you trace it. It is hard to follow thing in recursion because you have a lot of calling on itself. It is good for finding the depth of a nested list. It is easy because I simply don't know the depth and recursion does it for me.

Recursion is good in finding parameter such as depth that you don't know but it can blow up the memory in your computer called over flow so I don't like it in that way

4th blog

This is a late blog for last week. I had been thinking really hard on LinkedList. Linked list consist of 2 parameters value and next. value is stored in this node and next refer to the next node. It was unclear for me that how does assigning node to next made them connected and later on I realized that I was assigning memory address to the next. The memory address made the whole thing smooth. I also did a=b on them and discovered that the what I changed on a changed b.

What I learned is that a=b assign the memory of a to b and that's how the thing works. By understanding memory made the whole thing make much more sense. so I need to get a copy of b to a.

Thursday, 4 February 2016

Second blog

This week I am very interested in LinkedList. It is said that they are efficient in memory allocation and every node contains a value and next item. The next item points to the next node and the value is stored inside this node. The node is connected to a chain of nodes in a very simple way and it is just like a list but save spaces for memory.

I lecture we learned that for a linked list, it can contain front, back and size. The front points to front of the node and back points to back.The variable size is used to keep track of size of the node. When adding nodes to the back first I need to set the next of the back to the item that we are adding and point back to the new item. It is very interesting.