George's Midterm 1 Study Guide
George's Midterm 1 Study Guide
Guide
Study
by George
③
Recurrence Tree
D
+ Substitution + Master's
Given Tcnl =
27 T(5) + 53 Recurrence Tree D
↓
O 543
i 2)
27 (5)
-
5(5)
=
= 27
729
·
:
5
5 =
543
543
umber of levels
: The
Work work/cost at each level is in
Depth 5n (logn 1)
= ·
+
en
H is because for level O before recursion startsI
we are
accounting
5
5431
5430 logand
- =
=1
n is a constant here T =
1 n
using[ O(nPlog n)
=
,
· From Recurrence
,
we know Tcl =
Ochlogh) Substitution &
·
Use induction to prove -
1) Assume TCn)sCologn for some constant C
instead
-
Tcn) < Ch (logn - 10gs) 543 + =
Chlogn-unlogs + 53
=
chlogn cr + 53 -
As 'n grows ,
chlogn dominates so Tch) Sch logn
No =3
*
will
>
only
<25
hold
due to base of
true
loggh
if :
↑
For C25 and
any n2lo the Recurrence Tcalschlogh holds.
T(n) =
27(b) + 5n3 nd us fen) add logn
a = 27
Calculated
b=
loga 3
What about Tch) =
Tch-11 + 3h ?
n -
i= 1
ou 3h U
i= 1
Continues until the
base is reached 2 n 2 3(n 2) -
n
31
case
-
at 1 h times
,
d 3 (n-i)
Substitution &
↓ ↓
Prove Tcn) Ocu2)
3423 (n +
·
=
using Induction 0
Assume Con2
.
·
Tch) S
32 -
3
Substitute TCn)SCo(n-1 + 3n
342 (1 -
2) + E
Tch)3co(h2 2n 1) + 3 Ch2-2Ch#C
+whatic
- + = +
+
L
dominates
On
Make sure n(3-2C) -3-2CSO
Because Cano exis
&ZSC Not so Tch = Ocas
& =
# subproblems befactor of problem size reduction ful : work per call
·
Problem needs to be reduced LOGARITHMICALLY NOT LINEAR !
,
-
change in Depth
For Pseudo code :
focus
·
on clarity &
simplicity
·
use clear a
descriptive variables
·
stick to universal constructs like if, else, for, while return
,
State
inputs and
outputs
·
·
Aim for readability basic programming concepts
,
Majority of these HW
Merge Sort Merge problems
·
+ were
·
List all subsets of an
array list (Brute force)
·
of list
Finding sum elements
&
·
in
·
List all substrings given a
string
Binary Search · Divide &
Conquer ways to do these
·