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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:11:26+00:00 2026-05-26T04:11:26+00:00

Here is my function. It is a simple one, I’m just not confident on

  • 0

Here is my function. It is a simple one, I’m just not confident on what the answer is.

  int calcul( int n) {
    if(n=1)
      return 1;
    else
      return calcul(n/2) + 1;
  }

Now, to get the complexity, I do:

T(n) = T(n/2) + O(1)

T(n/2) = T(n/4) + O(1)

…

T(1) = O(1)

Now, adding the equations, I’m getting

T(n) = O(1) + O(1)…

so what is the final answer ?

  • 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-26T04:11:26+00:00Added an answer on May 26, 2026 at 4:11 am

    You’re executing the function once for each time you can divide n by 2, which is log n times.

    So you get O(log n).

    Edit:

    The logarithm (of base 2) of a number n is the power 2 has to be raised to get n.

    That is, 2^(log n) = n, where ^ indicated exponentiation.

    Now, a simple way to calculate an approximation of log n is divide n by 2 while n > 1.

    If you’ve divided k times, you get n < 2^k.

    Since k - 1 divisions still yielded n > 1, you also have n >= 2^(k-1).

    Taking logarithms on each member of 2^(k - 1) <= n < 2^k, you get k - 1 <= log n < k.

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

Sidebar

Related Questions

Here is a simple function that converts a string to an integer. int str2int(char
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
What is the function of the namespace here? I would think in this simple
I'm trying to simply prove here that this simple function isn't good enough to
I have a simple Delete function to drop scheduled events. Here's the function: def
I have a simple question related to one-line programming. First an example: function test(a)
I created a simple function to get first and last day of a week
I have two functions, one function calling the other. Below is a simple analogy
This is a very simple function if one where to use an input tag,
here is some sample javascript: SomeObjectType = function() { } SomeObjectType.prototype = { field1:

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.