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

  • Home
  • SEARCH
  • 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 1077363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:33:46+00:00 2026-05-16T21:33:46+00:00

In Programming Pearls (second edition) Column 5, problem 5 the question is about implementing

  • 0

In Programming Pearls (second edition) Column 5, problem 5 the question is about implementing binary search on an unsorted array.

How can you add partial checking to
the function at significantly less
than O(n-1) cost?

I know you can check with every iteration and achieve O(log n), but the hint in the back suggests there is an O(1) solution.

What is that solution?

  • 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-16T21:33:46+00:00Added an answer on May 16, 2026 at 9:33 pm

    Summary

    Partially checking if the array is sorted so that the binary search is applicable can be done in O(log n), as the OP said, and in O(1). The O(log n) method is to check each of the probes against the previous probe to make sure that it compares properly (less than, greater than). The O(1) method is to just check the final element found by binary search and one next to it so that if the sought-after element wasn’t found, at least the correct place for insertion was found. If the sought-after element was found, then that is a good O(1) partial check.

    Longer explanation

    The part of the problem before the code block says that a common problem is using binary search on an unsorted array. Basically, how can use partial checking to check if an array is sorted in less than O(n-1) cost?

    The O(log n) solution is to check each of the binary search probes meshes with respect to the previous probe (is less than or greater than it is expected to be). This doesn’t guarantee that the array is sorted, but it is a good partial check.

    The only O(1) check that I can think of is to check the final place that is searched such that its value and the neighboring values mesh with the idea of where the searched for element should be, even if the element wasn’t found. It’s a pretty good partial check: if the element is found then things are probably working correctly. If it wasn’t, then check the elements around where it should be that such that there is one less than the searched for element and then one that is greater than the searched for element. However, I do realize that checking in this manner means that the binary search, which is O(log n), has already been done so I don’t know if this is truly O(1). However, it only adds O(1) to the overall search so I think that it is applicable.

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

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm fairly certain the following line $url = $_GET['http://www.rememberthemilk.com/rss/test.reeher/15418678/?tok=eJwNzccJw0AQAMCKzmwO5VzYxQa ZPWP9R*Y8JoFVAph3Zs26GIXmEgHkp3VUNsqZ1aK436o0Dm4JykGjLt*9*uqetc1vp-… May 17, 2026 at 1:59 am
  • Editorial Team
    Editorial Team added an answer something like this: http://checkasm.booring.net/ ? May 17, 2026 at 1:59 am
  • Editorial Team
    Editorial Team added an answer Some BNF describing a context-free grammar is also describing a… May 17, 2026 at 1:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Programming Pearls in the column 2 (AHA! Algorithm) talks about how binary search aids
In Programming Pearls I have met the following problem. The question is this: print
i have question from programming pearls problem is following show how to use Lomuto's
From programming pearls, it is known that array[1...n] has heap property if for all
Page 120 of Programming Pearls 1st edition presents this algorithm for selecting M equally
I am studying More programming pearls (Addison-Wesley, 1988) by Bentley J. and am stumped
I am solving Programming Pearls exercises. 4.11 say: Write and prove the correctness of
here is code from programming pearls this code prints random numbers in decreasing form
Hey, in the Programming Pearls book, there is a source code for setting, clearing
I am solving this problem of rotating an array and got algorithm and code

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.