Final Notes Chapter1 7 1
Final Notes Chapter1 7 1
0 Notation
-
flnl =
Olgin) ) OR f =
0cg)
d- Notation
Let f and be functions If 7 constant
g
a
.
G- Notation
Let fond be functions if 7 two constants
g
.
s.tqglnkflnkczg.tn/-VnZk
G. GEIR and KEN
then we write :
Runtime :O / n
login) Runtime Olnlostd :
)
S, Biz Bzz SEA ,tA,z
-
=
,
2 I 4 3
53 Az, 1- Azz 54=132,1-13
-
2 1 9 13 •
2
I 4 3
11 2 314
Master theorem
.
1121314
'
Tlnl={a.TL%)
n -4
+ nd n >1
smallest
elem ins
Runtime: Oln)
Finding Runtime :
Unfolding Induction :
Let be
Tlnl -11%1
n
large and assume
n Tlmlsc.vn for
+
all
k-mcn-tl.IT/+Z&n n
:
•
Chapter 3
Order
Depth-first Search / DFS) Topo
undirected
Problem : Explore directed
Problem : Explore graph
graphs
with vettices
Input Directed
: graph G
Graph C-
Input : a
w/ no
cycles
order of C-
✓ and
edges E Output Topo ;
Runtime: 0114+11=-1) r
n do B > D VE
A
d
89C
2
B) >
B→ A S
→,c→E
☐
3 14s 6 1 2
,
3
D E 4 5 g
DFS -
? I C
¢ : tree edges on Postnumbers
/ q
✗ v10 \ e
'
: forward edges 3 : Reverse
posterder
,zyy T : back edges
4¥ Runtime :O / IVHIEI)
' F-
g. Cross edges
☐
l '
iii. ←
! -
'
Chapter 3
Dijkstra's Algo
Problem Find : the shortest path between 2 vertices
in weighted directed
a
,
graph
1- input Directed
:
graph G w/ vertices V
and
edges Fe
,
where each
edge ahas a weight .
Output :
Ys
at >✗
^
t ✗ y z
r ^ 1 0 10 ✗ 5 X
lo
2 3 a 8 14 7
6 2
S y
3 8 13
r 5
9 / T
Yy 2
Yz
4 I
7
Chapter 4
Greedy Algo :
An that arrives
algorithm at a solution by '
Making Change
Problem How can
: a
given amount of
money
be made
w/ the least number of fins with gives demons
Afn put : An of denominations and
integer v
array ,
an
the value V
1. 65 -
1
Coins :{0.05, 0.1 0.25 1,2 }
, ,
0.65 -
0.25
Sum : 1.65
0.4 -
0 .
25
0.15 -
0.10
0.05 -
0.05
knapsack
Fon put objects weight end
n
each object
:
st has a
a valve and a maximum weight W
=
Xz,✗, .
. .
,xn St
-
Of ✗if I -
the total value ✗
, Ytxzvzt txn is
maximised
.
. -
the total
weight
-
✗
txzwzt EW
w
+
, , . . -
Xniwn
Runtime Olnlogln ) ) :
Chapter 4
knapsack lemma
knapsack example
If the objects are
I 1 2 3 4 5
✗g- I selected in
Vi 20 30 66 40 Go decreasing
✗i lo 20 30 40 50
4=1 Viwi , then the greedy
✗2=1
choice finds an optimal
'
Minimum LMST)
Spanning Tree
Given undirected connected
a
weighted , , Graph G- Cv,r
,
MSTG of
'
an G is sub
a
graph such that :
-
G is connected
Sum of the
weights of
-
edges in minimum
'
G is
8 7
$ • •
9
4 2
11
y
•
• 14 •
,
10
8
••• -
• •
I z
shortest
edge connected
be A and B
Let { 44 G- E the .
Kruskal
5
MST of G 6
Problem: Find an A c E
Runtime :
Olmlogln)) BGBD.CD.CF.tt#DFEF,.A/B,CE,Ac
1 2 3 4
Prim
start :
-
A-
T
is a set consisting
of
of an
arbitrary vertex
- is an
empty set
edges
Q is all vertices in G- not in A
-
Freq , let :
weight 1×1 is
-
Add ✗ to A and remove it from Q
-
add
{× ,
closest 1×1 } to T
-
update closest and minmeight for all vertices
not in A. connected to ✗
Runtime : Olmloglnl )
Chapter 4
Prim -
example
6 5 b
A B C D
1
>
1 23 5 5 7
2 46
F- 2
43
5
F C- H
,
:
Chapter 5 General structure
B. Structure the optimal
solution
2. Write a recursion for
the optimal solution
3. Solve the recurrence
Matrix Multiplication
Problem : Find the optimal order to multiply a set
of matrices
together matrices Al Az Az
F- input :
A set of n
, ,
An where
, , . . .
A, is Po XP,
,
Az is P, Pz ,
✗
,
Antis
. .
Pn i ✗ Pn
. .
-
-
,j)={iI¥jk
0 if i=j
mli
mliikltmlktl 's ) -1 Pi
, Pkpj ) lficjsn ,
Runtime : 01ns)
-
Longest common
subsequence (Lcs)
Problem : Find the LCS between two sets
Input : 2
sequences
✗ and Y
between ✗ and Y
Output : the LCS
{[a×(
i = 0 or j = 0
Cli , j ) = 1 + Cli -
1, j -
and ✗ i =/
,
Yj
Chapter 5
Floyd -
War shall
,j,o)={
tliii ) if
distli edge fisj ) exists
✗
else
For Asian , 1£ js.in Is Ken :
,
distci,j,k)=min{
distli.j.k-H.distli.kik-iltdistlkis.tl-11)
Runtime: 01h31
Chapter 6
A decision problem is a
problem for which
polynomial -
C is polynomial to the
length of I
-
In Polynomial time ,
Problems in P we
verify that
can
C is a correct proof
graph bipartite
?
-
Is a
-
-
a
1-1am Cycle-
Problem
Input Undirected graph
:
G- =
IV. E)
•
•
Chapter 6
G- LYE)
,
where
each
edge is
weighed
An
- K
integer
Question : Does G contain a hamiltonian cycle
of total at most
weight K?
Unknown if in p
A of
5={5,756/23,2902}
set
integers g
-
f- 2963
-
an
integer K
Yes ! { 5,5612902}
'
S
Question : Is
-
there a subset g)
of S Unknown if in P
s.tt#s.x--t ?
Chapter 6
Definition of P
A
The
language L is in P if 7 an
algo
and a
constant cat sit for any input ✗
-
✗ EL Alex)= Yes
-
The runtime of Atx ) is olnc) where n
is the
length of ✗
Definition of Np ( Non -
deterministic Polynomial)
The language L is in NP if F- an
algor
and a Constante 21 s -
t for any input ✗
✗ EL ⇐ 1- a certificate yet
-
Iyl =
011×14
-
Vlx, y ) =
Yes
- VCX /
y)
runtime is polynomial
of
to the
length ✗
Theorem Language
NP The
language
of
P c- NP a Problem
decision
p is the set of all
inputs for which
the answer is
yes or no
Chapter 6
Reductions Famous 3 Properties
'
L and L
For 2 languages
J
.
✗ c- L⇐> flxl
C- L
CZI
Lsp
CLIQUE Problem
K=4
Input :
• • •
graph
•
,
- An undirected C-
An integer K •
••
-
a clique of size K
INDEP -
SET
k =3
Problem
In plot : ⑨ •
\
- An undirected graph C-
- An integer K
⑨
Question Does : C- contain
an independent set of size
K
•
⑨
INDEP -
SET
Ep CLIQUE
Chapter 6 Theorem
If LEPL '
and L' EP
then LEP
-
An int k •
Question :
Does ' G contain ⑧ ⑨ ⑨
a vertex cover of size K
-
CLIQUE ftp.VERTEX -
COVER
3. SAT
µ%npUt ?
10=1> ✗ vyv> 2) nlxv > yvz )A(xvyvz't
y
"
-
A boolean formula of the
Y ✗
form 10=9^9 ^ . . -
Mcm
'
Clause
↳ ci-ljvli.ve , literal
7✗ 72 TY -2
Question : Is at satisfiable? ×
s.to/--l3SATfp.INDEP- SET
Chapter 6
NP-Hard NP-Complete
A L is NP-complete
A
language
L is NP-Hard
if
language
:
if Y L' ENP, L'
Ep L -
LENP
t L'c- NP L' fpl
Not covered
-
Theorem Million $
Then
Assume L is NP-complete Question
LEP < P=NP
Theorem
}
L NP-complete
is
'
L NP-complete
'
is
Lfp L
L' GNP
'
show L is NP-complete
1. Show L' ENP
2. Look for "
similar
"
problem L that
is NP Complete
-
'
3. Show Lfpl
Chapter 6
CIRCUIT -
SAT
Input :
whose vertices in
degree
are -
2
boolean
gates NOT Gates
-
have
Known input gates
-
in
have in
degree 0 and
-
degree I
are TRUE or FALSE
-
There is one output
-
Unknown input gates gate
is 0
,
whose out
degree
have
and
in
are
degree
labelled ?
0
complete
'
CIRCUIT SAT is NP -
-
CIRCUIT
-
SAT fp SAT 3
Chapter 7
Theorem
In the decision tree moder
,
of numbers
sorting array n
an
takes rent
ogcnll time
Theorem
In the decision tree model ,
in sorted
finding the position of × a
Theorem
Icn) time to find the
max
It takes
element in an A- [ 1 n]
array
. - •
Theorem
It takes h1n1 steps to compute
the median of an unsorted array AII . . ]
n