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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:30:42+00:00 2026-06-10T23:30:42+00:00

I am reading book on programming pearls. Question: Given a sequential file that contains

  • 0

I am reading book on programming pearls.

Question: Given a sequential file that contains at most four billion
32 bit integers in random order, find a 32-bit integer that isn’t in
the file (and there must be at least one missing). This problem has to
be solved if we have a few hundred bytes of main memory and several
sequential files.

Solution: To set this up as a binary search we have to define a range,
a representation for the elements within the range, and a probing
method to determine which half of a range holds the missing integer.
How do we do this?

We’ll use as the range a sequence of integers known to contain atleast
one missing element, and we’ll represent the range by a file
containing all the integers in it. The insight is that we can probe a
range by counting the elements above and below its midpoint: either
the upper or the lower range has atmost half elements in the total
range. Because the total range has a missing element, the smaller half
must also have a mising element. These are most ingredients of a
binary search algorithm for above problem.

Above text is copy right of Jon Bently from programming pearls book.

Some info is provided at following link

"Programming Pearls" binary search help

How do we search by passes using binary search and also not followed with the example given in above link? Please help me understand logic with just 5 integers rather than million integers to understand logic.

  • 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-10T23:30:43+00:00Added an answer on June 10, 2026 at 11:30 pm

    Why don’t you re-read the answer in the post "Programming Pearls" binary search help. It explains the process on 5 integers as you ask.
    The idea is that you parse each list and break it into 2 (this is where binary part comes from) separate lists based on the value in the first bit.

    I.e. showing binary representation of actual numbers
    Original List “”: 001, 010, 110, 000, 100, 011, 101 => (broken into)
    (we remove the first bit and append it to the “name” of the new list)
    To form each of the bellow lists we took values starting with [0 or 1] from the list above
    List “0“: 01, 10, 00, 11 (is formed from subset 001, 010, 000, 011 of List “” by removing the first bit and appending it to the “name” of the new list)
    List “1“: 10, 00, 01 (is formed from subset 110, 100, 101 of List “” by removing the first bit and appending it to the “name” of the new list)

    Now take one of the resulting lists in turn and repeat the process:
    List “0” becomes your original list and you break it into
    List “0***0**” and
    List “0***1**” (the bold numbers are again the 1 [remaining] bit of the numbers in the list being broken)

    Carry on until you end up with the empty list(s).

    EDIT
    Process step by step:
    List “”: 001, 010, 110, 000, 100, 011, 101 =>
    List “0”: 01, 10, 00, 11 (from subset 001, 010, 000, 011 of the List “”) =>
    List “00”: 1, 0 (from subset 01, 00 of the List “0”) =>
    List “000”: 0 [final result] (from subset 0 of the List “00”)
    List “001”: 1 [final result] (from subset 1 of the List “00”)
    List “01”: 0, 1 (from subset 10, 11 of the List “0”) =>
    List “010”: 0 [final result] (from subset 0 of the List “01”)
    List “011”: 1 [final result] (from subset 1 of the List “01”)
    List “1”: 10, 00, 01 (from subset 110, 100, 101 of the List “”) =>
    List “10”: 0, 1 (from subset 00, 01 of the List “1”) =>
    List “100”: 0 [final result] (from subset 0 of the List “10”)
    List “101”: 1 [final result] (from subset 1 of the List “10”)
    List “11”: 0 (from subset 10 of the List “1”) =>
    List “110”: 0 [final result] (from subset 0 of the List “11”)
    List “111”: absent [final result] (from subset EMPTY of the List “11”)

    The positive of this method is that it will allow you to find ANY number of missing numbers in the set – i.e. if more than one is missing.

    P.S. AFAIR for 1 single missing number out of the complete range there is even more elegant solution of XOR all numbers.

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

Sidebar

Related Questions

From reading parts of the Programming in Scala book, I realize that Scala can
Well, reading a bit old book (The C programming language, second edition, by Dennis
I'm reading a book about parallel programming an it says that it's not thread
I'm reading a book - Big Nerd Ranch iOS Programming. It says that dot
Hi, guys! Currently I'm reading a book Programming in Objective-C by Stephen Kochan. Actually
im currently reading a book about programming Android and there is a nice little
I'm reading a book on scala programming (the Programming in Scala), and I've got
I have been reading from the book The C Programming Language learning C, and
I'm pretty new to web programming, reading a book on ASP.NET, and I notice
I'm new to Java but not to programming. I'm reading the book Beginning Android

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.