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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:13:02+00:00 2026-05-15T11:13:02+00:00

Is there an algorithm to split a sequence of random numbers into two groups

  • 0

Is there an algorithm to split a sequence of random numbers into two groups based on a median value determined on the fly(without sorting them)?

Ex. If I have the sequence 2-3-6-7-1-4-5, the result would be two separated groups:

A) 1 2 3

B) 5 6 7

Median value: 4

  • 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-15T11:13:03+00:00Added an answer on May 15, 2026 at 11:13 am

    Yes, this can be done in O(n).

    First of all, if we already knew the median, we could easily split the sequence in two in O(n) by iterating the sequence and comparing each value with the median. So how do we find the median in O(n)?

    The basic idea is to use quicksort, but instead of recursively sorting both sides of the pivot, only sort the half that contains the median (ie. the half that encompasses the index ⌈n/2⌉). If our selection of a pivot guarantees geometric convergence of quicksort (like median-of-medians does), then our overall algorithm will be O(n).

    Algorithm

    Let’s call the current size of our array k, and the reduction due to median-of-medians c – ie. our pivot guarantees the array shrinks by a factor of at least c each step

    1. Estimate the median of the array using median-of-medians – O(k)
    2. Partition the array quicksort-style (with the estimate as our pivot) – O(k)
    3. Choose the half of the array containing the median (index ⌈n/2⌉). This new sub-array will have size no greater than k/c. Repeat steps 1 & 2 recursively until we’ve determined the element whose position in the original array is ⌈n/2⌉.

    The asymptotic running time of this algorithm is

    2 O(n) + 2 O(n/c) + 2 O(n/c2) + 2 O(n/c3) + …
    = O(n)

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

Sidebar

Related Questions

Is there an algorithm to securely split a message into x parts requiring at
I was wondering if there is an algorithm to split a line into multiple
Is there a good algorithm to split a randomly generated number into three buckets,
Is there an efficient algorithm to split up a number into N subsections so
Is there an algorithm to estimate the median, mode, skewness, and/or kurtosis of set
Is there a preferred algorithm for converting a 2-digit year into a 4-digit year?
Is there any fast algorithm that allows to compare two files (for verification purpose)
Is there an algorithm for figuring out the following things? If the result of
Is there any algorithm in c# to singularize - pluralize a word (in english)
Is there any algorithm that gives the compass direction of a shadow given latitude,

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.