Data Structures¶
An abstract data type (ADT) is a specification of:
-
A set of data.
-
A set of operations that can be performed on the data.
ADT is abstract in the sense that it is independent of various concrete implementations.
- Encapsulates data structures and relecant algorithms.
- Provides access interface.
Stack¶
A pile of plates
An object added to the stack goes on the "top" of the stack. (push
)
An object removed from the stack is taken from the "top" of the stack (pop
)
LIFO: Last in, First out
Operations¶
1 2 3 4 5 6 7 8 |
|
Queue¶
A real-life queue
An element added to the queue foes to the "end" of the queue. (enqueue
)
The element which has been in the queue the longest can be removed from the queue. (dequeue
)
Elements are removed from a queue in the same order as they were inserted.
FIFO: First in, First out.
Operations¶
1 2 3 4 5 |
|
Linked List¶
A sequence of elements
Each element in the linked list is with:
- One key
- One ore more pointers
There are different types depending on how the elements are linked.
Singly linked list¶
Element:
- A key
- One pointer: "next", pointing the the successor of the element.
- The last element points to a "NIL".
Head pointer:
- Pointer "head": pointing to the first element of the list.
Note:
- "next" are for elements (x.next)
- "head" is for whole list (L.head)
Alternatively:¶
Doubly linked list¶
Element:
- A key
- Two pointers: "next" and "prev"
Still has "head".
Alternatively¶
Operations¶
1 2 3 4 5 6 7 8 |
|
Priority Queue¶
A priority queue (PQ) is a container for maintaining a set A of elements, each with an associated value called key.
Operations¶
1 2 3 4 5 6 7 8 |
|
Heap Implementation¶
Use a max-heap.