数据结构来处理以下用例的要求 [英] Data structure to handle the requirement of following use case
本文介绍了数据结构来处理以下用例的要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
中的所有数据库中的记录被保存在(键,值)对formats.Records总是可以通过指定键值进行检索。数据结构有待开发,以处理以下情形
- 访问以线性方式中的所有记录(数组或链表是最佳的数据结构,这种情况在O访问(N)的时间)
- 通过提供关键检索记录(哈希表可以实现索引它在O(1)复杂性)
- 检索记录集为一个数值上的关键一特定字节。例如:所有记录的清单其中第2个数字(10的地方)的关键应该是5,如果密钥是256,1452,362,874,钥匙记录,256和1452应退还
解决方案
我假设你钥匙在大多数D位数(十进制)。
怎么样普通的哈希表和一个额外的10 * D二维数组(姑且称之为A)的套。 A [1] [j]的是一组具有数字我在第j个位置键。该组可以支持O(1)插入/删除,如果实现自己的哈希表。
All the records in a database is saved in (key, value) pair formats.Records can always be retrieved by specifying key value. Data structure needs to be developed to handle following scenarios
- Access all the records in a linear fashion (Array or linked list is best data structure for this scenario to access in O(N) time)
- retrieve the record by providing the key (hash table can be implemented to index it in O(1) complexity)
- Retrieve set of records for a value at a particular byte in the key . Ex: List of all records for which 2nd number(10's place) in the key should be 5 and if the keys are 256, 1452, 362, 874, the records for keys , 256 and 1452 should be returned
解决方案
I am assuming you keys are at most d digits long (in decimal).
How about a normal hashtable and an additional 10*d two dimensional array (let's call it A) of sets. A[i][j] is the set of keys which have digit i in the jth position. The sets can support O(1) insert/delete if implemented themselves as hashtables.
这篇关于数据结构来处理以下用例的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文