A data structure is required for storing a set of integers such that each of the following operations can be done in O(logn) time, where n is the number of elements in the set.
-
Deletion of the smallest element
- Insertion of an element.
Which of the following data structures can be used for this purpose?
- A heap can be used but not a balanced binary search tree
-
A balanced binary search tree can be used but not a heap
-
Both balanced binary search tree and heap can be used
-
Neither balanced search tree nor heap can be used
I. Deletion of an element for both balance BST and heap (min heap) will take O(logn)
II.for insertion of an element in heap should take O(logn) time by insert key operation and for balance Bst also it should be O(logn) as for balancing it will take O(logn) time .
Correct me if i am wrong