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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:17:44+00:00 2026-06-05T01:17:44+00:00

I am trying to test what I know about BigO not very confident not

  • 0

I am trying to test what I know about BigO not very confident not totally illiterate either but please guide.

This is not a home work , I am not a student any where but interested in understanding this and various other related concepts.

//What is bigO of this Application ?
public class SimpleBigOTest {

    // What is BigO of this method -> I am certain it is O(n) but just checking
    private void useItirativeApprachToPrintNto0(int n) {
        for (int i = 0; i < n; i++) {
            System.out.println("useItirativeApprachToPrintNto0: " + i);
        }
    }

    // What is BigO of this method -> I am reasonabily certain it is O(n)
    private void useRecurrsiveApprachToPrintNto0(int n) {
        if (n != 0) {
            System.out.println("useRecurrsiveApprachToPrintNto0: " + n);
            useRecurrsiveApprachToPrintNto0(n - 1);
        }

    }

    // What is BigO of this method -> I think now it is O(n^2)
    private void mutltipleLinearItirationsDependentOnValueOfN(int n) {
        int localCounter = n + n;
        for (int i = 0; i < localCounter; i++) {
            System.out.println("mutltipleLinearItirationsDependentOnValueOfN: "
                    + i);
        }
        for (int i = 0; i < n; i++) {
            System.out.println("mutltipleLinearItirationsDependentOnValueOfN: "
                    + i);
        }
    }

    // What is BigO of this method -> I think this is again O(n)
    private void mutltipleLinearItirationsNotDependentOnValueOfN(int n, int j) {
        int localCounter = j;
        for (int i = 0; i < localCounter; i++) {
            System.out
                    .println("mutltipleLinearItirationsNotDependentOnValueOfN: "
                            + i);
        }
        for (int i = 0; i < n; i++) {
            System.out
                    .println("mutltipleLinearItirationsNotDependentOnValueOfN: "
                            + i);
        }
    }

    // What is bigO of this main -> I would say O(n^2) because
    // mutltipleLinearItirationsDependentOnValueOfN has biggest BigO of O(n^2)
    // if I am correct
    public static void main(String[] args) {
        SimpleBigOTest test = new SimpleBigOTest();
        int n = 1000;
        int j = 1234;
        test.useItirativeApprachToPrintNto0(n);

        test.useRecurrsiveApprachToPrintNto0(n);

        test.mutltipleLinearItirationsDependentOnValueOfN(n);

        test.mutltipleLinearItirationsNotDependentOnValueOfN(n, j);

    }

}

As a side question why do all the books on Algorithms speak so highly of Recursion where as in my practical experience I have always used iteration. Using Recursion we can run out memory quickly and nightmare to debug.

  • 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-05T01:17:48+00:00Added an answer on June 5, 2026 at 1:17 am

    Your answers to the first two are correct.

    Your answer to the third function is incorrect; this is also O(N). The reason is that the first loop iterates 2N times, and the second loop iterates N times. This is a total of 3N iterations, and 3N = O(N) because big-O ignores constant factors.

    Your answer to the fourth function is also incorrect; this is O(N + J). It is possible to have a function’s runtime dependent on multiple parameters, and that is the case here. Greatly increasing N or J will cause the runtime to depend on that parameter more than the other. Many important algorithms like Dijkstra’s algorithm, the KMP string matching algorithm, etc. have runtimes that depend on multiple parameters. Some algorithms have runtimes that depend on the value they produce (these are sometimes called output-sensitive algorithms). It’s good to keep this in mind when analyzing or designing algorithms.

    Finally, the complexity of main is O(1) because you are calling all four functions with fixed values for the arguments. Since the program always does exactly the same amount of work (some constant). If you allow n and j to vary with the command-line arguments, then the runtime would be O(n + j), but since they’re fixed the complexity is O(1).

    As a final note, I’d suggest not dismissing recursion so quickly. Recursion is an extremely useful technique for designing algorithms, and many recursive algorithms (quicksort, mergesort, etc.) use little stack space and are quite practical. Thinking recursively often helps you design iterative algorithms by allowing you to think about the structure of the problem in a different way. Plus, many major data structures (linked lists, trees, tries, etc.) are defined recursively, and understanding their recursive structure will help you write algorithms that operate over them. Trust me, it’s a good skill to have! 🙂

    Hope this helps!

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

Sidebar

Related Questions

I really know very little about regex's. I'm trying to test a password validation.
just trying to test for equality in this piece of code, but getting a
I was trying to learn unit test with PHP. I know it's a bit
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I'm trying to test some mailers with rspec but deliveries are always empty. Here
I am trying to test a sinatra app using minitest and capybara but get
I don't really know much about the internals of compiler and JIT optimizations, but
My need is to implement following graph I know about stacked chart , but
Sorry for asking a question about something I don't know much about, but I've
I am trying to study for a test where I have to know something

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.