Data Structures and Algorithms - Performance Analysis of Algorithms and Recurrences

Avatto > > UGC NET COMPUTER SCIENCE > > PRACTICE QUESTIONS > > Data Structures and Algorithms > > Performance Analysis of Algorithms and Recurrences

71. An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum is

  • Option : D
  • Explanation :
    Suppose a list contains n elements, consider first three element and find middle element which will be neither maximum nor minimum. Hence it is θ(1).
Cancel reply
Cancel reply

75. 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?

  • Option : C
  • Explanation :
    Delete operation require O(1) time total O(N) Delete so time is = O(n).
    Insert require O(n) time in worst case total O (logn) insert so time is = O(Nlogn) to Search (logn) key time is = nlogn.
    To perform decrease key we need O (n) time (because after decrease we need to arrange elements in sorted sequerce) so total O(N) decrease key So total time is O(N2) All operations put together than worst time is O(N2)
Cancel reply
Cancel reply