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

  • Home
  • SEARCH
  • 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 5940061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:54:57+00:00 2026-05-22T15:54:57+00:00

Possible Duplicate: How to find the kth largest element in an unsorted array of

  • 0

Possible Duplicate:
How to find the kth largest element in an unsorted array of length n in O(n)?

I’m currently sitting in front of an course assignment.
The task is to find the nth-smallest element in an array. (Without sorting it!)

I tried to understand the BFPRT algorithm but from what I got it is only useful if you want to calculate the median and not the “n-th smallest” element.

Another idea I had, was to convert the array into a tree by attaching smaller/bigger nodes to the left/right of the root node. I’m not sure however if this counts as sorting.
To accelerate this I could store the number of subnodes in each node.

The complete assignment also includes that the algorithm has to be recursive.
There is also the hint to think about other data structures.

What do you think about my idea of transforming the array into a balanced tree?

Are there any other options I might have missed?

EDIT: I looked at various similar questions but were not able to completely understand the answers/apply them to my specific task.

  • 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-22T15:54:58+00:00Added an answer on May 22, 2026 at 3:54 pm

    The traditional approach to this problem (the order statistic problem) is reminiscent of quicksort. Let’s say that you are looking for the k‘th smallest element. Pick a (random) pivot element and partition the remaining elements into two groups (without sorting the two groups): L contains all elements that are smaller than or equal to the pivot element (except the pivot element itself), and G contains all elements that are greater than the pivot element. How large is L? If it contains exactly k – 1 elements, then the pivot element must be the k‘th smallest element, and you are done. If L contains more than k – 1 elements, then the k‘th smallest element must be in L; otherwise, it is in G. Now, apply the same algorithm to either L or G (if you need to use G, you must adjust k since you are no longer looking for the k‘th smallest element of G, but the k‘th smallest element overall).

    This algorithm runs in expected O(n) time; however, there exists a clever modification of the algorithm that guarantees O(n) time in worst case.

    Edit: As @Ishtar points out, the “clever modification” is the BFPRT algorithm. Its core idea is to make sure that you never select a bad pivot element, such that the two partitions L and G do not become too unbalanced. As long as one can guarantee that one partition will never be more than c times larger than the other (for some arbitrary, but fixed c), the run time will be O(n).

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

Sidebar

Related Questions

Possible Duplicate: How do I find out which DOM element has the focus? Is
Possible Duplicate: Where do I find the current C or C++ standard documents? I
Possible Duplicate: How can I find the method that called the current method? I
Possible Duplicate: C#/.NET analysis tool to find race conditions/deadlocks I am debugging an application
Possible Duplicate: Model.find(1) gives ActiveRecord error when id 1 does not exist If there
Possible Duplicate: How to find out if a .NET assembly was compiled with the
Possible Duplicate: how to find leap year? What will be the exact definition of
Possible Duplicate: Anyone else find naming classes and methods one of the most difficult
Possible Duplicate: How do you find all subclasses of a given class in Java?
Possible Duplicate: How can I find the method that called the current method? Hi,

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.