Data structure to handle the requirement of following use case

前端 未结 5 1786
梦谈多话
梦谈多话 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条回答
  •  没有蜡笔的小新
    2021-01-29 13:42

    The first thing that comes to mind is embedding a pair of nodes in each record. One of the nodes would be a part of a tree sorted by the record index and the other, part of a tree sorted by the record key. You can then have quick access to the records by index or key using these trees. With this you can also quickly visit records in sequential index or key order. This covers the first and second requirement.

    You can add another node for a tree of records whose values contain 5 in the tens position. That covers the third requirement.

    Extra benefit: the same tree handling code will be used in all cases.

提交回复
热议问题