Abstract Data Types are structures that can be useful across many problems. There are a few different examples of ADT's that we have learned about in class including Stacks / Queues, Trees, Binary Trees. Their main use is the storage of information.
Stacks:
A stack is an ADT that contains many different tupes of items. When adding new items to a stack, the new item is stacked, or pushed on top of the items already in the stack. On the contrary, to remove and item, the item is removed from the top, meaning that the last item added to the stack is the first one to be removed. "pop" is used to remove the item from the stack. Some important uses for the stack ADT are to track the function calls as a program is being run, and checking for balanced parentheses.
Queue:
Queue is closely related to stack ADT's meaning that is also deals with the storage of data, however the difference is in the order that new items are added and removed. A Queue is a "First in first out" data structure, meaning that the first item that was added to the queue will be the first one removed.
Trees:
A tree is a set of nodes(a node can have any value) with edges between these nodes. Nodes are divided into two categories, which are parent nodes and child nodes, each child node has a parent, except for the root, which is the beginning of the tree. Parent nodes that do not have any children are called leaves. Recursion is especially useful when dealing with trees because the root is able to deleagete various tasks such as finding height, depth, and others to its children, and from there it gets passed on to the children's children and so on until a leaf is reached, at which time the information gets passed back in the opposite direction to the parents until the root recieves all the information. Tree ADT's are mainly used to represent hierarchical relationships.
Binary Trees:
A binary tree is a subset of the normal tree in that each node can only have a maximum of two children.
Thursday, 26 February 2015
Friday, 13 February 2015
Week 6 SLOG
For the past two weeks we have been learning about Abstract Data Types, specifiaclly stacks and trees. Before doing the lab, we had only briefly touched upon stacks in class, therefore I had to reread the lecture notes a couple of times before I knew how to complete the lab questions. Next, for this week's lab was the topic: Trees. In the lecture, in order to fully understand trees, we created our own real life tree in which one student at the back of the class was the root with two children, and each of those children had their own two children, and so on until every student in the class was part of the tree. We then began to figure out the height of the tree, and other aspects based on our real life tree. I found this really helped my understanding of how trees actually looked, and how they delegated specific tasks to their children. At first, I was kind of confused as to how to complete the function bodies for the various functions in the lab, but after looking up some examples I got the hang of it, and I realized that trees are quite simply another form of recursion. Knowing this greatly helped me to proceed and complete the rest of the function bodies.
Wednesday, 4 February 2015
Week 5 SLOG
My impressions of tracing recursion:
To begin off our lecture on recursion, the istructor provided us with a problem involving a list within a list within a list... At first this preblem seemed completely bizarre and I had no idea where to even begin. We then began working on a problem in class, which essentially returned the the greaters number in the list. We first began by feeding the function something that was not a list (int) and observed what the function gave back, then moving to lists of depth 1, all the way to lists of depth 3. I found, as we went along, that while increasing the dephth of the list, we didn't really need to think about how to calculate anything new, but rather we just have to use exactly what we implemented before that. So in other words, recursion was just basically applying the same base computation multiple times in order to solve a more complex arrangement. Being a math major, I find that recursion in kind of like a puzzle in which you are always trying to see where to place elements of a list, and when a function needs to call itself. I really enjoyed learned about recursion (my favourite topic of the course so far), and I think it is very useful in that it make problems that originally seem very complicted, more simple by breaking them down into smaller steps.
To begin off our lecture on recursion, the istructor provided us with a problem involving a list within a list within a list... At first this preblem seemed completely bizarre and I had no idea where to even begin. We then began working on a problem in class, which essentially returned the the greaters number in the list. We first began by feeding the function something that was not a list (int) and observed what the function gave back, then moving to lists of depth 1, all the way to lists of depth 3. I found, as we went along, that while increasing the dephth of the list, we didn't really need to think about how to calculate anything new, but rather we just have to use exactly what we implemented before that. So in other words, recursion was just basically applying the same base computation multiple times in order to solve a more complex arrangement. Being a math major, I find that recursion in kind of like a puzzle in which you are always trying to see where to place elements of a list, and when a function needs to call itself. I really enjoyed learned about recursion (my favourite topic of the course so far), and I think it is very useful in that it make problems that originally seem very complicted, more simple by breaking them down into smaller steps.
Subscribe to:
Posts (Atom)