0% found this document useful (0 votes)
14 views11 pages

AAL4 Recurrences

The document discusses various algorithms and their time complexities, particularly focusing on recurrence relations and the Master Theorem. It provides examples of different cases for solving recurrences, including binary search and quicksort algorithms. The document also outlines conditions under which specific time complexity results are achieved, such as Θ(n log n) and Θ(n^2).

Uploaded by

engineeringengtr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

AAL4 Recurrences

The document discusses various algorithms and their time complexities, particularly focusing on recurrence relations and the Master Theorem. It provides examples of different cases for solving recurrences, including binary search and quicksort algorithms. The document also outlines conditions under which specific time complexity results are achieved, such as Θ(n log n) and Θ(n^2).

Uploaded by

engineeringengtr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

!

" # ! $
% & # '
' (! $
!
! % &
! )
) % & % *
)
' ' (! % !

! "

" +
Θ(1) if n = 1
T ( n) =
2T ( n / 2) + Θ( n) if n > 1

! ) %

, !* ! !

! '
, +!* !
% & #* *
% -.* ! ! ! $
1 if n = 1
T (n) =
2T ( n / 2) + n if n > 1
T(n) = 2 T(n / 2) + n // substitute
= 2 (2 T(n / 4)+n / 2) + n // expand
= 22 T(n / 4) + 2n // substitute
= 22 (2 T(n / 8)+n / 4) + 2n // expand
= 23 T(n / 23) + 3n // observe
= 2b T(n / 2b) + bn
= 2lgn T(n / n) + nlgn
= n + n lgn

, +!* ! !
/
& &
+!* !
012
+!* !
012
3
+ !% #4* $ '
!* ! 5 )
*! ! !
, +!* !
% % & *!
#* * % -.* $

2 if n = 1
T (n) =
2T ( n / 2) + 2 n + 3 if n > 1

T (n) = 5n + 2nlgn -3

2 if n = 1
T (n) =
2T ( n / 2) + 2 n + 3 if n > 1

T(n) = 2 T(n / 2) + 2n + 3
= 2 (2 T(n / 4)+n + 3) + 2n + 3
= 22 T(n / 4) + 4n + 2 . 3 + 3
= 22 T(n / 22) + 22n + 21 . 3 + 20.3
= 22 (2 T(n / 8)+n / 2 + 3) + 4n + 2.3 + 3
= 23(T(n/23)+2.3n + (22+21+20).3
b-1

= 2b T(n / 2b) + 2.bn + 3 2j


j=0

= n T(n / n) + 2nlgn + 3(2b-1)


= 2n + 2nlgn + 3n -3
= 5n + 2nlgn -3
! ,
!
% &
! ) % %
* !
T (n) = T ( n / 4) + T (n / 2) + n 2

!
& 2 ! ) %
% !
T (n) = aT ( n / b) + f (n)
≥6 * 7 68 ) 2 )
,# $ * % &
9
** !! 2 * !
% * ,# 9
*$
)# $ 2 * * !% * &
% % ' % T (n) = 2T (n / 2) + Θ(n)
*
! #.$

Problem logbn seviyesinde a parçaya


bölünür. a logb n = n logb a adet yaprak
vardır.

! #:$
;2 a logb n
= nlogb a
! ) % & %% &
!
T ( n) = f (n) + aT (n / b)
= f (n) + af (n / b) + a 2T (n / b 2 )
= f (n) + af (n / b) + a 2T (n / b 2 ) + ...
+ a logb n−1 f (n / blogb n−1 ) + a logb nT (1)
Thus,
Böylece
logb n −1
T ( n) = a j f (n / b j ) + Θ(nlogb a )
j =0

/ * 9* & # %
2 $
/ 6* nlogb a 2 *
% )
!
%!! T ( n) = aT ( n / b) + f (n)
< & 2 )
*
< & &
&
< & )
*
! ) % %
*
!! % f (n) O (nlogb a )
& &

! #=! ! 6$
T (n) = aT (n / b) + f (n)
f ( n) = O (n log b a −ε
) ε >0 %
)# $) ! nlogb a ) !
&*
# ! $ % $
! ' % &
log b a
2 O (n )
, 2 % & 2 Θ( nlogb a )
, % & 2 % &
& Θ( n logb a
)
! #=! ! .$
T ( n) = aT ( n / b) + f (n)
f (n) = Θ(nlogb a )

f (n) nlogb a 2

# ! %
! $ % !

T (n) = Θ(n logb a lg n)

! #=! ! :$
f (n) = Ω(n logb a +ε ) ε >0 %
6 !! !
log a
)# $ ) ! n b ) !
*
& & !! !
∃c < 1 and n0 > 0 such that af ( n / b) ≤ cf (n) ∀n > n0
# ! $$ % $
T (n) = Θ( f (n))
!"
> * ! ) % T (n) = aT (n / b) + f (n)
1. (
f (n) = O n logb a −ε )
(
T (n) = Θ n logb a )
2. (
f (n) = Θ n logb a )
(
T (n) = Θ n logb a lg n )
3. ( )
f (n) = Ω n logb a +ε and af (n / b) ≤ cf (n), for some c < 1, n > n0
T ( n ) = Θ ( f ( n) )

/
&
" 8*8 )# $ ! )

n logb a *
)# $ n logb a )
& &
!! ! !* !
! !
" # + $

T ( n) = 2T (n / 2) + Θ(n)
a = 2, b = 2; n logb a = n log2 2 = n = Θ(n)
Also f (n) = Θ(n)
( )
Case 2: T ( n) = Θ n logb a lg n = Θ ( n lg n )

"
Binary-search(A, p, r, s):
T (n) = T (n / 2) + 1 q←(p+r)/2
if A[q]=s then return q
a = 1, b = 2; n log2 1 = 1 else if A[q]>s then
Binary-search(A, p, q-1, s)
also f (n) = 1, f (n) = Θ(1) else Binary-search(A,
(A, q+1, r, s)

Case 2: T (n) = Θ(lg n)


T (n) = Θ(nlogb a lg n)
T (n) = 9T (n / 3) + n
a = 9, b = 3; Θ( nlogb a )
f (n) = n, f (n) = O (n log3 9−ε ) with ε = 1
Case 1: T (n) = Θ ( n 2 )
"
T (n) = 3T (n / 4) + n lg n
a = 3, b = 4; n log4 3 = n0.793
f (n) = n lg n, f (n) = Ω(nlog 4 3+ε ) with ε ≈ 0.2
Case 3:
Regularity condition
af (n / b) = 3(n / 4) lg(n / 4) ≤ (3 / 4)n lg n = cf (n) for c = 3 / 4
T (n) = Θ(n lg n)

T (n) = 2T (n / 2) + n lg n
a = 2, b = 2; nlog 2 2 = n1
f (n) = n lg n, f (n) = Ω(n1+ε ) with ε ?
also n lg n / n1 = lg n
neither Case 3 nor Case 2!

) "
?! 2 " % *
2 ) * @2 )
299
A: ! 9
A *9
A * *
Quicksort(A,p,r) Partition(A,p,r)
01 if p<r 01 x ← A[r]
02 then q←Partition(A,p,r) 02 i ← p-1
03 Quicksort(A,p,q) 03 j ← r+1
04 Quicksort(A, q+1, r) 04 while TRUE
05 repeat j←j-1
06 until A[j] ≤ x
07 repeat i←i+1
08 until A[i] ≥ x
09 if i < j
10 then exchange A[i]↔A[j]
11 else return j

You might also like