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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:27:02+00:00 2026-06-16T19:27:02+00:00

My sincere apologies for such a naive question. I know this is simple. But

  • 0

My sincere apologies for such a naive question. I know this is simple. But nothing comes to my mind now.

I am using C++. I’m a bit concerned about efficiency since this is targeted for an embedded hardware with very less processing power and RAM.

I have 2 integer arrays with 50 members local to a function. I need to determine what is the corresponding number in the second array when an element in the first array is specified and vice versa. I have the information that the element provided to me for look-up belongs to which array i.e. array 1 or array 2.

Ex : Array1 => 500 200 1000 300 .....

 Array2 => 250 170 500  400 .....

Input 500 , Output will be 250

Input 400 , Output will be 300

input 200 , Output will be 170 and so on

I think an array look-up will be least efficient. Is stl::map the best option or do i have to look for any efficient search algorithms? I would like to know if you have to do this, which option you will be choosing.

Any thoughts?

  • 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-16T19:27:04+00:00Added an answer on June 16, 2026 at 7:27 pm

    You can use std::map for readability and a little efficiency as well, though in your case efficiency is of small matter

    std::map<int,int> mapping;
    .... //populate 
    cout <<mapping[200]; //170
    

    This is only 1 way (Array 1 -> Array 2) though. Im not sure if any easier way to do the other way, but create a second map.

    To support reverse lookup, or going from (Array 2 -> Array 1), Reverse map lookup suggests using Boost.Bimap

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

Sidebar

Related Questions

My sincere apologies if this question has been asked, but I really couldn't find
I hope this question (or one similar) hasn't been asked before. Sincere apologies if
EDIT: My sincere apologies! This wasn't an issue with anything but myself - I
First up, this might be the wrong place to ask this question.. So, sincere
This question is in relation to a question I posted yesterday. The link -http://stackoverflow.com/questions/12636348/how-to-add-a-different-class-to-the-same-class-in-jquery
With sincere help from experts in this wonderful forum, I have been able to
im using hibernate xml to map my databse, but i didn't knew how to
I can't seem to re-use a Net::FTP object after using quit. Is this expected?
I am being asked to create a table using javascript that displays simple arithmetic
I am using ggplot2 to chart bunch of items in one chart. Sincere there

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.