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:11 [2020/12/10 22:01]
fabianpatras
aa:lab:11 [2025/01/23 14:09] (current)
dmihai
Line 1: Line 1:
-====== Lab 10: SAT ======+===== Analiza amortizata ​=====
  
 +Utilizați metoda agregării, metoda contabilizării și metoda potențialelor pentru a găsi costul amortizat în situațiile prezentate mai jos.
  
-=== 0. Recap Conjunctive Normal ===+$ \DeclareMathOperator{\push}{push} \DeclareMathOperator{\pop}{pop} \DeclareMathOperator{\mpop}{mpop} \DeclareMathOperator{\key}{key} \DeclareMathOperator{\cost}{cost} $
  
 +=== 1. Stack ===
  
-**CNF** is form of boolean logic formulae that consists of a **conjunction** of one or more **clauses**. A **clause** is a **disjunction** of **literals**.+Presupunând că avem o implementare ​unei stive care permite operațiile $ \pop - O(1) $, $ \push - O(1) $ si $ \mpop(k) - O(k) $,  
 +demonstrați că pentru o secvență arbitrară $ S $ de $ n $ operatii, $ \cost(S) = O(n) $  
 +și că fiecare operație are un cost amortizat $ \cost(op) = O(1) $.
  
-A good analogy for **conjunction** is **product** and for **disjunction** is **sum**. Thusa formula in **CNF** can be seen as a product of sums.+**Exemplu:** $ \push\pop, \push, \push, \push, \mpop(2), \push, \pop, \push $
  
 +=== 2. Heap ===
  
-Examples of **terminals**:+Un max-heap este un arbore binar aproape complet - toate nivelurile, cu excepția ultimului, sunt complete, iar ultimul este completat de la stânga la dreapta. Fiecare două noduri AA și BB, unde BB este fiu al lui AA, satisfac relația: 
 +$ \key(B) \leq \key(A) $
  
-  * $math[X, Y, Z, a, b, X_{1}, X_{2}, ..., X_{n}]+Un max-heap se poate stoca sub formă de array, unde a[i] $ are  
 +copiii $ a[2i] $ si $ a[2i+1] $.
  
-Examples of **disjunctions**:+Adăugarea unui element constă în următorii pași: 
 +  - adaugă un element în prima poziție liberă de pe ultimul nivelele 
 +  - compară elementul adăugat cu părintele și interschimbă-i dacă e cazul 
 +  - repetă pasul anterior până nodul respectă proprietatea în raport cu părintele lui sau a devenit rădăcina
  
-  * $math[X\vee Y\vee Z] +Arătați că fiecare inserare are un cost agregat de $ \cost(op) = O(\log n) $.
-  * $math[a\vee b] +
-  * $math[X_{1}\vee X_{2}\vee X_{3}\vee ​... \vee X_{n - 1}\vee X_{n}]+
  
-Examples of **conjunctions**:​ 
  
-  * $math[a\wedge b\wedge c] +=== 3. Binary Counter ===
-  * $math[X\wedge ​ Z]+
  
-Examples of **CNF**: +Presupunând ​că avem un contor binar implementat folosind o listă de \( \) biți, acesta permite doar operația ​\( increment ​\), care adaugă ​\( 1 \) la contorAceastă operație are complexitate temporală ​\( O(k) \) în cel mai rău cazArătați însă ​că operația are un cost amortizat constant.
- +
-  * $math[a\wedge (b\vee ​c)\wedge d] +
-  * $math[(X_{1}\vee X_{2})\wedge (Y_{1}\vee Y_{2})\wedge (Z_{1}\vee Z_{2})+
-  * $math[(X\vee Y)\wedge (Y\vee Z)\wedge (Z\vee X)] +
- +
-\\  +
- +
-** 1. Conjunctive Normal Form ** +
- +
- +
-Rewrite the following formulae in Conjunctive Normal Form: +
- +
-** 1.1** $math[\neg (a\leftrightarrow b)\wedge ​(b\vee c)+
- +
- +
-** 1.2. ** $math[\neg ((a\vee c)\to (b \wedge \neg (a\vee c)))] +
- +
-\\  +
- +
-** 2Interpretations ** +
- +
-** 2.1. ** Write an interpretation which makes each of the previous formulae: +
-  * true +
-  * false +
- +
-\\  +
- +
-** 3. Satisfiability and validity ** +
- +
-Write down a formula with 3 variables which is: +
-  * valid +
-  * satisfiable +
-  * invalid +
- +
-\\  +
- +
-** 4. Binary Decision Diagrams ** +
- +
-Write binary decision diagrams for the formulae at 1. +
- +
-\\  +
- +
-** 5. Encodings ** +
- +
- +
-** 5.1. ** Express the following as ** CNF SAT ** formulae: +
- +
-    * $math[a\oplus b]  (xor) +
- +
-    * if then t else p +
-     +
-    * exactly one of $math[{X_{1},​ X_{2}, ..., X_{n}}] is true. +
- +
- +
-** 5.2. ** Encode the n-queens problem as a ** SAT ** formula. In the n-queens problem, we have a n x n board and we need to find a position for each n queens such that no queen is attacking another. +
- +
- +
-** 5.3. ** What is ** 3SAT **? Construct a transformation that takes a ** SAT ** formula and builds a ** 3SAT ** formula. Motivation: a lot of ** SAT ** solvers use as input ** 3SAT **.+
  
 +<​note>​
 +Soluțiile acestui laborator se găsesc [[https://​ocw.cs.pub.ro/​ppcarte/​doku.php?​id=aa:​lab:​sol:​11|aici]]
 +</​note>​