recategorized by
41,262 views
131 131 votes

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

  1. Unsorted array
  2. Min - heap
  3. Sorted array
  4. Sorted doubly linked list

7 Answers

Best answer
178 178 votes
$\small \begin{array}{|c|l|l|l|l|} \hline
&\mathbf{(\log N)^{\frac{1}{2}}} \text{ find} & \mathbf{N} \text{ insert} &  \mathbf{(\log N)^{\frac{1}{2}}} \text{delete} & \mathbf{(\log N)^{\frac{1}{2}}}  \text{decrease-key} \\ \hline
\text{Unsorted Array} & O(N (\log N)^{\frac{1}{2}}) &O(N) &O(\log N)^{\frac{1}{2}})&O(\log N)^{\frac{1}{2}})\\ \text{Min-heap} &O(N (\log N)^{\frac{1}{2}})&O(N \log N)&O(\log N)^{\frac{3}{2}})&O((\log N)^{\frac{3}{2}})\\ \text{Sorted Array} &O((\log N)^{\frac{3}{2}})&O(N^2)&O(N (\log N)^{\frac{1}{2}})&O(N (\log N)^{\frac{1}{2}})\\ \text{Sorted doubly linked-list} &O(N (\log N)^{\frac{1}{2}})&O(N^2)&O((\log N)^{\frac{1}{2}})&O(N (\log N)^{\frac{1}{2}})\\\hline \end{array}$

So, Unsorted array is the answer.

The operations given can be performed in any order. So, for Min-heap we cannot do the usual BuildHeap method.

Delete in unsorted array is $O(1)$ as we can just swap the deleted element with the last element in the array and delete the last element.

For sorted-doubly linked-list we cannot do binary search as this would require another array to maintain the pointers to the nodes.

Correct Answer: $A$
edited by
66 66 votes

I got the same table as Arjun sir got.

& Everybody must know that how it derived.

But I think for average mind like me it will time-consuming in exam.

I have one observation while I read this question.

Imp Note : I have Considered (find,insert,delete,dec-key) operations while giving ans.

Before and After doing operations on data structure x it is required that it should be data structure x only.Now replace x with given data structures.

So If it is a heap then after doing specified operations(find,insert,delete,dec-key) it should be heap only.

Means Heap Constraint need to be satisfied. Same phenomena applicable for other data structure.

So max time is consuming in fulfilling that constraint.

That's why Unsorted Array (where no such constraint) won the Race compare to Heap,Sorted array and Sorted doubly linked list which are truely structured.

So Option A. unsorted array is Ans.

PS:- 1. Plz verify my ans. And comment if u r not agree.

2. Must realize Arjun sir's Ans.

edited by
38 38 votes

This might help n(logn)^1/2

1 flag:
✌ Edit necessary (aashish1406 “Min heap searching time will take O(n) time but here akshat is taken it O(logn)”)
11 11 votes
Answer : A

The time complexity of insert in unsorted array is O(1), O(Logn) in Min-Heap, O(n) in sorted array and sorted DLL.

Since number of insertion operations is asymptotically higher, unsorted array is preferred.
2 2 votes

For Unsorted Array

Find takes O(N) time as we have to scan all the elements so for $O(logN)$$^1$$^/$$^2$ find operations =O(N$(logN)$$^1$$^/$$^2$)

Insertion takes O(1) time as we will insert at the end of array so for O(N) insertions = $O(1)*O(N)=O(N)$

For Deletion a pointer is given so we will swap pointed element with last element and delete it which takes O(!) time, so for $O(logN)$$^1$$^/$$^2$ deletions = O(1)*$O(logN)$$^1$$^/$$^2$=$O(logN)$$^1$$^/$$^2$.

for Decrease Key a pointer is given so we can decrease key in O(1) time so for $O(logN)$$^1$$^/$$^2$ decrease key operations = O(1)*$O(logN)$$^1$$^/$$^2$=$O(logN)$$^1$$^/$$^2$.

in the same way analyse other data structures 

and then check table given by Arjun sir.

 Unsorted array is the answer

Answer:
Position:
Show:

Related questions

77 77 votes
5 answers 5 answers
16.9k
16.9k views
Misbah Ghaya asked Feb 13, 2015
16,918 views
Let a$_{n}$ represent the number of bit strings of length n containing two consecutive $1$s. What is the recurrence relation for $a_{n}$?$a_{n - 2} + a_{n - 1} + 2^{n - 2...
93 93 votes
16 answers 16 answers
32.7k
32.7k views
Misbah Ghaya asked Feb 13, 2015
32,729 views
Let $G = (V, E)$ be a simple undirected graph, and $s$ be a particular vertex in it called the source. For $x \in V$, let $d(x)$ denote the shortest distance in $G$ from ...
89 89 votes
7 answers 7 answers
29.5k
29.5k views
Misbah Ghaya asked Feb 13, 2015
29,515 views
The graph shown below has $8$ edges with distinct integer edge weights. The minimum spanning tree (MST) is of weight $36$ and contains the edges: $\{(A, C), (B, C), (B, E...
80 80 votes
9 answers 9 answers
32.0k
32.0k views
Misbah Ghaya asked Feb 13, 2015
32,005 views
Consider the following C function.int fun1 (int n) { int i, j, k, p, q = 0; for (i = 1; i < n; ++i) { p = 0; for (j = n; j 1; j = j/2) ++p; for (k = 1; k < p; k = k * 2)...