CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2008
    Posts
    6

    Sorted Structure/constant ith item access time

    Hello,

    I am looking for a structure that allows me to:

    1. Append in O(logN) or better
    2. Delete in O(logN) or better
    3. Access the ith item in O(1)

    I don't need any other operations

    In addition, new items are always greater (>) than existing items (the structure is always sorted) and no item appears twice.

    Maybe, I think it is impossible...

  2. #2
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Sorted Structure/constant ith item access time

    c# SortedDictionary removal and insertion and retrieval is O(log n)

    see more information here and some comparison between c# SortedDictionary and SortedList.

    MSDN:
    http://msdn.microsoft.com/en-us/library/ms132319.aspx

    what do you mean by access O(1) i think it is not possible !
    if you mean access by KEY, index all Array-Like structures apply to it but something like any kind of Linked-List (recursive-Two way- with header/ without header) don't apply to it.
    Last edited by toraj58; December 16th, 2008 at 03:08 AM.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Dec 2008
    Posts
    6

    Re: Sorted Structure/constant ith item access time

    Deletion and Append O(N), Access O(1), that is an array.

    You can improve the first two to O(logN) by making access more expensive. For any kind of item. I know that.

    What I want, is to make the first two cheaper, but keeping access at O(1), by abusing the fact that I only need delete/append (and not insert). and the values are increasing. If it's possible...

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Sorted Structure/constant ith item access time

    If you use a sorted array, append would also be in O(1) due to the nature of your data, but deletion not at the end would still be in O(n).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Dec 2008
    Posts
    6

    Re: Sorted Structure/constant ith item access time

    That's right, I meanto to say Deletion and Insertion are O(N).


    Basically what I am trying to avoid is the effect that deleting at the start requires moving all items in front to move one back. But I guess there is no way around it if you want to keep access at O(1).

    What about something like

    n items, m (already done) deletions, or gaps

    O(m) access, O(1) append, O(logN) delete... possible? hmm

  6. #6

    Re: Sorted Structure/constant ith item access time

    Are those worst case or average?

    The primary operations of a VList are:
    * Locate the kth element (O(1) average, O(log n) worst-case)
    * Add an element to the front of the VList (O(1) average, with an occasional allocation)
    * Obtain a new array beginning at the second element of an old array (O(1))
    * Compute the length of the list (O(log n))

    You haven't specified whether it's deletiog from one end, from either end or from the middle you want to be scalable.

  7. #7
    Join Date
    Dec 2008
    Posts
    6

    Re: Sorted Structure/constant ith item access time

    Deletion from everywhere.

    I had a look at VLists, but it seems a bit flawed. What happens if you delete lots of elements in the middle? The VList will turn into a linked list? Or is there some magical "rebalancing" going on? I will read the paper on it.

    Also, if you have 2^20 elements, in the first node there will be 2^10 items. What happens if you delete the 2^9th element? Still need to move lots of elements.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured