Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
aa:lab:12 [2021/01/13 21:28]
claudiu.dorobantu Correct k-Independent-Set problem
aa:lab:12 [2026/01/19 12:58] (current)
dmihai
Line 1: Line 1:
-===== Lab 12: NP-hard and NP-complete problems ​=====+====== Abordări practice pentru probleme ​NP-Complete ======
  
-Consider the following problems:+Problemele NP-Complete despre care am discutat până acum la curs și la laborator au două trăsături principale:
  
-===k-Independent Set===+  * nu au soluții eficiente cunoscute 
 +  * sunt relevante practic
  
-Let $math[G=(V,​E)] be an undirected graph and $math[k] be natural number**k-Independent-Set** asks if there exists a subset $math[C\subseteq V] of size $math[k] of nodes from $math[G] such that all nodes from $math[C] ​are **independent**:​ $math[\forall u,v \in C, (u,v)\not\in E].+Trebuie deci să avem o strategie de le aborda, nu putem să le evităm. 
 +În acest laborator vom studia o strategie puternică numită //"​kernelizare"//​. 
 +Kernelizarea ​are la bază ideea că backtrackingul este inevitabil; dar în loc să aplicăm backtracking pe întreaga instanță a problemeiputem încerca a priori să //extragem miezul dificil al problemei//​. 
 +Această extragere constă în aplicarea unui algoritm determinist polinomial ​(deci //​eficient//​care să reducă drastic dimensiunea problemei. 
 +Este similar cu o reducere polinomială;​ dar în loc să transformăm inputul unei probleme ''​A''​ într-un input pentru o altă problemă ''​B'',​ îl vom transofrma într-un input mai mic pentru aceeași problemă ''​A''​.
  
-**Remark:** Let $math[G] be a **social network** where each edge $math[(u,​v)\in E] models friendship between participants $math[u] and $math[v]. **k-independent-set** asks if there exist a group of size $math[k] such that no two members of it are friends.+==== Vertex Cover ====
  
-===Subset Sum===+Vom implementa un algoritm simplu de kernelizare pentru problema Vertex Cover pe graful $ G (V, E)$ și dimensiunea căutată $ K$, care constă în următorii pași:
  
-Let $math[a_1, a_2, \ldots, a_n, b] be natural numbers**Subset Sum** asks if there exist a subset of $math[a_1a_2, \ldots, a_n] whose **sum** equals ​$math[b].+    * căutăm toate nodurile ​\in V$ cu $ grad(v) > K$ (gradul unui nod este numărul de muchii adiacente nodului)Dacă există un cover de dimensiune ​K$ aceste noduri trebuie să facă parte din el. Putem să le reținem separatapoi să le ștergem din graf și să decrementăm $ K$ pentru fiecare din ele. Căutăm în continuare un cover mai mic într-un graf mai mic. **Atenție!** După aplicarea acestei reguli, este posibil să o putem aplica din nou pe noul graf și noul $ K$.
  
-**Remark:** Imagine ​$math[a_1, a_2, \ldots, a_n] to be **weights** of various items identified as $math[1,2, \ldots, n] and that $math[b] is the **capacity** of a rucksack. **Subset sum** asks if you can pick a **combination** of items such that the rucksack can be **completely full**. ​+    ​Căutăm toate nodurile ​\in Vcu grad(v) = 0$; acestea pot fi eliminate
  
-===Partition===+    * Dacă graful obținut are mai mult de $ K^2$ (aici e vorba de $ K$-ul obținut prin transformări,​ nu neapărat $ K$ inițial) muchii, atunci graful nu poate conține un cover de dimensiune $ K$ (pentru că acum fiecare nod are grad maxim $ K$, deci $ K$ noduri pot acoperi maxim $ K \times K$ muchii); putem întoarce direct răspunsul negativ. Altfel, invocăm algoritmul de backtracking naiv pe noua instanță.
  
-Let $math[a_1, a_2, \ldots, a_n] be natural numbers. **Partition** asks if there exists a partitioning of $math[{a_1, \ldots, a_n}] into $math[P_1,​P_2] such that the sum of elements from one element of the partition equals that of the other. 
-  * how is a **partition** formally defined? 
  
-**Remark:** Imagine you have items each having a certain **value** ​$math[a_1, a_2, \ldots, a_n]**Partition** asks you to split those item +<​note>​ 
-s between two people such that each one receives **equal** value.+Pentru completitudine,​ trebuie să considerăm și situația ​K = 0$; în acest caz răspunsul e pozitiv dacă și numai dacă nu există muchii în graf
 +</​note>​
  
-==== 1Reductions ====+<​note>​ 
 +Ca să păstrăm analogia cu reduceri polinomiale (în care transformarea trebuie neapărat să producă o instanță a problemei și nu direct un răspuns) putem la ultimul pas, în caz că sunt mai mult de $ K^2$ muchii, să aplicăm backtracking naiv pe orice instanță despre care știm că răspunsul e negativ: e.g. întoarcem un graf cu două noduri, muchie între ele și $ K 0$. 
 +</​note>​
  
-1.1. Show that SAT $math[\leq_p] Subset Sum. Group discussion on the reduction in class. ​ 
  
-1.2. Prove that Partition is NP-hard. What are the steps to take? Build the reduction on your own.+==== Exerciții ====
  
-1.3. Prove that Independent set is NP-hard.+1. Implementați o soluție prin backtracking naiv pentru problema $ \texttt{VERTEX COVER}$; trebuie ca punctul de intrare să fie o funcție ''​solve_vertex_cover(<​graph>,​ <​k>​)''​.
  
-1.4Show that Partition $math[\leq_p] Subset Sum.+2Implementați pașii de preprocesare discutați mai sus. 
 +La final, aplicați funcția ''​solve_vetex_cover''​ pe graful și numărul obținut.
  
-==== 2.Properties of NP-hard and NP-complete problems ====+3. Implementați reducerea $ \texttt{CLIQUE} \le_P \texttt{VERTEX COVER}$; trebuie ca punctul de intrare să fie o funcție ''​solve_clique(<​graph>,​ <​k>​)''​. 
 +După reducerea grafului, aplicați preprocesarea prin kernelizare descrisă la punctul ​2.
  
-2.1. Identify a problem which is NP-hard but not NP-complete. Justify your answer. ​ 
  
-2.2. Suppose $math[f \leq_p g], $math[f] is NP-hard and $math[g] is in NP. Is it true that $math[g \leq_p f] ? +Găsiți {{:aa:lab:graph-example.zip|aici}} un exemplu de graf în următorul format:
- +
-2.3. What is an **equivalence class**? Show that the set of NP-complete problems is an equivalence class. +
- +
-==== 3. P vs NP ==== +
- +
-3.1. Suppose you find an algorithm which solves $math[SAT] in $math[O(n^4)] time. Is it true that $math[P = NP]? Justify your answer. What does this entail? +
- +
-3.2. Suppose that you find an algorithm $math[A] which can solve the problem of finding if **all subsets of size k** of nodes from a graph are **not** cliques in polynomial time. Does that entail $math[P = NP] or $math[P \neq NP]? Justify your answer. +
- +
-==== 4. Further work ==== +
- +
-4.1. How would you define the concept of a $math[P]-complete problem? How difficult (informally) would these problems be? +
- +
-4.2. Give an example ​of a $math[P]-complete problem.+
  
 +  * pe prima linie, o literă ''​U''​ sau ''​D''​ indică dacă graful este neorientat (**U**ndirected) sau orientat (**D**irected).
 +  * tot pe prima linie, seaparate cu un spațiu sunt numărul de noduri $ N$ și numărul de muchii $ M$
 +  * pe următoarele $ M$ linii sunt triplete: ID nod sursă, ID nod destinație,​ cost muchie (pentru grafuri neorientate,​ muchiile apar o singură dată, listate la nodul cu ID mai mic)
 +  * nodurile sunt indexate de la 0.
  
 +Este un graf complet cu 29 de noduri; are acoperiri doar de 28 și de 29 de noduri.