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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:32:09+00:00 2026-06-13T08:32:09+00:00

Here I come again with basic questions :( If I have the next pseudo-code:

  • 0

Here I come again with basic questions 🙁

If I have the next pseudo-code:

iterate over set (A)
    //some *O(1)* operations

iterate over set (B)
    //another *O(1)* operations

From what I have learned, the time would be O(numberOfElementsInA + numberOfElementsInB)

However, If I know that B is subset of A and numberOfElementsInA is always greater or equal than
numberOfElementsInB, can I simplify the time by writing just O(numberOfElementsInA) ?

  • 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-13T08:32:10+00:00Added an answer on June 13, 2026 at 8:32 am

    Yes, you are correct.

    This is because numberOfElementsInA + numberOfElementsInB <= 2 * numberOfElementsInA, and from definition of big O notation it makes it O(numberOfElementsInA) (with c=2, and for every N)


    EDIT: To be exact, each loop is O(numberOfElementsInSet_i) – thus there are constants c_i, N_i for each loop such that T(loop_i) <= numberOfElementsInSet_i * c_i for each numberOfElementsInSet_i > N_i.

    Thus:

    for each numberOfElementsInSet_1 > max{N1,N2}:
    T(loop_1) + T(loop_2) <= numberOfElementsInSet_1 * c_1 + numberOfElementsInSet_2 * c_2
    <= numberOfElementsInSet_1 * c_1 + numberOfElementsInSet_1 * c_2 //set1 is bigger
    <= 2 * numberOfElementsInSet_1 * max{c_1,c_2}
    

    And now we have a formal proof that the loops together are also O(numberOfElementsInSet_1) with N = max{N1,N2} and c = max{c_1,c_2} * 2

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

Sidebar

Related Questions

I have another problem, and because the reply is to fast here i come
Hi Masters Of Web Programming, here I come with another stupid question, hoping someone
I happen to come across a Java code at my work place. Here's the
After quite a long time perusing the web i have decided to come here
I come again with my inabilities to comprehend javascript. I have a draggable library
Hello pros I come here once again for help with php programming. I am
This is a weird one, but... We have this code: jQuery(function($) { $('#basic-modal .basic').click(function(e)
after quite a googling without a luck I come here again to bother you
I've come here for help with a complicated query. I've tried a lot of
I figured when I started getting stack overflow it was time to come here

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.