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 926547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:42:05+00:00 2026-05-15T19:42:05+00:00

I am looking for an efficient data structure to represent a priority list. Specifically

  • 0

I am looking for an efficient data structure to represent a priority list. Specifically I need to assign a priority to a set of items and return only the top scoring items. I have looked into priority queues which operate on heaps, but they don’t seem to really suit my needs. They will reorganize the heap structure as soon as I will poll the top rating item from the queue.

The simplest solution would of course be a linked list, which in the worst case would take quite long for the insertion operation.

Does anyone have a better solution?

  • 1 1 Answer
  • 0 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-15T19:42:06+00:00Added an answer on May 15, 2026 at 7:42 pm

    Heaps seem very suitable, and it seems like you are going about it wrongly.

    Say you wanted the top x elements (how does this x compare to n, btw?)

    What you are doing is putting all into a max-heap and getting the top x.

    I suggest instead, you use a min-heap of exactly x elements.

    First x elements you insert into heap.

    Next incoming element, you compare against the min which can be done very quickly (O(1) time) in the heap. If smaller, you just ignore the incoming element.

    If incoming element is larger than min, then you increase the min to the incoming element and sift it down in the heap. This should be logx time at worst.

    Once done (in nlogx time), you can retrieve the elements from the heap in sorted order in O(xlogx) time.

    Depending on how your data is (and how small x is), using this min-heap solution can be really fast.


    If you really really want the inserts to be super-fast and don’t care much about the retrieval then you can also do the following.

    Insert the elements into a vector (array with amortized O(1) insert time) in the order they come.

    The use the Selection algorithm to find the xth largest element (in O(n) time, but the constants might be big). Say that number is S.

    Now walk the array comparing each element with S and select the ones as large as S.

    If x is reasonably sized and comparable to n (like n/2 or something) this might work out fine, but if x is small compared to n, I would suggest go with the min-heap.

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

Sidebar

Ask A Question

Stats

  • Questions 540k
  • Answers 540k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try http://drupal.org/project/logging_alerts It will enable to you to send watchdog… May 17, 2026 at 2:40 am
  • Editorial Team
    Editorial Team added an answer A shared_ptr would work for sharing data. Its counter is… May 17, 2026 at 2:40 am
  • Editorial Team
    Editorial Team added an answer Boost is C++, not C (emphatically not C -- virtually… May 17, 2026 at 2:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am looking for an efficient data structure, that'll allow me to cue events
I have a structure called Patch that represents a 2D array of data. newtype
I have a set of N items, which are sets of integers, let's assume
I am looking for an efficient way to store users' information in a SQL
I'm looking to graph basic database data in a X Y axis graph. I
I am trying to compare two byte arrays in memory and produce a data
Possible Duplicates: Implementing a matrix, which is more efficient - using an Array of
This is similar to a recent question. I will be maintaining sorted a list
I need to read a large space-seperated text file and count the number of
I have a data class Student, and I have an aggregate class Students. Student

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.