Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 786663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:04:43+00:00 2026-05-14T21:04:43+00:00

I need a collection data-structure that can do the following: Be sorted Allow me

  • 0

I need a collection data-structure that can do the following:

  • Be sorted
  • Allow me to quickly pop values off the front and back of the list O(log n)
  • Remain sorted after I insert a new value
  • Allow a user-specified comparison function, as I will be storing tuples and want to sort on a particular value
  • Thread-safety is not required
  • Optionally allow efficient haskey() lookups (I’m happy to maintain a separate hash-table for this though)

My thoughts at this stage are that I need a priority queue and a hash table, although I don’t know if I can quickly pop values off both ends of a priority queue. Another possibility is simply maintaining an OrderedDictionary and doing an insertion sort it every-time I add more data to it.

Because I’m interested in performance for a moderate number of items (I would estimate less than 200,000), I am unsure about what asymptotic performance I require for these operations. n will not grow infinitely, so a low constant performance k in k * O(n) may be as important O(n). That said, I would prefer that both the insert and pop operations take O(log n) time.

Furthermore, are there any particular implementations in Python? I would really like to avoid writing this code myself.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:04:44+00:00Added an answer on May 14, 2026 at 9:04 pm

    You might get good performance for these kinds of operations using blist or a database (such as the sqlite which is in the stdlib).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some data structure that I can build from standard collections or using
I just realized that I need to synchronize a significant amount of data collection
I need to implement a bag data structure using the interface java.util.Collection . I'm
I have the following function that prunes a tree data structure : public static
I'm looking for a data-structure, or combination of several, that can give me a
I need a collection that can lookup a value based on the key and
What is the need of Collection framework in Java since all the data operations(sorting/adding/deleting)
I need to populate a .net DataGridView from a collection physically (without data binding)
I need a collection of objects which can be looked up by a certain
I need a collection that behaves as Set and preserves order of element insertion.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.