A data structure is required for storing a set of integers such that each of the following O(log n) operations can be done in time, where n is the number of elements in the set. Deletion of the smallest element 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?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. A balanced binary search tree can be used but not a heap.
Explanation
A heap deletes the minimum in O(log n) but cannot check 'not already present' faster than O(n). A balanced BST does both in O(log n).
More Data Structures and Algorithms questions
- Consider the following graph. Among the following sequences I. a b e g h f II. a b f e h g III. a b f h g e IV. a f g h b e Which are depth…
- Which of the given options provides the increasing order of asymptotic complexity of f1, f2, f3 f4 functions and ? f1(n) = 2n A. f2(n) = n3…
- A hash function h(key) = key mod 7 with linear probing is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed 0 to 6. W…
- Match each graph algorithm with its time complexity (n vertices, m edges). List I: A. Bellman-Ford, B. Kruskal's algorithm, C. Floyd-Warsha…
- The reverse Polish notation of the infix expression [A * {B + C * (D + E)}] / {F * (G + H)} is
- With preconditions a > 1 and a < b (no overflow): int x = 0; int p = 1; while (p < b) { p = p * a; x = x + 1; } When the loop ends, x in te…