Skip to content
Official PYQ · 2015

GATE CS 2015 Set 1 Q40 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

An algorithm performs (log⁡N)12(\log N)^{\frac{1}{2}} find operations , NN insert operations, (log⁡N)12(\log N)^{\frac{1}{2}} delete operations, and (log⁡N)12(\log N)^{\frac{1}{2}} 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?

Choose one option
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: (log⁡N)1/2(\log N)^{1/2} operations
  • Insert: NN operations
  • Delete (pointer given): (log⁡N)1/2(\log N)^{1/2} operations
  • Decrease-key (pointer given): (log⁡N)1/2(\log N)^{1/2} operations

Let us evaluate the total cost for each data structure:

  1. Unsorted Array:
    • Insert: O(1)O(1) per operation   ⟹  \implies Total O(N)O(N)
    • Find: O(N)O(N) per operation   ⟹  \implies Total O(N(log⁡N)1/2)O(N (\log N)^{1/2})
    • Delete: O(1)O(1) (swap with the last element)   ⟹  \implies Total O((log⁡N)1/2)O((\log N)^{1/2})
    • Decrease-key: O(1)O(1) (no order to maintain)   ⟹  \implies Total O((log⁡N)1/2)O((\log N)^{1/2})
    • Total Cost: O(N(log⁡N)1/2)O(N (\log N)^{1/2})
  2. Min-heap:
    • Insert: O(log⁡N)O(\log N) per operation   ⟹  \implies Total O(Nlog⁡N)O(N \log N)
    • Find: O(N)O(N) per operation (linear search)   ⟹  \implies Total O(N(log⁡N)1/2)O(N (\log N)^{1/2})
    • Total Cost: O(Nlog⁡N)O(N \log N) (since Nlog⁡N>N(log⁡N)1/2N \log N > N (\log N)^{1/2})
  3. Sorted Array:
    • Insert: O(N)O(N) per operation (due to shifting)   ⟹  \implies Total O(N2)O(N^2)
    • Total Cost: O(N2)O(N^2)
  4. Sorted Doubly Linked List:
    • Insert: O(N)O(N) per operation (to find position)   ⟹  \implies Total O(N2)O(N^2)
    • Total Cost: O(N2)O(N^2)

Comparing the total complexities, the Unsorted Array achieves the lowest overall asymptotic complexity of O(N(log⁡N)1/2)O(N (\log N)^{1/2}).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions