Friday, 27 February 2015

Abstract Data Types

Abstract Data Types
    Up until this point we've dealt with a number of abstract data types such as stacks, queues, trees and binary trees. The stack is simple enough to follow. You add some number of elements to the stack. Then when you remove them, the first one to be removed is the last one to have been added to the stack. Or essentially last in, first out. As with queues, they run on a first in first out basis. The first element to be added to the queue is the first one to be removed. Comparing the stack with the queue, my thought is that each abstract data type is situational. That is, dependent on the circumstance, one may be more beneficial to use than the other. The tree as I understand is to be thought of as more or less a representation of an upside down tree. Such that each place where a new branch branches off is considered a node. Furthermore, a binary tree is a specific type of tree where each parent node can have up to and including two children nodes. The nodes in a tree then can be their own data type. Again, each data type is better suited to different circumstances. Traversing the trees brings us a whole bunch of options. We have traversals such as preorder, inorder, and postorder. Essentially, how preorder works is it displays the root node's data, traverses the left subtree recursively while displaying the current node's data, and then traverses the right subtree similarly displaying the current node's data. Inorder and postorder are simply just variations of the steps in preorder. In inorder, it traverses the left, displays the data of the root, and then traverses the right. For postorder, it traverses the left, then it traverses the right, and finally it displays the root's data. In the end, these concepts aren't too difficult to understand. 


No comments:

Post a Comment