【发布时间】:2015-12-07 16:07:24
【问题描述】:
我有一个代表一个事件的类。
所以我们可以通过创建这个类的对象来创建一个事件。构造函数接受description, start time, end time, list of invites, location 并返回一个用于唯一标识此对象的id。
Create events : (description, start time, end time, list of invites, location) -> id
现在这个类有另一个方法,它接受一个 id 并返回一个相应的事件对象
Get event by id : id -> event object
同样我们可以更新一个事件
Update event -> description, start time, end time
现在我们要做的第四个操作是我们要过滤掉一个时间范围内的所有事件
get event : start time, end time
现在我必须使用/设计一个可以有效执行这 4 种操作的数据结构。 (我的意思是我们现在可以使用文件存储或缓存技术)
对于第一个三个操作,我认为我可以使用 Has map/table,它将 id 作为键和对象作为值。
但在这种情况下,我将无法有效地执行第四次操作。
虽然我可以再次使用 trie 数据结构。
Root Node->
Month nodes (12 nodes)
each month node will be having 30(or 31/28) children nodes.
and then those children nodes will be having time stamp nodes.
但在这种情况下,前三个操作变得有点低效。
如何结合这两种数据结构来解决这个问题并高效地执行所有 4 种操作。或者有没有更好的数据结构可以完成这项任务。还是我们必须创建自己的自定义数据结构?
【问题讨论】:
标签: algorithm data-structures hashmap binary-search-tree