Ads Unit 1
Ads Unit 1
Ads Unit 1
.
• •
v/? ~-= ~~ -. ✓
I
l~~~ ~' t!:)~' ~
- • .~VM~.
\ ~ ~ ) ......] ~~
, . ~~ (~ct ~ ~~~(9,A
// . ~ ~ . ~ -~~-1\.,LL : • '
/9 W"'ClM \ . ~ , ~~ j~~oJt ~ -
·~ ~~1- ~-~~ w\u~ ~ ~~
Ji ~ ~ ~i~ & - ~ ·- :·'
'\,di ~ £JI,-. ,. ~
---=::==-~--~ . • . I ~ q\~
➔~~
J) ➔ ~""'---
'> A<t~::i ~~IYoAW~
(' c'--t\ V ~"\ tJ oQ..1-v r\)""t>uJ
,us
~ ~\J ~ o.tr?
-, J e._Q_Q (' t.. p..) (
C.7 ~
~ ~~;
l J\-; ~¢") rW
\. bo~ . tu<-'/, I
~ i,o~a -._,;-f
"-'-~ ~J,1'.) Q_ ~ \Ln) ~ ~\..,,) '"
) "·.... . . i ln) ~ A litn)) _ -
\ l 1\) ~ t_·ol") tm- all (\ 2:. n D cw.A ......
t >o
~ ~ VJ)~t,{) le): c~ ~) .
.~ i ~ ~ I\,.~ Clt.\L l> ~ ~
~ ~ \,t>~ ~~~u.wl o.J ~
~~ .. )
i ~#.),~ •l11) rv'"' ..
I"(\ ,, iln)~ ~CJ\))
• • I
C. ~ , 1 ln ) £. :1 { ln) ~ ~ ·c_~ • ~ ~)
CD 5\L-bs~-n,di~ ~ &
J; .., > v
!fvrwo..L.J. ~o.1d.
T(n) = T(n - 1) + n
... (3)
If n =1 then
T(l) = T(O) + 1
t.
= T (n - k) + (n - k + 1) + (n - k + 2) + ... + n
If k = n then
T(n) = 0 + 1 + 2 + ... + n
n(n+l) n2 n
T(n) = - - - = - + -
2 2 2
Again we can denote T(n) in terms of big oh notation as
T(n) e O (n 2 ).
-
\
,~~ f\AJUM L)
fb t \t\1- o}
I
°IY'J: . ,~"~?;
t it toss- 0) oou.l- LL" tibo9~eA~ "5nurn~ ,j
~Oj i°'t!v..i- t""oi f L-11 ! Y++)
ii Ln•~z l \I n"'s-~) '. I
·
t c_ou.k cc. t ~ b Lt) ~~ l\ LI
;
~\' ,) I
11
'
tJJ~ ~ .o;
.-e.tuM, l -£;b (p-1) +-iibln-~)))
..
j
Offlul- :~ I \
~ b-o .g ~ 9i ? ~ f>u : 0 \ l ~ 3
'
The Tree Method, also known as the Recursion-Tr ee Method, is a technique for solving
recurrence relations, which describe the time complexity of an algorithm in terms of its
subproblem s. This method involves representing the recurrence relation as a tree,
where each level of the tree corresponds to a recursive call and the nodes represent
the sizes of subproblem s. The cost associated with each recursive call is assigned to
• Construct a tree to represent the recursive calls of the algorithm. Each node in the
tree corresponds to a subproblem, and the edges represent the recursive calls.
• Det e rmine the cost assoo~ted with each level of the tree. The cost includes the work
done at each leve l, such as computations, comparisons, or other operations.
Example:
Consider the following recu rrence relati on for quicksort:
T (n ) == T(Icft partition) + T(right partition) I cost of p-armtioning
Recursion Tree:
LI Copycode
T (n)
I \
T( left) T( right)
I \ I \
T(left-left) T(left-right) T(rightaleft) T(right-right)
Costs:
current partition .
• The cost of partitio ning is typicall y 0( n ), where n is the size of the
cost is the sum of
• Each level in the tree corresp onds to a recursive call, and the total
the costs at each level.