data structure and algorithm for table allocations in restaurant?

In one of my past interviews, I was asked to describe how do you model a restaurant with tables and chairs and how do you allocate to the guests as they arrive as well as previously made reservations.

For example, when a group of 20 people come in you have to join the tables into one to make them as a group.

when I tried to model using simple object oriented design terms, he stopped me and asked is there any specific data structures or algorithms would you use to solve this problem.

I am not aware of any? Could someone give me a pointer?


I can't think of any particular algorithm and by this I mean that maybe is simply a problem to see how you think rather than a problem which would have a particularly well suited solution.

In any case it seems to me that the physical distribution of the tables is crucial: you can only join tables that are close to each other. Typically, you cannot move seated people to a different table or drag far apart tables across the restaurant. This calls for a data structures which models the physical distribution of tables, that is, a net with connected nodes. This can be complicated all you want including, for instance, distance between tables, partition the net with the corridors, etc.

To find a free table, or take or release a free table, as the typical number of tables would be small you can just iterate sequentially. Being more of an academical exercise you'd probably want to think of something more apt to the problem but there aren't enough requirements to make a decision about that.

链接地址: http://www.djcxy.com/p/26954.html

上一篇: Redis使用的基础数据结构是什么?

下一篇: 餐厅餐桌分配的数据结构和算法?