This question was asked to me during company interview –
Which data-structure is efficient for Implementing Elevator Mechanism?
I am not able to find the efficient data-structure for it even after a lot of Googling.
I can think of Priority queue to Implement it.Is priority queue an efficient data structure or more efficient data structure is there for implementing Elevator Mechanism?
Thanks!
Since you cannot implement mechanisms in software (although you can certainly model them), I assume that the question has been about the Elevator algorithm.
The algorithm looks deceivingly simple, yet it is surprisingly very tough to implement, even with a good set of data structures in hand. A good structure to use for this algorithm is three priority queues:
Your implementation would first decide the direction, then pick a queue into which to place the requested pair of
{from, to}values.