N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this order: Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key. What is the time complexity of all these operations put together?

N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this order: Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key. What is the time complexity of all these operations put together? Correct Answer O(N<sup>2</sup>)

Here, it is given that pointer is provided to the record on which the decrease key operation is to be performed. So, time complexity of decrease key operation is Θ (1)

For insert – Θ (N), we need to insert the element at the end of the sorted list.

For delete – Θ (1) time is needed, as pointer is directly given

For decrease key – Θ (N), because after decreasing the key value, all the elements must be sorted again.

Now combining all the operations together:

For delete = Θ (N)* Θ (1)

For insert = Θ (log N)*Θ (N)

For find = Θ (log N)*Θ (N)

For decrease-key = Θ (N)* Θ (N)

So, overall complexity = Θ (N)* Θ (1 ) + Θ (logN)* Θ (N) + Θ (logN)* Θ (N)+ Θ (N)* Θ (N)

Time complexity of all these operations put together = Θ (N2)

Related Questions

Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not given, can we delete the node X from given linked list?
Consider a singly linked list of the form where F is a pointer to the first element in the linked list and L is the pointer to the last element in the list. The time of which of the following operations depends on the length of the list?
Consider the problem of reversing a singly linked list. To take an example, given the linked list below, the reversed linked list should look like Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in O(1) space?