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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:03:17+00:00 2026-05-26T16:03:17+00:00

The average length is 4 characters for the strings. I was thinking a binary

  • 0

The average length is 4 characters for the strings. I was thinking a binary search might be the fastest starting at position 4. Also I think an inlined templatized function might perform well. This is done in a very tight loop so performance is critical.

The data looks like:

"1234    "
"ABC     "
"A1235   "
"A1235kgo"
  • 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-26T16:03:18+00:00Added an answer on May 26, 2026 at 4:03 pm
    char* found = std::find(arr, arr+9, ' ');
    

    Note that ‘no match’ is signaled wuth the end iterator:

    bool match = (arr+9) != found;
    

    Note, that

    • binary search doesn’t apply unless you characters are in some known ordering.
    • std::find is inlined, templatized and will perform to the max if you turn on optimization (e.g. -O3 -march=native for g++)

    Edit since you have shown more code, I now realize you actually want to detect (sub)string length. You could use

    • std::string::find_first_of
    • std::string::find_last_of
    • std::string::find
    • std::string::rfind
      etc.

    Of course, that assumes you’d want to convert the char[] to std::string for the purpose. In practice, that might be a perfectly valid idea, because of SSO (Small String Optimization) found in nearly all implementations of the C++ standard library.
    (see Items 13-16 in Herb Sutter’s More Exceptional C++, or Scott Meyers’ discussion of commercial std::string implementations in Effective STL).

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

Sidebar

Related Questions

how would you sort n sorted lists with average length K in O(n*log K)
I have a text field that can be 30 characters in length, however it
According to the book I'm reading, interpolation search takes O(loglogn) in average case. The
I'm generating QR codes using strings that could very easily be longer in length
I am working with a large set (5-20 million) of String keys (average length
Randomized binary search trees like treap give a good performance (in the order of
I think the field type should be string of variable length (VARCHAR), but what
Let's suppose I need to perform some average-length (several days) refactoring. I create mybranch
On average, how long does it take for Debian to package new versions of
Any ideas what the average user's download speed is? I'm working on a site

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.