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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:42:29+00:00 2026-06-15T04:42:29+00:00

I’ve searched for other threads with a similar problem, but I couldn’t find any

  • 0

I’ve searched for other threads with a similar problem, but I couldn’t find any that apply to me.
If I have a variable which has some value, and an array that has a list of values… is it possible for me to efficiently (time efficient, space isn’t a constraint) find out the index of the array when the variable matches an element in the array?

I’m getting the variable from reading out of a massive file, and brute force iterating over every possibility will mean several million iterations. I’m willing to do that as a last resort, but I’d rather not. 🙂

I’m programming in C, if the algorithm depends on that. I don’t have an option to program in C++/Python.
Thanks!

Edit : The valued that I want to match with the array come in pairs (x,y). If the array matches with x or y, I further process (x,y). But it’s vital that the ordering not change if I have to sort it for example.

  • 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-15T04:42:29+00:00Added an answer on June 15, 2026 at 4:42 am

    If space isn’t a concern, and you want to know whether a value is contained in the array, you could do something like this:

    • First, create a new array. Let’s call the old one v[ ], the new one w[ ], and let i be your iterator through v[ ].

    • Now, make w[v[i]] = 1, and the rest of w[ ] = 0. This basically says “if x is a value in array v[ ], then w[x] = 1“. (Note: if you declare w[ ] globally, all of its positions will be initialized with 0, by default)

    • Whenever you want to check for a value contained in v[ ], check w[value] instead. If it equals 1, then the answer is yes.

    If you do many checks per array, this should work pretty well. Take note, though, that w[ ] could get pretty big, in size.

    Edit: if you want to also keep the index, you could replace the 1’s in w[ ] with actual positions – as long as the values do not repeat, this works well.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.