Data Structures Flashcards
Describe the format of Linked List data structure (3)
- Linear data structure
- Data is not stored in contiguous memory
- Comprised of nodes which have a variable for the data to be stored and a pointer to the next node in the list.
Advantages of Linked List (3)
- Dynamic size
- Memory is not wasted
- Effective insertion and deletion as data doesn’t have to move like in arrays
Disadvantage of Linked List (3)
- Using more memory per node due to having to maintain the pointer
- O(n) access due to having to traverse list from head
- Cache inefficient as memory is not stored in contiguous memory
Complexity of insert/delete at beginning of Linked List
O(1)
Complexity of insert/delete at end of Linked List
O(n)
Complexity of insert/delete at given point in Linked List
O(n)
Complexity of searching/accessing Linked List by index
O(n)
Describe the format of a Stack data structure (4)
- Linear data structure
- Follows Last in First Out, access via the top of the stack
- Can be fixed size or dynamic
- Can be implemented with both Arrays or Linked List
Advantages of Stack data structure (4)
- Simplicity
- Efficiency: O(1) operations
- LIFO
- Limited memory usage
Disadvantages of Stack data structure (2)
- Limited access: O(n)
- Possibility of overflow if fixed size
Common Stack operations (5)
- Push
- Pop
- Peek
- Size
- isEmpty
Complexity of insert in Stack
O(1)
Complexity of removal in Stack
O(1)
Describe the structure of Queue data structure (4)
- Linear data structure
- Follows First in First Out
- Can be fixed size or dynamic
- Can be implemented with both Arrays or Linked List
Common Queue operations (5)
- Enqueue O(1)
- Dequeue O(1)
- Peek
- Size
- IsEmpty
What is a Binary Search Tree?
A tree data structure where each node has two children and they fit a specific ordering such as:
All left children < n < all right children
What are the advantages of BST? (5)
- Efficient searching: O(log n) time complexity
- Ordered structure: Elements are stored in sorted order, making it easy to find the next or previous element
- Dynamic insertion and deletion: Elements can be added or removed efficiently
- Balanced structure: Can be balanced to maintain logarithmic height, ensuring efficient operations
- Space efficiency
What are the disadvantages of BST? (5)
- Not self-balancing: Unbalanced BSTs can lead to poor performance
- Worst-case time complexity: In the worst case, BSTs can have a linear time complexity for searching and insertion
- Memory overhead: Pointers
- BSTs can become inefficient for very large datasets
- Limited functionality: BSTs only support searching, insertion, and deletion operations