An algorithm performs find operations , insert operations, delete operations, and decrease-key operations on a set of data items with keys drawn from a linearly ordered set . For a delete operation, a pointer is provided to the record that must be deleted . For the decrease-key operation, a pointer is provided to the record that has its key decreased. Which one of the following data structures is the most suited for the algorithm to use, if the goal is to achieve the best total asymptotic complexity considering all the operations?
View worked solution
Answer: A
To find the most suitable data structure, we analyze the total asymptotic cost for each option based on the given operation counts:
- Find: operations
- Insert: operations
- Delete (pointer given): operations
- Decrease-key (pointer given): operations
Let us evaluate the total cost for each data structure:
-
Unsorted Array:
- Insert: per operation Total
- Find: per operation Total
- Delete: (swap with the last element) Total
- Decrease-key: (no order to maintain) Total
- Total Cost:
-
Min-heap:
- Insert: per operation Total
- Find: per operation (linear search) Total
- Total Cost: (since )
-
Sorted Array:
- Insert: per operation (due to shifting) Total
- Total Cost:
-
Sorted Doubly Linked List:
- Insert: per operation (to find position) Total
- Total Cost:
Comparing the total complexities, the Unsorted Array achieves the lowest overall asymptotic complexity of .
Free practice · Your answers on this page are not saved.
