0% found this document useful (0 votes)
9 views5 pages

George's Midterm 1 Study Guide

Uploaded by

vrakkati
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)
9 views5 pages

George's Midterm 1 Study Guide

Uploaded by

vrakkati
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/ 5

Midterm 1

Guide
Study

by George

Recurrence Tree
D
+ Substitution + Master's
Given Tcnl =
27 T(5) + 53 Recurrence Tree D

problem with original size 'U ·


is broken into 27 subproblems
·
Each Subproblem is size
·
5h"work done at each level of recursion
level
Depth Level work per
N


O 543

i 2)

27 (5)
-
5(5)
=
= 27

729
·

:
5
5 =
543

543
umber of levels

Depth : Also known as


theheight of the tree The
.
recursion will
continue until the proble size becomes 1 (This is usually the base
case in Code like if IA 1 or
= if n 1) = =
,

: The
Work work/cost at each level is in

In this case : Tch) = Work at each level ·

Depth 5n (logn 1)
= ·
+

en
H is because for level O before recursion startsI
we are
accounting

TCH) simplifies to a O(logn)


You can also set it as a summation :
up
logn logn

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

2) Substitute this hypothesis into our


You
Recurrence=n
can use

instead

Tcn) S27c(blog(5) + 543 Now Simplify

Tcn) S27 · Clog() + 5n =


ch
>
log() + 5n3 10g, 3 1=

-
Tcn) < Ch (logn - 10gs) 543 + =
Chlogn-unlogs + 53
=
chlogn cr + 53 -

As 'n grows ,
chlogn dominates so Tch) Sch logn

But let's solve forC


OChlogn)
TIIE chlogn - cr + 53 = Chlogn + n3(5 c) -

Ensure that Tcu) Schlogh


5 -
(So
,
which

No =3
*
will

>
only
<25
hold

due to base of
true

loggh
if :


For C25 and
any n2lo the Recurrence Tcalschlogh holds.

Master's Theorem & I recommend using


this first ! Get Oc faster

T(n) =
27(b) + 5n3 nd us fen) add logn

a = 27

Calculated
b=

loga 3
What about Tch) =
Tch-11 + 3h ?

Recurrence Tree &

depth Level Work

n -
i= 1
ou 3h U

n i I 3(n 1) 3(n -i)


n
= -

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
- + = +

T (h) S (n2 + n(3 2C) -

+
L

dominates
On
Make sure n(3-2C) -3-2CSO
Because Cano exis
&ZSC Not so Tch = Ocas

Master's Theorem & Cannot USE Here !!!

Need to have a Recurrence in the form Tcul = aT(b) f(n) +

& =
# 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
,

* Show understanding of the


question explain solution approach
,

* Provide runtime analysis

If it helps , you can answer these


questions in
paragraph
format Show . us your understanding of the
question and concepts
to
get the solution .

some algorithms to know :

Majority of these HW
Merge Sort Merge problems
·
+ were

·
List all subsets of an
array list (Brute force)
·

finding smallest number in list A

of list
Finding sum elements

&
·
in

·
List all substrings given a
string
Binary Search · Divide &
Conquer ways to do these
·

MAYBE MaxSubarray if covered


·

You might also like