-
Notifications
You must be signed in to change notification settings - Fork 43
Data Structures
Definition: A linear collection of nodes in which each node links to the next node.
Each node has a single pointer to the next node.
- Need constant time insertion or deletion
- Only at head (front of list)
- Inserting elements is easier in singly linked list that in doubly linked list
- Unknown number of elements
- No need for random access
- Need linked list and memory is a concern
- Requires less memory than doubly linked list
Average | Worst | |
---|---|---|
Access | θ(n) | O(n) |
Search | θ(n) | O(n) |
Insertion | θ(1) | O(1) |
Deletion | θ(1) | O(1) |
Each node has two pointers, one to the previous node and one to the next node.
- Need constant time insertion or deletion
- Only at head or tail (front or back of list)
- Doubly linked list deletion is faster that singly linked list deletion, except when deleting the head
- Unknown number of elements
- No need for random access
Average | Worst | |
---|---|---|
Access | θ(n) | O(n) |
Search | θ(n) | O(n) |
Insertion | θ(1) | O(1) |
Deletion | θ(1) | O(1) |
Definition: An abstract data type that supports a last in, first out (LIFO) policy. A push method is used to add an element onto the stack and a pop method is used to remove the most recent element of the stack.
- List reversal
- Parsing
- Expression conversion and evaluation
- Balancing delimiters
- Tower of Hanoi
Average | Worst | |
---|---|---|
Access | θ(n) | O(n) |
Search | θ(n) | O(n) |
Insertion | θ(1) | O(1) |
Deletion | θ(1) | O(1) |
Definition: Elements within this abstract data type are ordered by a specified principle. An enqueue method adds an element to the back of the queue, while a dequeue method removes an element from the front of the queue.
The traditional queue policy is first in, first out (FIFO), just like a line for a service. Elements which are added to the queue more recently are accessible sooner than elements added to the queue later on.
- Need to maintain order
- Packet transmission
- Providing a service in which clients are all valued equally
Average | Worst | |
---|---|---|
Access | θ(n) | O(n) |
Search | θ(n) | O(n) |
Insertion | θ(1) | O(1) |
Deletion | θ(1) | O(1) |
Elements can be inserted and removed from both the front and back of this type of queue.
- Need access to old and new elements
- Providing a service that is likely to require clients to return
- A fast food cashier serves a customer their order but forgets to include ketchup packets
- The customer is allowed to cut the line to get ketchup packets.
- A fast food cashier serves a customer their order but forgets to include ketchup packets
Average | Worst | |
---|---|---|
Access | θ(n) | O(n) |
Search | θ(n) | O(n) |
Insertion | θ(1) | O(1) |
Deletion | θ(1) | O(1) |
Similar to a queue, except elements are assigned priorities, and these priorities determine the element's position in the queue. A priority queue is typically implemented with a min or max heap.
- Event-driven scheduling
- Data compression
- Graphing algorithms (Dijkstra, Prim)
- Bandwidth management
Average | Worst | |
---|---|---|
Access | θ(1) | O(1) |
Search | θ(n) | O(n) |
Insertion | θ(nlog(n)) | O(nlog(n)) |
Deletion | θ(nlog(n)) | O(nlog(n)) |
Definition: A hierarchical structure of parent-child relationships between nodes. Each parent will one level higher on the structure than its children, respectively. Trees are non-cyclic but may be linear.
Ordered upon the principle that a node's left child must have a value less than the parent's value and its right child must have a value greater than the parent's value. It is common for repeated nodes to be disallowed; however, in the case of a BST which allows repeated nodes, either the left child condition or the right child condition can be modified to handle equal values.
- Goal of average case of log(n) for all operations
- Need memory efficient solution to storing data
- Expression evaluation
- Data compression
Average | Worst | |
---|---|---|
Access | θ(log(n)) | O(n) |
Search | θ(log(n)) | O(n) |
Insertion | θ(log(n)) | O(n) |
Deletion | θ(log(n)) | O(n) |
Self-balancing binary search tree in which the difference in height between left and right subtrees cannot exceed one for all nodes. If a node is inserted or deleted such that the height condition is violated, an AVL tree will reorder itself to meet its height conditions and standard BST conditions.
- Lookup time is priority
- Fastest of the trees in terms of lookup time
- Not concerned with insertion and deletion times
- Slow insertions and deletions due to strict height requirements
- Requires rebalancing often
Average | Worst | |
---|---|---|
Access | θ(log(n)) | O(log(n)) |
Search | θ(log(n)) | O(log(n)) |
Insertion | θ(log(n)) | O(log(n)) |
Deletion | θ(log(n)) | O(log(n)) |
Average | Worst | |
---|---|---|
Access | θ(log(n)) | O(log(n)) |
Search | θ(log(n)) | O(log(n)) |
Insertion | θ(log(n)) | O(log(n)) |
Deletion | θ(log(n)) | O(log(n)) |