Data structure to handle the requirement of following use case

前端 未结 5 1792
梦谈多话
梦谈多话 2021-01-29 13:10

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 follo

5条回答
  •  Happy的楠姐
    2021-01-29 13:40

    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.

提交回复
热议问题