Algoritmos e complexidade Notas de aula - Arquivo Escolar
Algoritmos e complexidade Notas de aula - Arquivo Escolar Algoritmos e complexidade Notas de aula - Arquivo Escolar
8. Algoritmos de aproximação Como aproximar? • Idéia: Ordene por vi/ti (“valor médio”) em ordem decrescente e enche o mochila o mais possível nessa ordem. Abordagem 1 K−G(vi ,ti ) := 2 ordene os i t e n s t a l que vi/ti ≥ vj/tj , ∀i < j . 3 for i ∈ X do 4 i f ti < M then 5 S := S ∪ {i} 6 M := M − ti 7 end i f 8 end for 9 return S Aproximação boa? 186 • Considere • Então: v1 = 1, . . . , vn−1 = 1, vn = M − 1 t1 = 1, . . . , tn−1 = 1, tn = M = kn k ∈ N arbitrário v1/t1 = 1, . . . , vn−1/tn−1 = 1, vn/tn = (M − 1)/M < 1 • K-G acha uma solução com valor ϕ(x) = n−1, mas o ótimo é OPT(x) = M − 1. • Taxa de aproximação: OPT(x)/ϕ(x) = M − 1 n − 1 = kn − 1 n − 1 • K-G não possui taxa de aproximação fixa! ≥ kn − k n − 1 • Problema: Não escolhemos o item com o maior valor. = k
Tentativa 2: Modificação 1 K−G’ ( vi ,ti ) := 2 S1 := K−G(vi ,ti ) 3 v1 := i∈S1 vi 4 5 S2 v2 := {argmaxi vi} := i∈S2 vi 6 i f v1 > v2 then 7 return S1 8 else 9 return S2 10 end i f Aproximação boa? • O algoritmo melhorou? • Surpresa Proposição 8.5 K-G’ é uma 2-aproximação, i.e. OPT(x) < 2ϕK-G ′(x). 8.3. Aproximações gulosas Prova. Seja j o primeiro item que K-G não coloca na mochila. Nesse ponto temos valor e tamanho ¯vj = vi ≤ ϕK-G(x) (8.1) 1≤i
- Page 137 and 138: Saída A potência a n . 1 i f n =
- Page 139 and 140: 3 Quicksort (l ,m − 1 ,a ) ; 4 Qu
- Page 141 and 142: 6.2. Resolver recorrências 1. Se f
- Page 143 and 144: 6.3. Algoritmos usando divisão e c
- Page 145 and 146: 6.3. Algoritmos usando divisão e c
- Page 147 and 148: 6.3. Algoritmos usando divisão e c
- Page 149 and 150: 6.3. Algoritmos usando divisão e c
- Page 151 and 152: unidade. Em total a avaliação pro
- Page 153: 3. T (n) = 3T (n/4) + n log n 4. T
- Page 156 and 157: 7. Árvores de busca, backtracking
- Page 158 and 159: 7. Árvores de busca, backtracking
- Page 160 and 161: 7. Árvores de busca, backtracking
- Page 162 and 163: 7. Árvores de busca, backtracking
- Page 164 and 165: 7. Árvores de busca, backtracking
- Page 166 and 167: 7. Árvores de busca, backtracking
- Page 168 and 169: 7. Árvores de busca, backtracking
- Page 170 and 171: 7. Árvores de busca, backtracking
- Page 172 and 173: 7. Árvores de busca, backtracking
- Page 174 and 175: 7. Árvores de busca, backtracking
- Page 176 and 177: 7. Árvores de busca, backtracking
- Page 178 and 179: 7. Árvores de busca, backtracking
- Page 180 and 181: 8. Algoritmos de aproximação Clas
- Page 182 and 183: 8. Algoritmos de aproximação Exem
- Page 184 and 185: 8. Algoritmos de aproximação - Te
- Page 186 and 187: 8. Algoritmos de aproximação O qu
- Page 190 and 191: 8. Algoritmos de aproximação decr
- Page 192 and 193: 8. Algoritmos de aproximação •
- Page 194 and 195: 8. Algoritmos de aproximação Apro
- Page 196 and 197: 8. Algoritmos de aproximação 12(l
- Page 199 and 200: 9. Algoritmos em grafos 197
- Page 201 and 202: 9.1. Fluxos em redes A circulação
- Page 203 and 204: + + − + Figura 9.3.: Manter a con
- Page 205 and 206: Prova. Seja f um fluxo s-t. Temos 9
- Page 207 and 208: 9.1. Fluxos em redes aumentou nessa
- Page 209 and 210: 9.1. Fluxos em redes Figura 9.5.: R
- Page 211 and 212: V ′ = V ∪ {s ∗ , t ∗ } 9.1.
- Page 213 and 214: s 30 19 12 i 10 10 j 10 10 10 1010
- Page 215 and 216: Solução Um fluxo s-t f com valor
- Page 217 and 218: Objetivo Minimiza o valor c(M) de M
- Page 219 and 220: 9.2. Emparelhamentos Teorema 9.4 (B
- Page 221 and 222: 9.2. Emparelhamentos V1 e V2 com fl
- Page 223 and 224: 9.2. Emparelhamentos não sabemos c
- Page 225 and 226: 9.2. Emparelhamentos Sobre a implem
- Page 227 and 228: 9.2. Emparelhamentos reduzir o prob
- Page 229 and 230: v10 v9 v1 v8 v2 v3 v7 v6 v4 v5 v10
- Page 231 and 232: 10. Algoritmos de aproximação (As
- Page 233 and 234: 2 2 10.2. Aproximações para o PCV
- Page 235 and 236: 10.3. Algoritmos de aproximação p
- Page 237 and 238: 10.3. Algoritmos de aproximação p
8. <strong>Algoritmos</strong> <strong>de</strong> aproximação<br />
Como aproximar?<br />
• Idéia: Or<strong>de</strong>ne por vi/ti (“valor médio”) em or<strong>de</strong>m <strong>de</strong>crescente e enche<br />
o mochila o mais possível nessa or<strong>de</strong>m.<br />
Abordagem<br />
1 K−G(vi ,ti ) :=<br />
2 or<strong>de</strong>ne os i t e n s t a l que vi/ti ≥ vj/tj , ∀i < j .<br />
3 for i ∈ X do<br />
4 i f ti < M then<br />
5 S := S ∪ {i}<br />
6 M := M − ti<br />
7 end i f<br />
8 end for<br />
9 return S<br />
Aproximação boa?<br />
186<br />
• Consi<strong>de</strong>re<br />
• Então:<br />
v1 = 1, . . . , vn−1 = 1, vn = M − 1<br />
t1 = 1, . . . , tn−1 = 1, tn = M = kn k ∈ N arbitrário<br />
v1/t1 = 1, . . . , vn−1/tn−1 = 1, vn/tn = (M − 1)/M < 1<br />
• K-G acha uma solução com valor ϕ(x) = n−1, mas o ótimo é OPT(x) =<br />
M − 1.<br />
• Taxa <strong>de</strong> aproximação:<br />
OPT(x)/ϕ(x) =<br />
M − 1<br />
n − 1<br />
= kn − 1<br />
n − 1<br />
• K-G não possui taxa <strong>de</strong> aproximação fixa!<br />
≥ kn − k<br />
n − 1<br />
• Problema: Não escolhemos o item com o maior valor.<br />
= k