Issuu on Google+

ABSTRACT DATA TYPES | ADT Think of an abstract data type as a concept for modeling a certain mathematical definition. This includes the data objects that make up the data type as well as the functions that can be performed on these objects. ADTs are useful for showing how a certain structure may be more acclimated to solving a particular problem. For example, you probably wouldn’t’ want to have an ADT that only allows access of objects from one end when you need to frequently access the middle items. This type of thinking helps us choose an appropriate data structure for the operations required. Some of the concepts on the right may even sound familiar to you.

STACK QUEUE TREE MAP GRAPH LIST


2

STACK Think of a pile of plates. What sort of operations are most comprehensive with this pile? Well, it’s simple enough to put a plate onto a pile, look at the top plate, or remove the top plate from the pile. Of course, we could also move the plates from one pile into another to access middle elements, but that is not the basis of a stack. A stack holds elements of a collection and allows addition of elements to the top, checking to see what the top item is, or removing the top item from the stack. This means that middle or bottom access is restricted. This ADT is a last-infirst-out (LIFO) data structure, meaning that the last item put on the stack is the first one that can be accessed when there is a removal or checking operation. The item that was pushed first remains in the stack for the longest compared with the other elements.

TOP


OPERATIONS TO ADD

REMOVED RETURNED

ORIGINAL

PUSH

RESULT

Add an element to the top of the stack

ORIGINAL

PEEK Return the top element of the stack

ORIGINAL

POP

Remove the top element of the stack

RESULT

3


4

QUEUE Imagine you arrive at the back of a line to get a burrito at Chipotle. As more people are served in order of arrival, you advance toward the counter to place your order. While you are in the line, other people are able to join into the line behind you and others leave the front of the line as they pay. This is the concept of a queue. A queue allows access to the item at the front of the queue and allows you to place an item to the rear. This is a first-in-firstout (FIFO) ADT as the item that was placed in the queue first is also the first item that can be accessed or removed.

REAR

FRONT


5

OPERATIONS ORIGINAL

ORIGINAL

TO ADD

RESULT

ENQUEUE Add an element to the rear of the queue

ORIGINAL

PEEK

RETURNED

Return the element at the front of the queue

RESULT

REMOVED

DEQUEUE

Remove an element from the front of the queue


6

TREE Finding a document saved on your computer or cloud is a simple process requiring simple navigation. You first look at the desktop, then the folder where you store multiple subfolders for different classes. Then you dig a little deeper by accessing one of the subfolders and in there, among many other files and more subfolders, you find the document you are looking for. This hierarchical relationship can be represented by a tree ADT. A tree has a root value and subtrees of children and can be represented by nodes. This is a recursive structure--the children of a tree are themselves trees. Trees are useful for storing hierarchical relationships, and sorted lists while common operations on trees are traversals, searches, deletion, and addition. Highly specfic trees that are more efficient for certain applications will be discussed later.

ROOT

LEAVES LEAF


7

ROOT

A B D

An element contining zero or more children

C

LEAF

Any element that has no children

SUBTREE

E

Any element and its descendants are subtrees of the entire structure

ANCESTOR DESCENDANT

Any element that is higher in the tree than a specific element along a common pathway

Any element that is below a specific element along a common pathway


test