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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:56:19+00:00 2026-05-21T16:56:19+00:00

Finding intersection of two arrays can be done if you sort the 2 arrays

  • 0

Finding intersection of two arrays can be done if you sort the 2 arrays and then do a linear step through to record the common elements.
This would take O(nlogn) + O(nlogn) + O(n)

Alternatively, you could compare each element in the first array with each element in the second array and you would get a O(n^2) run-time complexity.

How can I prove the first approach is better than the second?

  • 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-21T16:56:20+00:00Added an answer on May 21, 2026 at 4:56 pm

    First of all, O(nlogn) + O(nlogn) + O(n) doesn’t make much sense, since O(f) is a set, not a number.

    What you mean is O(nlogn + nlogn + n), which can be shown to be equal to O(nlogn). Just look at what it means for a function f to belong to the set O(g):

    f is an element of O(g) iff there exists c>0 and x0 such that for all x>x0:

    |f(x)| <= c*|g(x)|

    By setting f=nlogn and g=nlogn+nlogn+n, it follows that f is in O(g), and hence that O(nlogn) == O(nlogn + nlogn + n).

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

Sidebar

Related Questions

I can find plenty formulas for finding the distance between two skew lines. I
Possible Duplicate: Python: Finding corresponding indices for an intersection of two lists I have
I have written a code for finding intersection of two multimap which will compare
I am working on a geometry problem that requires finding the intersection of two
I am having a problem finding all overlapping ranges in two lists efficiently. This
I can't imagine that this is a new problem, but I'm not finding any
I read Python Cookbook and see what in a recipe Finding the Intersection of
I am having trouble finding an answer to this. Consider the clipping code below:
I'm finding many articles on the web where it is implied that you can
I'm having trouble finding a way to do this in a way that doesn't

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.