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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:32:30+00:00 2026-05-23T08:32:30+00:00

I am finding a better logic to combine 2 vectors. vector_A[id][mark1]; vector_B[id][mark2]; vector_A: id

  • 0

I am finding a better logic to combine 2 vectors.

vector_A[id][mark1];
vector_B[id][mark2];

vector_A: id = [300 , 502, 401 , 900 , 800 ,700 , 250 , 001] 
          mark1 = [55 , 50 , 30 , 28 , 25 , 11 , 04 , 03]

vector_B: id = [800 , 005 , 502 , 925 ,025 ,300 , 52] 
          mark2 = [75, 60 , 50 ,35 , 30 , 25 , 04]

combination rule is If same id find in two vectors add mark1 and mark2. If not just display.

vector_combined: id = [800 , 300 , 502 , 005 , 925 , 401] 
                 mark_combine = [100, 80 , 100 , 60 , 35 ,30]

Please help me with a optimal 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-23T08:32:31+00:00Added an answer on May 23, 2026 at 8:32 am

    Here on SO we’re happy to assist people with hints for homework questions, provided they have been up-front about acknowledging the question as homework — as you have been 🙂

    As things are now, to find a match for a particular element in vector_A, you need to scan every element of vector_B. So if there are m elements in vector_A and n elements in vector_B, this will take O(mn) time to find all matches — quite slow.

    Suppose we sort these two vectors, and reorder mark1 and mark2 accordingly as well. What you now notice is that when looking for a particular element in vector_B, you can stop as soon as you get to an element that is too large — since you know that all later elements must be even larger. That will save some time.

    In fact you can go one step further and look at just the 1st element of vector_A and vector_B. Let’s call these a and b respectively. Now only one of 3 cases can occur:

    1. a < b. In this case, we can conclude that a cannot appear anywhere in vector_B, since all later elements will be at least as large as b, which is already too large.
    2. a > b. Similarly we can conclude that b cannot appear anywhere in vector_A, since all later elements will be at least as large as a, which is already too large.
    3. a = b. In that case, clearly this number appears in both vectors!

    Bearing in mind that sorting takes just O(nlog n) time, this should give you a big hint for a faster algorithm. If you need a bit more help understanding, leave a comment.

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

Sidebar

Related Questions

This question of mine (currently unanswered), drove me toward finding a better solution to
When finding the inverse square root of a double, is it better to clamp
I'm having trouble finding a better way to search MySQL for a pair of
I need your help in finding better way in downloading a url using HttpWebResponse
I am currently exploring Hibernate annotation and I am finding it better than having
How is Dijkstra algorithm better tham A* algorithm for finding shortest path?
I am trying to see if there is a better performing way of finding
In R, is there a better/simpler way than the following of finding the location
I´m having, in lack of better words, a hell of a time finding out
I've been interested in the problem of finding a better prime number recognizer for

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.