Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. A data structure is required for storing a set of integers such that each of the following operations can be done in O(log n), time, where n is the number of elements in the set
    I. Deletion of the smallest element.
    II. Insertion of an element, if it is not already present in the set
    Which of the following data structures can be used for this purpose ?
    1. A heap can be used but not a balanced binary search tree
    2. A balanced binary search tree can be used but not a heap
    3. Both balanced binary search tree and heap can be used
    4. Neither balanced binary search tree nor heap can be used
Correct Option: B

Both the tasks can be performed by both the data structures but heap is a data structure where to perform these function every element has to be checked so O(n) complexity.
But the balance binary search tree is efficient data structure since at every decision it selects one of its subtree to no. of elements to be checked are reduced by a factor of 1/2 every time.
n /2!= x
x = log n
Hence (b) is correct option.



Your comments will be displayed only after manual approval.