QuestionMay 1, 2025

If you need to implement a data structure that stores unique keys and allows for efficient insertions/deletions and enumeration(traversal) in a sorted order, which would you choose? Partially filled array Linked list Binary Search Tree Hash Table

If you need to implement a data structure that stores unique keys and allows for efficient insertions/deletions and enumeration(traversal) in a sorted order, which would you choose? Partially filled array Linked list Binary Search Tree Hash Table
If you need to implement a data structure that stores unique keys and allows for efficient insertions/deletions and
enumeration(traversal) in a sorted order, which would you choose?
Partially filled array
Linked list
Binary Search Tree
Hash Table

Solution
3.6(316 votes)

Answer

Binary Search Tree Explanation 1. Analyze the requirements The data structure must store unique keys, support efficient insertions/deletions, and allow traversal in sorted order. 2. Evaluate options - **Partially filled array**: Inefficient for insertions/deletions and does not guarantee sorted order. - **Linked list**: Inefficient for maintaining sorted order and traversal. - **Binary Search Tree (BST)**: Efficient for insertions/deletions (O(\log n) for balanced BSTs) and supports in-order traversal for sorted order. - **Hash Table**: Does not maintain sorted order.

Explanation

1. Analyze the requirements<br /> The data structure must store unique keys, support efficient insertions/deletions, and allow traversal in sorted order.<br /><br />2. Evaluate options<br /> - **Partially filled array**: Inefficient for insertions/deletions and does not guarantee sorted order.<br /> - **Linked list**: Inefficient for maintaining sorted order and traversal.<br /> - **Binary Search Tree (BST)**: Efficient for insertions/deletions ($O(\log n)$ for balanced BSTs) and supports in-order traversal for sorted order.<br /> - **Hash Table**: Does not maintain sorted order.
Click to rate: