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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:51:32+00:00 2026-05-27T11:51:32+00:00

a data structure to store the start and endpoint of a range. rangename start

  • 0

a data structure to store the start and endpoint of a range.

rangename      start     end

range1          10        11

range2          20        22

range3          0         5

now if i have to find the range in which a number ‘x’ may exist.

What would be the efficient way of storing this in c++ ?

I’m trying to use map. but then search to find the range might be expensive ( which i’m not sure of). Suggest a good data structure.

I should be able to find whether the element is present in a range or not. The ranges should not be mix and matched and no adjacent or other bounds.

If I need to a find an element 3, it is present in range 3, But an element 12 is not present at all. Just looping through cannot be an efficient way.

  • 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-27T11:51:33+00:00Added an answer on May 27, 2026 at 11:51 am

    (I have changed this answer since the asker clarified that his ranges do not overlap.)

    If the set of ranges does not change, you can use a sorted vector and binary search, as suggested in ravenspoint’s answer.

    If the set of ranges changes over time, you might still use a sorted vector, or you might want to use a std::map. You need to try both and see which one is faster in that case.

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

Sidebar

Related Questions

I need to store a tree data structure in my database, for which I
A single data structure to store different types in a single variable. Not asking
What is the best data structure to store an oracle table that's about 140
I want to store a data structure thats a table with one column Strings
I'd like to pre-store a bunch of function calls in a data structure and
I have a data structure where an entity has times stored as an int
I have a staging database which stores the GEO location as the following structure
I have data stored in a HashMap, which I want to access via multiple
I have a file where a data structure containing 6 columns is stored side
One of the data structures in my current project requires that I store lists

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.