The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
294 views

Solve the recurrence equations:

  • $T(n)= T( \frac{n}{2})+1$
  • $T(1)=1$
asked in Algorithms by Veteran (99.8k points) | 294 views

4 Answers

+4 votes
Best answer
$T(n) = T(n/2) + 1$

$=T(n/4) + 2$

$= T(n/8) + 3$

$\vdots$

$=T(n/{2^k}) + k.$

Recurrence stops when $2^k >= n$.

When $2^k = n,k = \lg n$

So, $T(n) = T(1) + \lg n \\= 1 + \lg n$

PS: Unless explicitly asked for asymptotic bound, we should give exact answers for solutions of recurrence equations.
answered by Veteran (355k points)
selected by
+1 vote
T(n)=T(n/2)+1

Using Master Theorem :

a=1,b=2,k=0,p=0

T(n)=O(logn)
answered by Active (2.9k points)
+1 vote

It is a standard Recurrence for Binary Search :
T(n) = T(n/2) + Θ(1).

T(n)=T(n/2k)+k
base case T(1)=1
k=logn
T(n)= logn+1
 

answered by Boss (11.5k points)
0 votes

T(n)=T(n2)+1
use master theorem we get answer as logn

answered by Boss (20.4k points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,980 questions
45,481 answers
131,420 comments
48,452 users