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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:21:26+00:00 2026-06-09T10:21:26+00:00

I am currently trying to get the values that are in the lowest half

  • 0

I am currently trying to get the values that are in the lowest half of an array of data. This array in unsorted at first.

From this:

{4,6,9,3,8,5}

To this :

{3,4,5,6,9,8} or {3,4,5}

An easy solution would be to sort the array (using quicksort) and then use only the values stored in the first half of the sorted array.
However, since quicksort and most efficient sorting algorithms will sort the entire array while I only need the first 50%, this seems like a waste of ressources. Note that performance is an issue in this project.

Knowing that a full sort is O(n log n) and that a sort that stops after it finds the lowest element is O(n), I can easily build a simple algorithm that will have a complexity of n/2 * n to find the lowest 50%. But is that really better than a full quicksort?

To be clear, what would be the best sort to use if we want only the lowest half of the values in an array?
If the 50% was smaller (like 1%), a sequential search of the lowest elements would of course be the fastest solution, but at what % does it become slower than a quicksort?

I am coding in C++ and using vectors, but this question should be pretty general.

  • 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-06-09T10:21:28+00:00Added an answer on June 9, 2026 at 10:21 am
    #include <algorithm>
    std::partial_sort(start, middle, end);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get the most popular productID from my MSSQL Database. This
I'm currently trying to convert xml values that represents two times. example: <from>960</from> <to>975</to>
i am currently trying to get data from a form in a view to
I'm currently trying to write data from an array of objects to a range
I am currently trying to get data out of a plist. It basically looks
I am currently having trouble getting a value from an AsyncTask that gets data
I need to get the values of all checkboxes that are currently checked using
I am currently trying to get RGB data for a texture image, while displaying
I'm trying to get a list of all the sockets/clients that are currently connected.
I am currently trying to insert data into a table called customer_quote , this

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.