Abstract Data Types Definitions, Implementations, and Uses
ADT An abstract data representation without reference to a specific implementation TABLE QUEUE STACK The primitive operations on the ADT elements store, retrieve, lookup Generically called getters and setters tostring provides a generic way to display the contents of a complex data element
Order TABLE ADT Unique key Data needed Store (insert) Search (lookup) Name & Address Telephone Number Retrieve (get_by_key)
TABLE Primitive Operations Insert (for ordered tables) Delete Find (search by key) Retrieve (data by key) = get(find()) Operations ordinarily dominated by retrieval Requires a find (by key) and a get (return of value) Does not modify the table data Traverse (all of the above require an ability to walk the links
TABLE Composite Operations Edit (general) Retrieve (to get location) Delete old data Insert new data Depending on how the table is implemented this could take up to three taversrals
QUEUE ADT Head First-In-First-Out Tail Retrieve (dequeue) Store (enqueue)
QUEUE Primitive Operations isempty returns true if there is nothing in the queue isfull returns true if this is a fixed size and is full of elements Enqueue adds an element to the tail of the queue Dequeue removes an element from the head Peek looks at the head element without removing it
STACK ADT Last-In-First-Out Store (push) Top_of_stack Retrieve (pop)
STACK Primitive Operations isempty returns true if there are no elements in the stack isfull returns true if the stack is of fixed size and it is full of elements Push puts a new element at the top of the stack Pop removes an element from the top of the stack Peek looks at the element at the top of the stack without removing it
Array Implementations Table multiple arrays or multi-dimensional Key element and value element must be kept in order Sorting two arrays difficult and time inefficient Searching can be implemented as a binary search much faster Queue Single dimensioned array of data type Problem with moving data toward index 0 Circular queue is very efficient Fixed size Stack Single dimensioned array of data type Fixed size
Linked List Implementation Linked lists are extensible (can grow as needed) Search operations take time proportional to the size of the list, n Good performance for queues and stacks but not so good for tables
Linked List Details Could be in program heap or function stack frame head count first last headptr variable In program heap stack (function stack frame) To Add data to unordered list just make the last element point to the new data node. first node node last data data NULL data typedef struct nodestr { Data data; nodestr ; } NodeStr; data heap variables data data typedef struct headstr { int count; NodePtr first; NodePtr last; } HeadStr; typedef HeadStr * HeadPtr; typedef NodeStr * NodePtr;
Linked List Insert newnode datab > dataa Go to next node node datab node datac > datab Insert before dataa datac temp_p Insert datab behind dataa and before datac to establish order. Doubly linked list prior_p dataa prior_p datab
BST New Node David left right root pointer Stack Bill Dennis Heap Less than left right 1 root node left right 0 Donald Granford George More than left right 2 Greg Jim Arron left right left right left right 7 3 4 left right left right 5 6 left right 8 Kelly
class Node { string ; float salary; double y_t_d; Node * ; } Hash Table/Map Implementation of Fast Table hash Wayvern function % class Head { int count; node first; } class HashMap { int size; head hashmap[size]; modulo the array size = 3 0 1 2 Table Array node salary y_t_d node salary y_t_d Wayne Wayvern } int hash(string); void insert(node entry); node find(string ); float getsalary(string ); double getyeartodate(string ); etc. size