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/11 14:19]
pdmatei
aa:lab:12 [2025/01/23 14:09] (current)
dmihai
Line 1: Line 1:
-===== Lab 12: NP-hard and NP-complete problems ​=====+====== TDA-uri și inducție structurală ====== 
 +  ​
  
-Consider the following problems:+1. Definiți axiome pentru următorii operatori pe tipul ''​List''​:
  
-===k-Independent Set===+  * ''​reverse''​ (inversează elementele dintr-o listă) 
 +  * ''​filterEven''​ (elimină elementele impare dintr-o listă)
  
-Let $math[G=(V,​E)] be an undirected graph and $math[k] be a 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[G] are **independent**$math[\forall u,v \in V . (u,​v)\not\in E].+2Definiți axiome pentru următorii operatori pe tipul ''​BTree''​:
  
-**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.+  ​''​mirror ​BTree → BTree'' ​(arborele oglindit pe verticalăi.e. pentru orice nod, copilul stâng devine copilul drept și vice-versa) 
 +  ​''​flatten : BTree → List''​ (lista cu toate elementele din arbore; observați că există mai multe ordini posibile)
  
-===Subset Sum===+3. Definiți axiome pentru următorii operatori pe tipul ''​Map'':​
  
-Let $math[a_1, a_2, \ldots, a_n, b] be natural numbers. ​**Subset Sum** asks if there exist a subset of $math[a_1, a_2, \ldots, a_n] whose **sum** equals $math[b].+  ​''​update : Map × K × V → Map''​ (un Map cu o nouă asociere cheie:​element) 
 +  ​''​delete : Map × K → Map''​ (șterge cheia și valoarea asociată)
  
-**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**. ​+4. Demonstrați următoarele propoziții,​ folosind inducție structurală:
  
-===Partition===+  * $math[\forall t \in \texttt{BTree}. size(t) ​size(mirror(t))] 
 +  * $math[\forall t \in \texttt{BTree}. size(t) ​length(flatten(t))] 
 +  * $math[\forall l \in \texttt{List}. append(l, Empty) ​l] 
 +  * $math[\forall l_1, l_2, l_3 \in \texttt{List}. append(l_1, append(l_2, l_3)) append(append(l_1,​ l_2), l_3))] 
 +  * $math[\forall l_1, l_2 \in \texttt{List}. length(append(l_1,​ l_2)) length(append(l_2,​ l_1))] 
 +  * $math[\forall l_1, l_2 \in \texttt{List}. reverse(append(l_1,​ l_2)) append(reverse(l_2),​ reverse(l_1))].
  
-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 items between two people such that each one receives **equal** value. 
- 
-==== 1. Reductions ==== 
- 
-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. 
- 
-1.3. Prove that Independent set is NP-hard. 
- 
-1.4. Show that Partition $math[\leq_p] Subset Sum. 
- 
-==== 2.Properties of NP-hard and NP-complete problems ==== 
- 
-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] ? 
- 
-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. 
  
 +<​note>​
 +Soluțiile acestui laborator se găsesc [[https://​ocw.cs.pub.ro/​ppcarte/​doku.php?​id=aa:​lab:​sol:​12|aici]]
 +</​note>​