Question: 1 / 50

Given the function T(n) = T(n/2) + 1, what does this imply about its complexity?

Linear time complexity

Constant time complexity

Logarithmic time complexity

The function T(n) = T(n/2) + 1 describes a recurrence relation where the problem size reduces by half with each recursive call, and there is a constant amount of additional work done (which is the +1). This pattern is indicative of logarithmic growth. To analyze the complexity, we can apply the Master Theorem or simply observe the behavior of the recurrence. Starting with T(n), you can see: 1. At the initial step, we have T(n). 2. The next call is T(n/2), which adds a constant 1. 3. The following step would be T(n/4), adding another constant 1. 4. This process continues until n is reduced to 1. If we continue this pattern, each level of the recurrence contributes a constant amount of work, and we effectively halve the problem size at each step. The number of steps taken to reduce n to 1 will be logâ‚‚(n). Each of these steps contributes a constant amount of additional work. This results in the overall time complexity being proportional to the number of steps taken in the recurrence, which is log(n). Therefore, the function T(n) grows logarithmically with respect to n, leading to a logarith

Quadratic time complexity

Next

Report this question