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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:56:09+00:00 2026-06-03T03:56:09+00:00

I got this question for HW and I can’t figure out how to do

  • 0

I got this question for HW and I can’t figure out how to do it:
An array A[1…n] contains all the integers from 0 to n except one. The array is not sorted.
In this problem, we cannot access an entire integer in A with a single operation.
The elements of A are represented in binary, and the only operation we can use to access them is “fetch the jth bit of A[i]”, which takes constant time.

I have to find the missing integer in O(n) time.

The time it takes to do it mormally is O(NlgN)
(run on the N array, and fetch all the bits which are function of N – lgn bits).

How can I do it without reading all the bits?

  • 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-03T03:56:11+00:00Added an answer on June 3, 2026 at 3:56 am

    Let’s assume for now that n is 2^k – 1 for some k.

    Let’s also look at an example where k = 3.

    000
    001
    010
    011
    100
    101
    110
    111
    

    You’ll notice that when there is a full set, like the one shown above, each column (each digit’s place) has the same number of ones and zeros. Of course, for convenience we are showing this as sorted, but in reality, I am not stating that it is.

    Let’s take a look at the following list

    000
    001
    010
    011
    100
    110
    111
    

    We look at the first bit of all of the elements ( O(n) ) and figure out which count is less than the other.

    We see that for the first bit, there is a number with the 1 in the most significant bit missing. This means that we know that our number has a one in its most significant bit.

    Basically, we partition into two sets, one where the most significant bit is 1 and one where the most significant bit is 0. The smaller set shows us what bit the missing number has.

    We do the same thing on the smaller partition.

    Since it is O(n) + O(n/2) + O (n/4) … it is basically O (2n) which is O (n).

    EDIT

    For the general case, refer to the following document, bottom of page 1.

    Basically, it involves making use of the fact that when n is not a power of two, you can take into account the fact that given n, you know exactly how many should fall under the bit=1 partition and the bit=0 partition if this was a complete set.

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

Sidebar

Related Questions

I got this question for homework, and all I can think of is to
i have got this question to solve from one my friends. i have searched
I got this question from my cousin: What will be the best way to
Based on feedback I got from this question , I'm interested in using Lazy
I got this question in an interview and I was not able to solve
when trying to make this question, i got this one it is using Java,
I asked from few weeks ago this question: How can I teach a beginner
Got this question from algorithms design manual by Steven Skiena. It is required to
I got this question from this discussion . A method call like object.m does
Following on from this question , can someone explain the following in Scala: class

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.