Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Inserting into a binary heap of n elements (array-based, sift-up) takes worst-case time:
- A. O(log n)
- B. O(1)
- C. O(n)
- D. O(n log n)
Correct answer: A. O(log n)
A new element is placed at the next free leaf and sifted up at most the height of the heap, which is O(log n).
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 12, 54, 92, 89, 71, 88, 69 are inserted in this order into an empty BST. What is the postorder traversal?
- A max-heap is built by inserting 87, 88, 19, 50, 39, 89 one by one (sift-up on each insert). After one extract-max (move the last element…
- Which traversal of a binary search tree visits the keys in ascending order?
- Which data structure does breadth-first search (BFS) use to decide which vertex to visit next?
- How many edges does a tree with n vertices have?
- In a min-heap, where is the smallest element always found?