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.
No comments:
Post a Comment