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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:32:39+00:00 2026-06-14T14:32:39+00:00

I have a Computer Science Midterm tomorrow and I need help determining the complexity

  • 0

I have a Computer Science Midterm tomorrow and I need help determining the complexity of these recursive functions. I know how to solve simple cases, but I am still trying to learn how to solve these harder cases. These were just a few of the example problems that I could not figure out. Any help would be much appreciated and would greatly help in my studies, thank you!

int recursiveFun1(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun1(n-1);
}

int recursiveFun2(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun2(n-5);
}

int recursiveFun3(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun3(n/5);
}

void recursiveFun4(int n, int m, int o)
{
    if (n <= 0)
    {
        printf("%d, %d\n",m, o);
    }
    else
    {
        recursiveFun4(n-1, m+1, o);
        recursiveFun4(n-1, m, o+1);
    }
}

int recursiveFun5(int n)
{
    for (i = 0; i < n; i += 2) {
        // do something
    }

    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun5(n-5);
}
  • 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-14T14:32:40+00:00Added an answer on June 14, 2026 at 2:32 pm

    The time complexity, in Big O notation, for each function:


    int recursiveFun1(int n)
    {
        if (n <= 0)
            return 1;
        else
            return 1 + recursiveFun1(n-1);
    }
    

    This function is being called recursively n times before reaching the base case so its O(n), often called linear.


    int recursiveFun2(int n)
    {
        if (n <= 0)
            return 1;
        else
            return 1 + recursiveFun2(n-5);
    }
    

    This function is called n-5 for each time, so we deduct five from n before calling the function, but n-5 is also O(n).
    (Actually called order of n/5 times. And, O(n/5) = O(n) ).


    int recursiveFun3(int n)
    {
        if (n <= 0)
            return 1;
        else
            return 1 + recursiveFun3(n/5);
    }
    

    This function is log(n) base 5, for every time we divide by 5
    before calling the function so its O(log(n))(base 5), often called logarithmic and most often Big O notation and complexity analysis uses base 2.


    void recursiveFun4(int n, int m, int o)
    {
        if (n <= 0)
        {
            printf("%d, %d\n",m, o);
        }
        else
        {
            recursiveFun4(n-1, m+1, o);
            recursiveFun4(n-1, m, o+1);
        }
    }
    

    Here, it’s O(2^n), or exponential, since each function call calls itself twice unless it has been recursed n times.


    
    int recursiveFun5(int n)
    {
        for (i = 0; i < n; i += 2) {
            // do something
        }
    
        if (n <= 0)
            return 1;
        else
            return 1 + recursiveFun5(n-5);
    }
    

    And here the for loop takes n/2 since we’re increasing by 2, and the recursion takes n/5 and since the for loop is called recursively, therefore, the time complexity is in

    (n/5) * (n/2) = n^2/10,

    due to Asymptotic behavior and worst-case scenario considerations or the upper bound that big O is striving for, we are only interested in the largest term so O(n^2).


    Good luck on your midterms 😉

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

Sidebar

Related Questions

I have just completed my graduation in computer science. Now I know about all
I am a layman to computer science, I have some questions about terminology of
I have to make a game in Java for my computer science class. Since
Scenario I have recently graduated from university with a degree in Computer Science. My
i've been programming for a while, but have never had a formal computer science
I only have one computer (running OS X), and need to test in both
i have a general question (taken from some computer science test) i'd like to
I am a student of Computer Science and have learned many of the basic
I am a newbie Computer Science high school student and I have trouble with
I'm a student of computer science and we have to use BaseX (a pure

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.