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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:11:05+00:00 2026-05-14T06:11:05+00:00

Given a Range of numbers say 1 to 10,000, Input is in random order.

  • 0

Given a Range of numbers say 1 to 10,000, Input is in random order.
Constraint:
At any point only 1000 numbers can be loaded to memory.

Assumption:
Assuming unique numbers.

I propose the following efficient , “When-Required-sort Algorithm”.

We write the numbers into files which are designated to hold particular range of numbers. For example, File1 will have 0 – 999 , File2 will have 1000 – 1999 and so on in random order.

If a particular number which is say “2535” is being searched for then we know that the number is in the file3 (Binary search over range to find the file). Then file3 is loaded to memory and sorted using say Quick sort (which is optimized to add insertion sort when the array size is small ) and then we search the number in this sorted array using Binary search. And when search is done we write back the sorted file.

So in long run all the numbers will be sorted.

Please comment on this proposal.

  • 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-14T06:11:05+00:00Added an answer on May 14, 2026 at 6:11 am

    It’s called Bucket sort.

    Another approach when main memory is limited is to use Merge sort.

    The part of your design where you sort each bucket on demand may be better described as “on demand”, “just-in-time”, or “lazy”. Might as well reuse nomenclature people are already familiar with instead of inventing the term “When-required-sort”.

    Have you considered how to handle additional input? What happens if some of the buckets are already sorted, and then more numbers are added?

    I assume the end goal is to identify if a number is included in the set, rather than to produce a sorted list. If you do this frequently there is benefit to the initial overhead of sorting a bucket. If infrequently, a linear scan of the appropriate bucket may suffice.

    One more alternative. Bucket sort can be thought of as a simplistic hash table. The hash function is n/1000. Collisions are expected since there can be a large number of values hashed into each bucket (up to 1000). Instead of using on-demand sorting (and then binary search) to resolve collisions, you could use a more sophisticated hash and get O(1) search performance.

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

Sidebar

Related Questions

There is an array which can contain, say, upto 1000 elements. The range of
You are given 2^32-2 unique numbers that range from 1 to 2^32-1. It's impossible
In PHP, given the final string length the range of characters it can use
i want to generate a sequence of unique random numbers in the range of
Given a date range how to calculate the number of weekends partially or wholly
Trouble! I'm looking for a way to find the countries within a given range
I'm trying to calculate time blocks from given date range. Here's my attempt: <?php
So in Java, whenever an indexed range is given, the upper bound is almost
VBA is throwing the above given error on the line Sheets(Sheet1).Range(A & i).Copy Destination:=Sheets(Sheet2).Range(A
When I create a named range through the Name Manager, I'm given the option

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.