Sollicitatievraag bij RTX

Design a getMin() method with constant, O(1), runtime.

Antwoord op sollicitatievraag

Anoniem

14 nov 2017

Not an answerable question with no additional information. One possibility is a min heap. The minimum value will always be the root node in the tree. But something like a plain array and you'll need to traverse the whole thing every time, so O(n). You could encapsulate an array in another class that keeps track of the min as you add elements, though, and that could run in O(1).