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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:47:04+00:00 2026-05-17T20:47:04+00:00

I am trying to be familiar with the complexity evaluation of algorithms. In general

  • 0

I am trying to be familiar with the complexity evaluation of algorithms. In general I think that is a good/elegant practice, but in the specific I need it to express time complexity of my C++ code.

I have a small doubt. Suppose I have an algorithm that just reads data from the beginning of a std::vector until the end; then it does the same starting from the end to beginning (so are 2 cycles for indexes “From 0 To N” followed by “From N To 0”).

  • I said to myself that the complexity for this stuff is O(2N): is this correct?
  • Once I reached the beginning, suppose that I want to start reading again all data from beginning to the end (passing in total 3 times the vector): is the complexity O(3N)?

It is maybe a stupid doubt, but I would like to have someone opinion anyway about my thinking process.

  • 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-17T20:47:04+00:00Added an answer on May 17, 2026 at 8:47 pm

    Big-O notation simply means:

    f(n) = O( g(n) ) if and only if f(n) / g(n) does not grow to infinity as n increases

    What you have to do is count the number of operations you’re performing, which is f(n), and then find a function g(n) that increases at least as fast as f.

    In your example of going one way and then back, the number of operations is f(n) = 2n because each element is read twice, so, you can choose g(n) = n. Since f(n) / g(n) = 2n / n = 2 obviously does not grow to infinity (it’s a constant), you have an O(n) algorithm.

    It’s also an O(2n) algorithm, of course : since the “grow to infinity” property does not change when you multiply g(n) by a constant, any O( g(n) ) is also by definition an O( C g(n) ) algorithm for any constant C.

    And it’s also an O(n²) algorithm, because 2n / n² = 2 / n decreases towards zero. Big-O notation only provides an upper bound on the complexity.

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

Sidebar

Related Questions

I'm trying to get familiar with CSS but some of things that are happening
I'm not that familiar with Flask/SQLite but I'm trying to insert several items into
I'm not too familiar with networking in JAVA but what i'm basically trying to
I'm trying to optimize the performance of my code, but I'm not familiar with
I'm trying to convert the following jquery to javascript syntax, but being not familiar
I'm familiar with SQL but not Crystal Reports. I'm trying to deal with an
I'm trying to install django file picker, but for whatever reason, it appears that
I'm pretty familiar with PHP, Javascript, etc but I'm new to Powershell. I'm trying
I'm getting trying to get familiar with Zend and have a question that's probably
I'm familiar with RichFaces, but relatively new to Primefaces and trying to implement a

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.