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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:20:23+00:00 2026-06-04T05:20:23+00:00

I am reading Section 9.3 of Jon Bentley’s Programming Pearls, 2nd Edition. On page

  • 0

I am reading Section 9.3 of Jon Bentley’s Programming Pearls, 2nd Edition.

On page 94, Jon gave an implementation of an improved binary search algorithm, utilizing the fact that n is 1000 (search 1000 numbers to find the target).

At the end of the program, it is:

if p > 1000 || x[p] != t
    p = -1

My question is that, what if p is exactly 1000? It seems like the when p is 1000, it should also error out, like:

if p >= 1000 || x[p] != t
    p = -1

Anyway, this part of code is translated from the code on page 93, at the end of wich:

if p >= n || x[p] != t
    p = -1

Is my understanding correct? I am just wondering if this is a typo, or it is really not necessary to include the case p is 1000 in the condtion.

Another question is, in lines 5~6 from bottom up on page 94, it says: When the first test fails and l stays zero, the program computes the bits of p in order, most significant bit first.

What does it mean here? And when the first test fails, shoudn’t l be -1, rather than 0?

Anyone can elaborate on this statement?

P.S. I can’t find Jon’s email address, otherwise, I’ll field these questions to him. 🙁

  • 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-04T05:20:24+00:00Added an answer on June 4, 2026 at 5:20 am

    It is typo. Maxvalue of l is 999 (1000 – 512 + 256 + .. + 1, ), so maxvalue of p = l+1 is 1000. It is clear for hardcoded version of binsearch (listing 9.8).

    And we can see real C code (not pseudocode) here (Alg.4) with if (p >= n ||

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

Sidebar

Related Questions

So I started reading Jon Skeet's 2nd edition of C# in depth and kind
Reading the MCIMX50 Application Processor Reference Manuals on page 1368 (Section 33.3) there is
Recently, while reading a Socket Programming HOWTO the following section jumped out at me:
I am reading through Jon Skeet's C# in Depth, first edition (which is a
I'm reading the book Real-world functional programming by Tomas Petricek and Jon Skeet and
I'm reading through the Source Making site, specifically the Refactoring section. On the page
Today I was doing some leisurely reading and stumbled upon Section 5.8 (on page
i am reading section about A Binary Recursive Gcd Algorithm,where this definition is given
I was reading the design patterns page on Wikipedia, particularly the Criticism section. Could
I was recently reading Stroustrups The C++ Programming Language and in the section about

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.