Re: Data structure query



mysorepushpa@xxxxxxxxx wrote:
I have a specific requirement in which I have thousands of key-value
pairs which needs to be stored and
retrieved in alphabetical order. Which data structure can I use for
the same. Which is the best data-structure to use both in terms of
space to store and also the time required to retrieve given a key the
corresponding value.

Insufficient information. Questions that spring to mind:

Are the key/value pairs static, or do they need to be added/removed dynamically?
Are the keys and values of fixed or variable size?
Will the keys or the key/value pairs fit in memory?

I will guess that the keys are strings (hence variable length), and that "alphabetical order" refers to the keys. I will assume that the values are also of variable length, and that the data structure is static and entirely in memory.

An array of {pointer to key, pointer to value} sorted by key would allow ordered retrieval, as well as binary search to find a value given the key with minimal space overhead.

This could be augmented with a simple hash table using open addressing and storing pointers to the array. This may give better lookup performance at a cost of, say, two pointers per item (ie table 50% full).

Alex
.



Relevant Pages

  • Data structure query
    ... I have a specific requirement in which I have thousands of key-value ... retrieved in alphabetical order. ... Which data structure can I use for ... space to store and also the time required to retrieve given a key the ...
    (comp.programming)
  • Re: For Each... Next equivalent
    ... However if you can use an external data structure you can use my RTVFLDA (Retrieve Field Attributes) utility to retrieve the field definition one by one. ... Additional fields of format FLDA0200 ... Reference library name ...
    (comp.sys.ibm.as400.misc)
  • [PATCH] s/retreiv/retriev/g
    ... /* Returns the dentry referring to the root of the extended ... we attempt to retrieve it from disk. ... * @tty - pointer to tty instance data ... * @buf - pointer to returned data buffer ...
    (Linux-Kernel)
  • Re: generic data structure question
    ... > What is the best data structure to ... > to maintain an array of information with containing 3 fields of differing ... > method to retrieve the correct record? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: CListBox question again
    ... Did you check the retrurn in pName at the top? ... I'm assuming you did call GetDocumentor something to fill in the m_pDoc pointer. ... and gets the same pointer when I retrieve them with GetItemDataPtr. ... is in the OnInitailDlgfunction of the dialog with the CListBox in it. ...
    (microsoft.public.vc.mfc)