CS170 Final Cheat Sheet, Study notes of Computer Science

Cheat sheet for CS170 covering main topics of class

Typology: Study notes

2024/2025

Uploaded on 12/10/2025

tamnhi-vu
tamnhi-vu 🇺🇸

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Non-MST
Ed
ge
Discount
path
:
Devise
a
0
(IvI)-time
als
for
consider
a
directed
graph
the
following
prob
lem
:
G
=
(V
,
E)
w/
pos
.
weights
((i
,
i)
Input
:
Graph
G
=
(V
,
E)
w/
distinct
on
its
edges
.
Given
a
path
=
vo-
edges
weights
Wi;
for
edge
V
,
...
->
UK
,
the
discounted
cost
(i
,
i)
=
E
.
of
the
path
is
the
sum
of
Solution
:
Find
some
edge
lengths
of
all
but
the
longest
edge
.
(i
,
i)
EE
S
.
E
.
Li
,
j)
is
Not
part
Formally
,
Of
any
MST
.
k
-
1
1)
Give
a
succinct
and
precise
cost(p)
=
((Vi
,
vi
+
1)
-
maxc(Vi
,
vit)
description
of
the
9l9
.:
(It
is
the
sum
of
cost
of
all
edges
The
idea
is
to
find
the
minus
maximum
costed
ge(
heaviest
edge
in
some
cycle
Devise
an
alg
,
to
compute
the
smallest
of
the
graph
.
Run
DFS
on
discounted
cost
path
from
a
vertex
the
graph
until
we
s
to
vertext
Give
a
succinct
and
encounter
a
back
edge
U-V
,
Precise
descr
.
of
your
alg
.
Proof
of
discovering
a
cycle
.
We
will
correctness
and
run-time
analysis
find
the
heaviest
edge
are
not
necessary
.
The
runtime
of
Cycle
and
return
it
.
This
Your
alg
.
Should
be
o((IVI
+
1E1)
10g
(v))
.
the
heaviest
edge
,
Check
Minimizing
the
discounted
cost
of
all
edges
along
the
path
a
path
is
the
same
as
minimizing
~
to u
in
the
tree
.
This
the
cost
of
a
path
wherein
one
edge
can
be
&
one
effiently
by
can
be
skipped
at
zero
cost
.
Since
popping
the
call
stack
we
are
looking
for
p
2X
act
1y
for
Explore
to
retrace
the
One
"skipped
edge"
,
wh
create
Path
up
the
tree
.
a
layered
graph
G'as
follows
:
For
2)
Briefly
justify
the
each
vertex
v
Ev
,
there
would
be
~
un-time
of
the
alg.
two
Copies
Vo
,
Vi
.
For
each
U-V
,
add
Each
edge
encountered
edges
No
-
Vo
,
No e
VI
,
and
U
,
-V
.
during
DFS
in
an
undir
.
Weights
of
the
edges
are
graph
is
either
a
tree
edge
((u0
+
Vol
=
c (U
,
evi)
=
c(ueV)
and
or
a
back-edge
.
Since
there
C
(Uo
,
V
,
)
=
0
.
Essentially
G'consists
are
only
Iv1-1
free
edges
,
of
2
separate
copies
of
G
,
w/
DFS
will
encounter
a
zero-weight
"skip"
edges
from
one
back-edge
in
O
(1v1)
time
.
Copy
to
other
.
We
construct
the
graph
G'and
use
Dij
.
Alg
.
to
find
Np-completeness
reductions
the
shortest
path
from
So
to
+i.
You
may
assume
that
the
following
problems
are
NPC
:
set
ordering
Rudrata
(Hamiltonian)
path
,
Input
:
A
family
of
subsets
S
,
....
Sn
Rudrata
(Hamiltonian)
Cycle
,
of
E1
,
...,
m3
.
Vertex
cover
,
Ind
.
Set
,
Solution
:
An
ordering
of
the
sets
3
-
Coloring
,
3-SAT
and
Int
So
that
consequetive
sets
in
the
programming
.
For
each
of
orderings
have
intersection
exactly
the
following
problems
,
fill
One
.
Formally
,
an
ordering
of
the
sets
in
the
details
of
the
proof
that
is
given
by
a
permutation
It
:
(n]
=
[n]
,
they
are
in
NPC
.
So
that
for
each
it
E1
,
...,
n-
13
,
1)
Tricl ique
:
Given
a
graph
IsnicunSicil
=
1
.
Proof
,
it
is
clear
that
G
=
(V
,
E)
,
a
subsets
<
Vof
the
set-ordering
problem
is
in
NP
.
Now
Vertices
is
called
a
clique
,
if
we
will
use
a
poly
,
time
reduction
to
every
Pair
of
vertices
ins
are
show
that
the
problem
is
indeed
NPC
.
conne
Che
&
by
an
edge
,
i
.
e
.,
for
Given
an
instance
!
of
problem
every
U
,
v
ES
we
have
(u
,
vI
E
.
We
will
construct
an
instance
T
Here
is
the
Tricl ique
problem
.
of
the
problem
as
follows
.
Input
:
A
graph
G
=
(V
,
El
Given
an
instance
G
=
(V
,
E)
of
solution
:
A
partition
of
the
Rudrata
Path
,
define
an
instance
vertices
into
3
disjoint
sets
of
set
ordering
as
follows
:
Let
S
,
USzUSy
=
VS
.
t
.,
each
of
the
the
universe
be
the
set
of
edges
Sets
S
1,
S2
,
So
is
a
clique
,
Proof
,
E
and
we
will
have
ach
Si
be
a
it
is
clear
that
the
Tricl ique
subset
of
this
universe
.
For
each
problem
is
in
NP
.
Now
we
will
use
a
vertex
itv
,
define
Si
=
Eedges
incident
polynomial
time
reduction
to
show
at
vertex
j3
.
that
the
problem
is
indeed
NPC
.
This
proof
that
this
is
a
valid
Given
a
instance
of
of
the
reduction
as
follows
:
Problem
we
will
SUPP
Ore
there
is
a
Rudrata
path
construct
an
instance
I
of
in
the
original
graph
,
then
it
gives
the
problem
as
follows
.
an
ordering
it
:
[n]
-
[n]
of
the
Given
an
instance
G
=
(V
,
E)
vertices
of
the
graph
.
The
corr
of
3-coloring
,
define
an
orderings
of
sets
satisfies
the
instance
G'
=
IV'sE')
of
Cond
.,
Sin
ce
Salis
1 Stcitic
contains
Tricl ique
as
follows
:
Set
Precisely
the
edge
from
Vertex
TT(i)
v
=
V
.
For
e
ach
Pair
(u
,
v)
to
Vertex
It
(i
+
1)
.
Conversely
,
suppose
define
,
la
,
use
Es
(4
,
v)
there
is
an
ordering
It
:
[n]e
<
n]
of
E
.
(In
other
words
,
edge
sets
.
Since
Sicil
Sici
+
i)
=
1
then
it
C
(u
,
v)
exists
in
E'if
and
only
means
that
the
set
of
edges
incident
not
exist
in
E
.
at
Vertices
iT
(i)
and
T
(i
+
1)
,
have
if
it
does
f
that
this
is
a
valid
exactly
one
common
edge
.
This
implies
reduction
as
follows
:
that
IT(i)
--
Tli+1)
is
an
edge
of
Given
a
3-coloring
G
=
(V,E)
,
be
vertices
let
Si
,
S2
,
Sy
the
set
colore
&
red
,
b
lue
,
and
green
very
-
respecti
w/in
e
ach
color
class
,
there
are
no
edges
in
E
...
the
Sets
Si
,
Sa
,
5
are
Cliques
in
the
graph
G'
=
(V'
,
E')
.
conversly
,
S
upp
OSe
S
,
Sc
,
S3
are
cliques
in
G'
=
(V'
,
E'l
Then
consider
the
coloring
that
assigns
vertices
in
these
sets
reen
red
,
blue
,
and
9
respectively
Since
each
Si
is
a
clique
in
G
,
there
are
no
edges
w/in
any
S
:
Hence
this
is
a
valid
3
coloring
of
graph
G
.
-
-o
0-0
I
-
&
-
b
-
-
~
-
do
O
El
-
Trian gul ar
Removal
Reduction
a
following
2
problems
:
In
the
triangular
removal
problem
,
the
input
is
a
graph
G
=
(V
,
E)
.
The
goal
is
1)
Matching
to
remove
the
smallest
#
of
edges
from
Input
:
Graph
G
=
(V
,
E)
and
a
#
so
as
to
delete
all
triangles
in
the
positive
integer
k
g
raph
.
Formally
,
here
is
the
def
.
of
Sol
:
A
set
of
k
edges
e
,
...,
ek
,
triangle
freeness
.
Definition
:
A
graph
no
pair
of
which
share
a
vertex
.
is
triangle
-
free
if
there
are
NO
3
2)
Indpendent
Set
Vertices i
,
j
,
keV
S
.
t
.
(i
,
j)
,
(Jsk)
,
Input
:
Graph
G'
=
(V'
,
E')
and
a
and
(k
,
i)
are
all
edges
.
Here
is
the
Positive
integer
K
for mal
def
.
of
triangle
removal
Problem
:
Sol
:
A
set
of
K
vertices
SCV'
,
no
Input
:
An
unweighted
undir
.
graph
G
=
(v
,
E)
pair
of
which
are
connected
by
an
Sol
:
Find
the
smallest
set
of
edges
E'such
edge
.
that
deleting
E'makes
the
graph
become
The
problem
Independent
Set
triangle-free
·
We
will
now
deve
an
approx
.
is
believed
to
not
reduce
in
&
lg
,
for
the
problem
.
First
write
a
linear
poly
.
time
to
Bipartite
programming
relaxation
for
the
Matching
because
Independent
trial-removal
problem
.
Set
is
a
NPC
problem
While
What
are
the
variables
of
the
linear
program
Bipartite
matching
is
a
(LP)
?
(write
out
succinctly
and
precisely
,
lem
in
p
.
Since
the
In
do
Prob
the
intended
meaning
of
the
variables
in
Set
is
a
harder
problem
than
your
LP)
Xe
for
each
edge
ef
E
.
The
intended
Bipartite
Matching
,
Provid
a
meaning
is
that
Xe
is
the
amount
of
Bipartite
matching
w
ould
edges
e
that
is
deleted
.
Show
that
p
=
Np
,
which
What
is
the
obj
.
func
.?
is
currently
not
believed
.
Minimize
e
on
the
other
hand
,
Matching
reduces
in
P
·
lynomial
time
What
are
the
constraints
of
the
LP
?
to
Ind
.
Set
.
Reduction
:
Given
&
Xe11
for
all
e
E
an
instan
ce
d
of
the
prob
nem
Xa
+
Xb
+
Xc])
for
all
triangles
a
,
b
,
C
.
Matching
we
will
construct
Describe
a
rounding
scheme
to
obtain
an
instance
Or
a
50
,
13
sol
·
from
the
opt
.
Sol
.
to
the
above
If
Xe
y
,
round
it
to
1
.
0
.
W
.
round
to
0
.
E'
is
the
set
of
edges
e
W/Xe
=
1
.
i
Briefly
justify
why
the
rounding
Scheme
Prod
.
a
Sol
.
to
the
Trian gula r
Reduction
:
Removal
problem
.
For
any
triangle
(a
,
b
,
c)
in
G
,
since
Xa
+
Xb
+
X
,
=
1
,
at
least
one
edges
&
EEa
,
b
,
13
has
Xe
?
"
,
so
we
delete
at
least
one
of
edges
in
the
triangle
·
So
there
can't
be
a
triangle
in
E
'
Wh
at
is
the
approx
.
ratio
of
your
alg
.?
3
.
b/c
Xe
is
scaled
up
by
a
factor
of
at
most
3
during
rounding
.
Edit
Distance
a
...
n
Y
[1
,
...,
my
,
recall
that
the
edit
dist
.
is
the
smallest
#
of
keystrokes
needed
to
edit
the
S
tring
X
into
String y
.
Here
each
insertion
and
deletion
of
a
character
takes
one
key
stroke
.
We
devised
a
dynamic
programming
alg
.
for
the
problem
wherein
the
subproblems
are
e
#
D[i
,
j]
=
minimum
#
of
keystrokes
nee
de
&
to
edit
the
Prefix
[1
,
...,
i]
into
the
Prefix
11
,
....
j]
.
Suppose
We
had
a
special
keeboard
in
which
·
each
Insertion
takes
z
keystrokes
·
each
insertion
takes
3
keystrokes
·
each
substitution
takes
a
keystrokes
1)
write
down
the
modified
recurrence
relation
ED[i
,
i]
E
ED[i
-
1
,
j]
+
3
-
intersection
ED[i
,
j]
=
min
ED[i
,
j
-
13
+
2
ED
Siri
,
j-1]
+
4
.
1x[i]
*
y[i]]
write
down
the
modified
base
case
for
ED(i
,
j]
ED[i
,
0]
=
3i
vi
ED[O
,
j]
=
2
;
j
Minimum
Median
Te
-
the
followin
S
problem
919.
for
the
graph
.
Hence
TT
(1)
-
-
T(z)
--
...
(n)
is
Input
:
A
graph
G
=
(V
,
E)
and
a
Rudrata
Path
in
the
original
graph
.
weights
on
the
edges
[Welec
E3
.
Solution
:
A
spanning
tree
T
that
All
pairs
shortest
paths
:
minimizes
the
median
cost
(T)
,
In
the
lecture
,
we
have
seen
the
Where
median
cost
(1)
is
defined
Floyd-Warshall
a19
,
for
computing
as
median
cost
(T)
=
median
of
the
distances
blu
every
pair
of
vertices
weights
of
the
weights
of
the
in
an
input
graph
.
The
Floyd
Warshall
edge
5
in
the
tree
T
.
The
runtime
of
alg
.
is
a
dynamic
programming
alg
.
Your
alg
.
must
be
polynomial
in
the
~
/
runtime
O(n3)
.
In
this
question
,
#
of
vertices
n
=
IVI
.
we
will
devise
a
simplier
dynamic
Give
a
succinct
and
precise
descr
.
programming
based
a
19.
for
all
pairs
of
your
a
eal's
or
prim's
shortest
paths
,
wh
slightly
worse
prove
the
correctness
o
f
your
a1g
.
runtime
Girlhahihugraphe
The
C
ut
property
stills
hold
.
If
(i
,
j)
.
Consider
the
following
sub-problem
:
+
lighest
edge
in
a
cut
is
not
ne
D
[i
,
j
,
t]
=
length
of
shortest
path
from
in
a
MMT
,
replace
it
/
that
and
i
to
;
w/
at
most
2t
hops
.
(Here
"hop"
You
get
a
better
MMT
::
any
MST
refers
to
the
#
of
edges
on
the
path)
.
is
a
MMT
.
Write
the
recurrence
relation
for
D[i
,
j
,
t]
D[i
,
j
,
+]
=
MinED(i
,
k
,
t-1
+
D(k
,
i
-
>
write
psuedocode
for
the
alg.
to
compute
all-pair
distances
,
including
the
initialization
.
For
i
,
jEV
,
D(ii]
=
SWijifiRE
For
t
=
1
+
o
Di
,
j
,
+]onForiinForinForKin
S
return
D(i
,
j(logn]]
KEV
for
all
i
,
j
.
What
is
the
runtime
of
your
alg
.?
O(n3
logn)
where
n
=
IVl
.
-
the
problem
End.
set
as
follows
.
For
each
&
of
$
,
create
a
edge
an
in
6'
of
T
.
For
each
Pair
of
edges
(e
,
22)
that
Share
vertices
,
add
an
edge
e'
=e
blu
the
corr
.
Vertices
VI'
,
in
G'of
Y
.
NP-completeness
Reduction
:
1)
Hitting
Set
:
Input
:
Positive
integers
n
,
m
,
k
and
a
family
of
sub
El
,...,
m3
Sol
:
A
subset
H
Sets
Si
.
Sno
e
size
k
that
overlaps
every
one
o
the
Sets S
s
null
Q
u
Proof
it
is
clear
that
Hitting
Set
Problem
is
in
NP
.
Now
we
will
use
a
polynomial
time
reduction
to
show
that
the
problem
is
indeed
NPC
.
Give
an
instance
6
of
the
problem
Vertex
cover
we
will
construct
an
instance
of
the
Problem
Hitting
set
as
follows
.
We
want
to
reduce
from
VC
to
Its
so
we
construct
an
instance
of
As
to
solve
a
given
instance
of
VC
.
Let
G
=
(V
,
El
be
the
input
graph
to
Vertex
cover
.
T
~
or
each
edge
(u
,
v)
EE
,
add
a
Subset
Si
=
Eu
,
v3
to
the
Hitting
set
instance
.
Finding
a
vertex
cover
of
s
ize
K
is
the
same
as
finding
a
hitting
Set
HCV
of
size
on
inputs
S
...,
SiEl
Crepe
integers
in
the
Hitting
Set
instances)
.
Proof
:
A
Vertex
cover
SCV
has
the
property
that
for
all
(u
,
v)
E
E
at
least
one
u
,
v
is
in
S
:
S
intersects
w/
each
of
Si
and
is
a
hitting
set
.
Now
suppose
we
have
a
hitting
Set
H
.
For
each
(u
,
v]
E
E
,
Eu
,
v3
10
::
I
covers
all
edges
and
is
a
vertex
cover
.
Max
Flow
:
There
are
connected
,
undir
.
graphs
G
S
.
t
.
dec
.
the
capacity
Of
any
single
edge
in
6
doesn't
Chan
aX
-
>
ow
the
value
of
the
min
cut
There
are
connected
,
undir
.
graphs
G
S
.
t
.
in2
.
the
capacit
a
of
any
singled
a
of
the
max
Chan
-
ow
.
True
There
are
dir
.
graphs
G
S
.
t
.
des
the
capacity
of
any
single
edge
in
a
does
not
change
the
Val
.
of
max
flow
.
True
CT
rueFas
can't
have
exact
distinct
optimal o
a
Bakery
((P/dual)
:
John
owns
a
bakery
which
prod
cakes
,
cookies
,
and
scones
.
Jon
makes
$10
for
each
cake
,
$1
for
each
cookie
,
and
$2
for
each
scone
sold
.
Ing
of
200
units
of
flour
,
100
units
of
sugar
,
and
so
eggs
.
LP
:
max
10
a
+
b
+
2C
dual
:
min
zood
+
100e
+
50f
one
cake
need
a
a
+
b
+
3C
1200
5d
+
2e
+
5f
-
10
5
·
e
cookie
needs
o
2a
+
2b
+
c
1100
d
+
2e
+
f
-
I
&
2)
I
le
f
·
one
S
59
+
b
+
2150
3d
+
e
+
2
-2
3f
,
I Scone
need
s
a
b
,
]
O
d
,
e
,
f
>
0

