如果您在图书馆组织图书,您将如何存储它们以及您将使用哪种数据结构?“

时间:2023-01-17 07:07:54

I would use a hash table and use ISBN number as key. As this will give me a look up time of O(1)....as avg time of look up in hash table is O(1)....

我会使用哈希表并使用ISBN号作为密钥。因为这将给我一个O(1)的查找时间....因为在哈希表中查找的平均时间是O(1)....

we can also use Binary search tree.....look up time is O(nlogn)...

我们也可以使用二进制搜索树.....查找时间是O(nlogn)...

What data structure would you guys use and why?

你会使用什么数据结构?为什么?

2 个解决方案

#1


This sounds like a homework or interview question. If I were asking it, I would be interested in more than just whether you understand a couple of data structures. I would also want to know how you analyze a real-world problem and translate it to the world of computers and data structures.

这听起来像是一个家庭作业或面试问题。如果我问它,我会感兴趣的不仅仅是你是否理解了几个数据结构。我还想知道你如何分析现实问题并将其转换为计算机和数据结构的世界。

As such, you should probably think about what operations you need to perform on the data before you pick a data structure. You should also think some about real libraries and some of the "gotchas" that could come up with any data structure you chose.

因此,您应该考虑在选择数据结构之前需要对数据执行哪些操作。您还应该考虑一些真实的库和一些可能出现您选择的任何数据结构的“陷阱”。

If all you need to do is translate from an ISBN to the catalog entry for the corresponding book, then a hash table might be a reasonable choice. But you might want to think about how you would deal with popular books, such as best sellers, that a library could have many copies of.

如果您需要做的只是从ISBN转换为相应书籍的商品,那么哈希表可能是一个合理的选择。但是你可能想要考虑如何处理流行书籍,例如畅销书,图书馆可以有很多副本。

But is ISBN lookup really the important use case? I use my local library all the time, and I never look up books by ISBN. Some of things that I do are:

但ISBN查找真的是重要的用例吗?我一直使用我当地的图书馆,而且我从不按ISBN查阅书籍。我做的一些事情是:

  • Look up a specific book by title. Sometimes there are different books with the same title.
  • 按标题查找特定书籍。有时会有不同的书籍具有相同的标题。

  • Browse the list of books by an author I like
  • 浏览我喜欢的作者的书籍清单

  • Find where books on a particular subject are shelved, so I can browse them.
  • 查找特定主题的书籍被搁置的地方,以便我可以浏览它们。

Librarians probably have additional uses for a catalog system:

图书馆员可能还有目录系统的其他用途:

  • Add new books to the catalog
  • 将新书添加到目录中

  • Mark books as checked out
  • 将图书标记为已签出

  • Change listing information, such as subject classification, for a book
  • 更改书籍的列表信息,例如主题分类

So I guess my recommendation would be to think more carefully about what problem you want to solve before you decide on the solution.

所以我想我的建议是在决定解决方案之前更仔细地考虑你想要解决的问题。

Apologies for asking more questions instead of providing an answer. I hope this is helpful anyway.

对于提出更多问题而不是提供答案而道歉。我希望无论如何这都有用。

#2


Well ... I don't think the hardest problem to solve with designing a data structure to store information about books is that of look-up speed.

嗯......我认为设计数据结构来存储有关书籍信息的最难解决的问题是查找速度。

And I would certainly not settle for a system that only allowed searching if you know the ISBN. What if you only remember the author, or a few words from the title? If there is to be any gains in having a computerized system for this, you must support flexible searches, in my opinion.

如果你知道ISBN,我肯定不会满足于只允许搜索的系统。如果您只记得作者或标题中的几个字,该怎么办?如果有一个计算机化系统可以获得任何收益,我认为你必须支持灵活的搜索。

I would probably look into using Dublin Core, but I'm not at all sure that's the "right" thing to do. It seems people have spent a great deal of time thinking about that one, though.

我可能会考虑使用都柏林核心,但我完全不确定这是“正确”的事情。不过,似乎人们花了很多时间思考这个问题。

#1


This sounds like a homework or interview question. If I were asking it, I would be interested in more than just whether you understand a couple of data structures. I would also want to know how you analyze a real-world problem and translate it to the world of computers and data structures.

这听起来像是一个家庭作业或面试问题。如果我问它,我会感兴趣的不仅仅是你是否理解了几个数据结构。我还想知道你如何分析现实问题并将其转换为计算机和数据结构的世界。

As such, you should probably think about what operations you need to perform on the data before you pick a data structure. You should also think some about real libraries and some of the "gotchas" that could come up with any data structure you chose.

因此,您应该考虑在选择数据结构之前需要对数据执行哪些操作。您还应该考虑一些真实的库和一些可能出现您选择的任何数据结构的“陷阱”。

If all you need to do is translate from an ISBN to the catalog entry for the corresponding book, then a hash table might be a reasonable choice. But you might want to think about how you would deal with popular books, such as best sellers, that a library could have many copies of.

如果您需要做的只是从ISBN转换为相应书籍的商品,那么哈希表可能是一个合理的选择。但是你可能想要考虑如何处理流行书籍,例如畅销书,图书馆可以有很多副本。

But is ISBN lookup really the important use case? I use my local library all the time, and I never look up books by ISBN. Some of things that I do are:

但ISBN查找真的是重要的用例吗?我一直使用我当地的图书馆,而且我从不按ISBN查阅书籍。我做的一些事情是:

  • Look up a specific book by title. Sometimes there are different books with the same title.
  • 按标题查找特定书籍。有时会有不同的书籍具有相同的标题。

  • Browse the list of books by an author I like
  • 浏览我喜欢的作者的书籍清单

  • Find where books on a particular subject are shelved, so I can browse them.
  • 查找特定主题的书籍被搁置的地方,以便我可以浏览它们。

Librarians probably have additional uses for a catalog system:

图书馆员可能还有目录系统的其他用途:

  • Add new books to the catalog
  • 将新书添加到目录中

  • Mark books as checked out
  • 将图书标记为已签出

  • Change listing information, such as subject classification, for a book
  • 更改书籍的列表信息,例如主题分类

So I guess my recommendation would be to think more carefully about what problem you want to solve before you decide on the solution.

所以我想我的建议是在决定解决方案之前更仔细地考虑你想要解决的问题。

Apologies for asking more questions instead of providing an answer. I hope this is helpful anyway.

对于提出更多问题而不是提供答案而道歉。我希望无论如何这都有用。

#2


Well ... I don't think the hardest problem to solve with designing a data structure to store information about books is that of look-up speed.

嗯......我认为设计数据结构来存储有关书籍信息的最难解决的问题是查找速度。

And I would certainly not settle for a system that only allowed searching if you know the ISBN. What if you only remember the author, or a few words from the title? If there is to be any gains in having a computerized system for this, you must support flexible searches, in my opinion.

如果你知道ISBN,我肯定不会满足于只允许搜索的系统。如果您只记得作者或标题中的几个字,该怎么办?如果有一个计算机化系统可以获得任何收益,我认为你必须支持灵活的搜索。

I would probably look into using Dublin Core, but I'm not at all sure that's the "right" thing to do. It seems people have spent a great deal of time thinking about that one, though.

我可能会考虑使用都柏林核心,但我完全不确定这是“正确”的事情。不过,似乎人们花了很多时间思考这个问题。