====== Laborator AA ======
===== Part 1 - Decidability - 4 labs =====
==== 1. Turing Machine ====
Key concepts:
- computation (the output of the tape) and acceptance (acceptare);
- mechanical description of an algorithm
- (Answers online - discussion) A **Turing Machine** consists of:
* an **alphabet** $math[\Sigma]
* a set of **states** $math[K]
* an **initial** state $math[q_0]
* a **transition function** $math[\delta : K \times \Sigma \rightarrow K \times \Sigma \times \{L,H,R\}]
* a set of **final** states $math[F \subseteq K]
Which of the following components of an **assembly language** would best correspond to the above? $math[K,\Sigma, \delta, q_0, F]
* the processor
* the memory
* registers
* assembly instructions
- (Answers online) What does the following TM do? (**bitwise complement**)
- (Answers online) Write a TM which **accepts** only if the **input** is a binary encoding of a **even** natural number.
- (Answers online) Write a TM which adds **5** to a number encoded in binary on the tape. The machine will always accept.
- (Answers online) Check if a symbol is present on the tape.
- (Discussion) How would the following algorithm be represented as a Turing Machine:
Algorithm(vector V, integer M) {
integer s = 0
for-each x in V
s += x
if (x > 1000)
then return 1
else return 0
}
Helpful questions:
* how should the tape be organised?
* when should the machine accept?
* how would ''foreach x in V'' be implemented?
* how would ''s += x'' be implemented?
* how would ''if (x > 1000) then ... else ...'' be implemented ?
Homework:
* Write a TM which verifies if a string has the **same number** of ones and zeroes. Give hints - live (what should the machine do?)
* write a TM which **accepts** a given regular expression
* write a TM which **reverses** a given binary string (always accepts)
==== 2. Turing Machines and Solvability ====
Key concepts:
* **acceptance** vs **decision**
* complement of a problem.
* Can the following problem be **accepted** by a TM? (f(x) = 0)
* What is the complement of this problem?
* Can a problem be accepted by two different TMs? Can a TM accept two different problems?
* If a problem is accepted by some TM, can its complement also be accepted?
* If a problem is **decided** by some TM, can its complement also be decided?
* Write a TM which accepts //is-odd// problem but which does not decide it.
* Which of the following problems you **think** can be **accepted** and which can be **decided**? Use pseudocode instead of writing a TM.
* a) V [[https://arxiv.org/pdf/1902.10188.pdf | Undecidable example 1]]
* b) V [[https://en.wikipedia.org/wiki/Hilbert%27s_tenth_problem | Hilbert undecidable ]]
* c) V [[https://en.wikipedia.org/wiki/Wang_tile | Wang Tile]]
* e) k-color
* f) Linear Integer Programming
==== 3. The Universal Turing Machine ====
Key concepts:
* simulation
Exercises:
* The Von Newmann architecture - explained.
* Which of the components of Von Newmann arch. corresponds best to the TM?
* Write a TM pseudocode which verifies if a word is the proper encoding of a TM.
Discussion on the pseudocode.
* Write a TM pseudocode which accepts if **there exists** a word which is accepted by a given TM in **k steps**.
Discussion on the pseudocode
* Which of the following is a suitable pseudocode for a TM:
Algoritm(M,w){
if size(w) > 10
then if M halts for w in k steps
accept.
}
Algoritm(M1,M2,w){
k = 0
while true
if M1(w) has the same behaviour as M2(w) after k steps
then accept
else k = k + 1
}
Algorithm(M,A) {
// A is a finite set of words
for each w in A
if M(w) halts //undecidable! Pseudocode is ok, but this machine may not terminate
then accept
}
Algorithm(M,w) {
build the machine M' such that M(x) accepts iff M'(x) does not accept, for all words x
if M'(w) in 1000 steps
accept
}
Algorithm(M1,M2) {
if M1 always halts then //we know of no procedure, terminating or not, which can achieve this. This is not a proper TM/algorithm.
if M2 always halts then
accept
}
* Write the problem which is accepted by each of the above machines.
* Write a TM pseudocode which accepts if a **given** word is accepted by two given TMs. Explain the dovetailing technique.
Homework:
* Write a TM pseudocode which accepts if **there exists** a word which is accepted by two given TMs.
* Write a TM pseudocode which accepts if **there exists** a TM which accepts a given word.
* Write a TM pseudocode which accepts if a given TM accepts **some** word of a given finite set A.
* Write a TM pseudocode which accepts if a given TM accepts **all** words of a given finite set A.
[[https://www.bbc.co.uk/bitesize/guides/zhppfcw/revision/3#:~:text=Von%20Neumann%20architecture%20is%20the,both%20stored%20in%20primary%20storage | Von Newmann Model]]
==== 4. Undecidable problems ====
Key concept:
* reduction
* proving a problem is not in R
* proving a problem is not in RE
===== Part 2 - Measuring algorithm performance (3 labs) =====
==== Notatii asimptotice ====
* (Homework) Implement mergesort and insertionsort in python. Use a large dataset (provided by us) to test your implementation. Plot the execution times together with the functions $math[n^2] and $math[n\cdot \log{n}] using ''gnuplot''. What do you observe? Adjust the constants for the previous functions so that the rate of growth can be better observed.
* Exercitii clasice
==== Recurente ====
* Cativa algoritmi si recurentele lor
* Merge-sort,
* Quick-sort (curs)
* Exemplul cu sqrt(n) al lui Sebi.
* Exercitii clasice
==== Ammortised Analysis ====
* Classical exercises
===== Part 3 - Algorithm complexity (4 labs) =====
==== NP completitudine ====
* Implement a SAT solver which encodes formulae as matrices and iterates over interpretations treating them as binary counters. Plot execution times.
* Implement a better SAT solver which uses BDDs to encode a formula. The variable ordering is known in advance. Plot execution times.
* Implement a k-Vertex-Cover solver using a reduction from SAT, and any of the above solvers.
* Exercitii clasice cu choice si reduceri
===== Part 4 - Abstract Datatypes (2 labs) =====
==== TDA-uri ====
* Conceptul de operator vs cel de functie (exercitiu in C, exercitiu in Haskell, pe Liste)
* (Homework) Implementare LinkedList si ArrayList in Python, impreuna cu operatii. Implementare Haskell a operatiilor, dupa o discutie la curs despre acestea.
* Exercitii clasice