Partial preview of the text

Download CS170 Final Cheat Sheet and more Study notes Computer Science in PDF only on Docsity!

Non-MST Ed ge Discount path

:

Devise a 0 (IvI)-time

als for

consider a directed graph

the following prob lem

: G

=

(V , E) w/ pos. weights ((i ,

i)

Input

: Graph G = (V , E) w/ distinct on its edges .

Given a path

= vo-

edges weights

Wi;

for edge V, ...

-> UK ,

the discounted

cost

(i , i) =

E

.

of the path is

the sum of

Solution

: Find some edge lengths

of all but the longest edge.

(i , i) EE S

.

E. Li ,

j) isNot

part

Formally,

Of any MST.

k - 1

1) Give a succinct and precise

cost(p)

=

((Vi

, vi

maxc(Vi

, vit)

description of the9l9.: (It is the sum of cost of all edges

The

idea is to

find the minus maximum costed ge(

heaviest edge

in

some cycle

Devise an alg

,

to compute the smallest

of

the

graph

. Run DFS

on discounted

cost path from a vertex

the graph

until we s to vertext

Give a succinct and

encounter a back

edge U-V ,

Precise descr. of

your alg.

Proof of

discovering

a cycle

. We will correctness and run-time analysis

find the heaviest edge

are not necessary.

The runtime of

Cycle

and return

it.

This

Your alg. Should be o((IVI

1E1) 10g (v))

.

the heaviest edge , Check

Minimizing the discounted

cost of

all

edges

along

the path

a

path is the same as

minimizing

~ to u in the

tree. This

the cost of a path

wherein one edge

can be

&one effiently

by

can be skipped

at zero cost.

Since

popping

the

call stack we are looking for p 2X act 1y

for Explore to retrace the One

"skipped

edge",

wh

create

Path up the tree . a

layered graph G'as follows

: For

2) Briefly justify the each

vertex v Ev ,

there would be

~

un-time

of the alg. two Copies Vo

,

Vi. For each

U-V

, add

Each

edge encountered edges No

Vo ,

No e VI ,

and

U

,

-V

.

during DFS in an undir. Weights

of the

edges are

graph is either a tree edge ((u

Vol

= c (U , evi)

= c(ueV) and

or a

back-edge. Since there

C (Uo

,

V , )

=

0. Essentially G'consists

are only

Iv1- free edges,

of 2 separate copies

of G ,

w/

DFS will encounter a zero-weight "skip" edges from one

back-edge

in O

(1v1)

time. Copy

to other. We construct the

graph

G'and use Dij. Alg. to find

Np-completeness reductions

the shortest path from So to +i.

You may assume that the

following problems are

NPC :

set ordering

Rudrata (Hamiltonian) path

,

Input :

A

family

of subsets

S

, ....

Sn

Rudrata (Hamiltonian) Cycle

,

of

E1, ...,

m

.

Vertex cover,

Ind.

Set

,

Solution

: An ordering

of the sets

Coloring

,

3-SAT

and

Int

So that consequetive sets in the

programming. For each

of orderings have intersection

exactly

the following problems , fill

One. Formally ,

an ordering of

the sets

in the

details

of the

proof that

is

given

by a

permutation

It

:

(n] = [n]

they

are in NPC.

So that for

each it E1, ...,

n- 13 ,

1) Triclique

: Given a graph

IsnicunSicil

= 1. Proof ,

it is clear that

G =

(V , E) ,

a

subsets

< Vof

the set-ordering problem is in NP. Now

Vertices is called a clique

,

if we will use

a poly ,

time reduction to

every

Pair of

vertices ins are show that the problem

is indeed NPC.

conne

Che & by an

edge ,

i

.

e

., for

Given an

instance !

of problem

every U ,

v ES we have (u , vI E.

We

will construct

an instance T

Here is the Triclique problem. of the

problem as follows .

Input

: A graph G

=

(V , El Given

an instance G

= (V ,

E) of

solution

: A partition of the Rudrata Path , define an instance

vertices into 3 disjoint sets of set

ordering as follows : Let

S,

USzUSy

=

VS. t ., each

of the the universe be the

set

of edges

Sets

S 1, S2, So is a

clique ,

Proof

E and we will have ach Si be

a

it is clear that the Triclique subset of this

universe. For

each

problem is in NP. Now

we will use a vertex itv ,

define Si

=

Eedges incident

polynomial time reduction to show

at vertex

j3.

that the problem is indeed NPC. This proof that this is a valid

Given a instance of of the reduction as follows

:

Problem we will

SUPP

Ore

there is a Rudrata path

construct

an instance

I of in

the original

graph ,

then it gives

the problem as follows. an ordering

it : [n]

  • [n] of the

Given an

instance G

=

(V , E)

vertices of the

graph. The

corr

of

3-coloring

,

define an

orderings of sets satisfies the

instance G'

=

IV'sE') of

Cond .,

Sin ce

Salis 1 Stcitic contains

Triclique

as follows : Set

Precisely the

edge from Vertex TT(i)

v

= V. For e ach Pair (u , v)

to Vertex It (i

1). Conversely

,

suppose

define

,

la

, use Es (4 ,

v) there

is an

ordering It

:

[n]e < n] of

E

. (In other words , edge

sets. Since Sicil

Sici

i)

= 1

then it C

(u, v) exists

in E'if and only

means

that the set of edges

incident

not exist in E.

at Vertices iT (i) andT (i

,

have

ifitdoesf

that

this is

a valid exactly one common edge. This

implies

reduction as follows

:

that IT(i)

--

Tli+1) is an edge of

Given

a 3-coloring

G

=

(V,E) ,

be

vertices let Si ,

S

, Sy

the set

colore

& red , b lue ,

and

green

respecti very -

w/in

each color

class ,

there are no edges

in

E

... the Sets

Si , Sa , 5

are

Cliques

in

the graph G' = (V'

,

E')

.

conversly ,

S upp OSe S , Sc , S

are cliques in G'

= (V' , E'l

Then consider the

coloring

that

assigns vertices in these sets

red reen ,

blue

,

and 9

respectively

Since each Si is a clique in G

,

there are no edges

w/in any

S:

Hence

this is a valid 3

coloring of graph G.

-o

0-

I

b

do

O

El

  • Triangular Removal

Reduction

afollowing

2 problems

: In

the triangular removal problem

,

the

input is a graph G

=

(V , E). The goal is

Matching

to remove the smallest

of

edges

from

Input

:

Graph

G

=

(V

,

E) and a

# so as to delete all triangles in the positive integer k

g

raph. Formally , here is the def.

of

Sol : A set of k

edges e , ...,

ek ,

triangle

freeness

Definition

:

A graph

no pair

of which share a vertex

.

is triangle

free

if there

are NO 3

Indpendent Set

Vertices i ,

j

, keV S. t. (i , j) ,

(Jsk)

, Input

:

Graph G' = (V' , E')

and a

and (k

,

i) are all edges. Here is the Positive integer K

for mal def. of triangle

removal Problem : Sol

: A set of K vertices SCV' , no

Input: An unweighted undir. graph G

=

(v, E) pair of which are connected by an

Sol

: Find

the smallest set of edges

E'such

edge

.

that deleting E'makes the graph become

The problem Independent

Set

triangle-free

· We will now deve an approx. is believed

to not reduce in

&lg , for the problem. First write a linear poly

time to

Bipartite

programming relaxation

for the Matching

because

Independent

trial-removal problem.

Set

is a NPC problem While

What are the variables of the linear

program Bipartite

matching is a

(LP)? (write out

succinctly

and precisely

, lem in p. Since the Indo

Prob

the

intended meaning of the variables in

Set

is a

harder problem

than

your LP)

Xe for each

edge ef E. The intended Bipartite Matching

,

Provid

a

meaning

is that Xe

is the

amount of

Bipartite

matching w ould

edges e that is deleted.

Show

that p

= Np

,

which

What is the obj. func .?

is currently

not believed.

Minimizee

on the other

hand

,

Matching

reduces

in P·

lynomial time

What are

the constraints of the

LP

to

Ind. Set.

Reduction

: Given

& Xe11 for all e E

an

instance

d

of the prob

nem

Xa + Xb

Xc])

for all triangles a , b , C. Matching

we

will construct

Describe a

rounding scheme to obtain an

instance

Or

a

sol · from the opt. Sol. to the

above

If

Xe

y , round

it to 1. 0. W. round to 0.

E' is the set of edges e W/Xe

=

i Briefly

justify

why

the

rounding

Scheme Prod. a Sol. to the Triangular

Reduction

:

Removal

problem

For any triangle (a , b

,

c) in G , since

Xa + Xb + X , = 1 ,

at least one edges

& EEa ,

b

has Xe? " ,

so we delete

at least one of edges in

the triangle · So

there can't be a triangle in E'

Wh at is the approx

. ratio of your

alg .?

b/c

Xe

is scaled

up by a

factor of at

most 3 during rounding.

Edit

Distance

a

... n

Y [1 , ...,

my ,

recall that the

edit dist.

is the smallest

of keystrokes

needed to edit the S

tring

X

into

String y. Here each insertion and

deletion of

a character

takes one

key stroke. We devised

a dynamic

programming alg. for

the problem

wherein the subproblems

are

e

D[i

, j]

= minimum # of keystrokes

nee de& to edit thePrefix [1, ...,

i]

into thePrefix 11 , .... j].

Suppose

We had

a

special keeboard in which

· each Insertion takes z keystrokes

·

each insertion takes

keystrokes

·

each substitution takesa

keystrokes

write down the modified

recurrence

relation ED[i , i]

E

ED[i - 1

,

j] + 3

intersection

ED[i , j]

=

min ED[i

,

j

  • 13

2

ED Siri ,

j-1]

.

1x[i]

y[i]]

write down

the modified base

case

for ED(i , j]

ED[i

,

0]

= 3i vi

ED[O ,

j]

=

j

MinimumMedian

Te

  • the followinS

problem

919. for

the

graph .

HenceTT (1)

    • T(z)

--

...

(n) is Input

:

A graph

G = (V,

E) and

a Rudrata Path in the original graph.

weights on

the edges [Welec

E .

Solution : A spanning

tree T

that

All

pairs shortest

paths

:

minimizes the median cost (T)

,

In the

lecture

,

we have seen the Where median cost

is defined

Floyd-Warshall

a19 , for computing as median

cost

(T)

=

median of the

distances blu

every

pair of vertices

weights of

the weights of

the

in an input graph

The Floyd Warshall

edge

5 in the

tree

T

. The runtime of

alg. is a

dynamic programming alg.

Your alg

. must be

polynomial in the

~/ runtime O(n3). In this question

,

of vertices n

= IVI

.

we will devise a simplier dynamic Give

a succinct and precise

descr

programming

based a 19. for all

pairs

of

your

aeal's

or prim's

shortest paths

,

wh slightly worse

prove the correctness o

f your

a1g.

runtime

Girlhahihugraphe

The

C

ut property stills hold. If

(i ,

j). Consider the following

sub-problem

:

+ lighest

edge in a

cut

is not

ne

D [i , j , t]

=

length of shortest path from in a MMT

,

replace it / that and

i

to

; w/ at most

2t hops

(Here

"hop"

You get a

better MMT

::

any

MST

refers to

the #

of edges on the path)

is a

MMT.

Write the recurrence relation for D[i

,

j

, t]

D[i ,

j

, +]

=

MinED(i

,

k ,t-1 + D(k, i -

>

write

psuedocode for the alg. to

compute all-pair

distances

,

including the

initialization. For i ,

jEV

,

D(ii]

=

SWijifiRE

For t

= 1 + o

Di ,

j

,

+]onForiinForinForKinS

return D(i , j(logn]]

KEV

for all i ,

j.

What is the

runtime of your

alg.? O(n

logn) where n

= IVl.

the

problem

End. set as follows. For

each

& of $

,

create a

edgean

in 6' of T

.

For each

Pair of edges (e, 22) that

Share vertices ,

add an edge

e'

=e

blu the corr. Vertices

VI'

,

in G'of

Y.

NP-completeness

Reduction

:

1) Hitting Set

:

Input

:

Positive integers n, m

,

k

and a

family of sub El

,...,

m

Sol

: A subset H

SetsSi

.Sno

e

size k that

overlapseveryoneothe Sets S

s

null

Q

u

Proof

it is clear that HittingSet

Problem

is in NP. Now we

will use

a

polynomial time reduction to show

that the

problem is

indeed NPC.

Give an instance 6 of the problem

Vertex cover we

will construct an

instance

↑ of theProblem

Hitting

set as follows.

We want to reduce

from

VC

toIts

so we construct an

instance of As to solve a given

instance of VC. Let G = (V

,

El be

the input

graph

to Vertex cover

.

T

~ or

each

edge (u , v) EE , add a

Subset

Si

=

Eu ,

v to the Hitting

set instance. Finding a vertex

cover of s ize K is the same

as

finding a hitting Set

HCV of size

oninputs

S ..., SiEl Crepe

integers

in

the Hitting

Set instances).

Proof

: A

Vertex

cover SCV

has

the property

that for all

(u , v) E

E

at least one u ,

v is in

S

S

intersects w/ each of Si and

is a

hitting set

.

Now suppose we have

a

hitting

Set H. For each (u ,

v] E

E

,

Eu

,

v3 10 :: I covers

all

edges and

is

a vertex

cover.

Max

Flow

:

There are

connected ,

undir

.

graphs G

S.

t

. dec. the capacity

Of any single

edge in 6 doesn't

Chan

aX

owthevalue ofthemin

cut

There

are connected ,

undir.

graphs

G S. t.

in

.

thecapacita

of

anysingled

a

ofthe max

Chan

ow. True

There

are dir. graphs G S. t.

des the capacity of any single

edge in a

does

not change

the

Val. of max flow. True

CT

rueFas

can't have

exact

distinct

optimal o a

Bakery ((P/dual)

:

John owns a bakery

which

prod cakes

,

cookies

,

and

scones.

Jon

makes $ 10 for each

cake

,

$ 1 for each

cookie

,

and $ 2 for each scone sold

Ing

of

200 units

of flour

units

of

sugar ,

and so

eggs.

LP

: max 10 a + b

2C

dual

:

min zood

100e

  • 50f

onecake

needa

a

+ b + 3C 1200 5d + 2e + 5f -

·e

cookie needs

o 2a

2b

  • c

d + 2e + f - I

&

  1. I

le f

· one

S

b

3d

e

3f

,

I Scone

needs

a

b ,

] O d , e ,

f