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
What are the common operations for BST and their time complexities? (3)
- Insert: O(log(N))
- Delete: O(log(N))
- Search: O(log(N))
What are some applications of a BST? (5)
- Searching: Finding a specific element in a sorted collection
- Sorting: Sorting a collection of elements in ascending or descending order
- Range queries: Finding elements within a specified range
- Data storage: Storing and retrieving data in a hierarchical manner
- Databases: Indexing data for efficient retrieval
What is a balanced tree?
Tree where the left and right sub trees are some what similar so that operations are O(log(n))
What is a complete binary tree?
A complete binary tree is a binary tree in which every level of the tree is fully filled, except for perhaps the last level. To the extent that the last level is filled, it is filled left to right.
What is a full binary tree?
A full binary tree is a binary tree in which every node has either zero or two children.That is, no nodes have only one child.
What is a perfect binary tree?
Binary tree which is both full and complete