CSC 320 - Spring 2023

TA Tutorials.


Tutorial 01 - Introduction

Outline

A review on essential mathematical concepts and an overview on languages.

  1. countability: an overview of definitions

  2. set theory: a review on set theory and describing sets

  3. proof types: proof by contradiction, contrapositive, induction, and construction

  4. languages: a review on alphabets, symbols, strings, etc..

Countability

Set Theory

A Few Basic Definitions

A Few Basic Definitions

Describing Sets

Describe the following set in plain English:

\[\{x | x = 2m \text{ for each m in } \mathbb{N}, m > 5\}\]

Writing Sets

Write the following sets in set notation:

Proof Types

Contradiction

\[\text{Prove that $\sqrt{2}$ is an irrational number by contradiction.}\]

Remember: You’ll want to state your goal (i.e., prove that \(\sqrt{2}\) is an irrational number). You’ll then want to assume the opposite (i.e., assume that \(\sqrt{2}\) is a rational number). And finally, you’ll want to draw a conclusion that results in a contradiction (i.e., a statement that contradicts \(\sqrt{2}\) is a rational number). Lastly, you’ll need to write a formal conclusion.

Contrapositive

Let us consider the following \(p \longrightarrow q\) where we want to prove \(\urcorner q \longrightarrow \urcorner p\).

Example

Prove that for any integer \(n\), if \(n^{2}\) is even then \(n\) is even.

  1. Suppose \(n\) is odd.

  2. Prove that \(n^{2}\) is odd.

Induction

Example

Prove that \(1 + 2 + \cdots + n = n(n+1)/2\).

  1. Prove the base case(s).

  2. State the inductive hypothesis.

  3. Perform the inductive step(s).

  4. Write a formal conclusion.

Construction

Theorems often state that an object exists. Proof by Construction is a way to prove the theorem by constructing the object (i.e., proof by look here’s one).

Example

Prove that there is a program that can be used to calculate \(A + B\).

  1. Write a program that can calculate \(A + B\).

Languages - Review

Informally

Alphabets and Languages will be key components of this course.

Note: Even when given the exact same alphabet, you can create different languages.

Formally

Languages

Kleene star, \(L^{\ast}\), is the concatenation of all substrings of \(L\) with \(L\) (infinite).

Example

Consider the following:

\[L_{1} = \{00, 11\}\]

then

\[L_{1}^{\ast} = \{\epsilon, 00, 11, 0011, 1100, \cdots\}\]

where \(\ast\) means 0 or more occurrences

\[L_{1}^{+} = \{00, 11, 0011, 1100, \cdots\}\]

and where \(+\) means at least 1 occurrence.

Tutorial 02 - DFA, NFA, Union, and Kleene Star

Question - 2.1

Give the formal specification of a Deterministic Finite Automata (DFA) for the following language:

\[L = \{0\}^{\ast} \text{ over } \Sigma = \{0\}\]

Question 2.2

Give the formal specification of a DFA for the following language:

\[L = \{w \in \{a, b\}^{\ast} | w \text{ is any string not in } (ab^{+})^{\ast}\}\]

Question 2.3

Consider the following state diagram:

where the start state is \(B\), and state \(A\) and state \(D\) are accept states

and is described by the following transition table:

State Diagram - Transition Table
\(\delta\) \(0\) \(1\) \(\epsilon\)
\(A\) \(\emptyset\) \(A\) \(B\)
\(B\) \(\emptyset\) \(\emptyset\) \(\{A, C\}\)
\(C\) \(\{C, D\}\) \(C\) \(\emptyset\)
\(D\) \(\emptyset\) \(\emptyset\) \(\emptyset\)

(a) Is the string 0011 accepted by this state machine? How about 1100?

(b) What is the language of this machine?

Question 2.4

Design an Non-Deterministic Finite Automata (NFA) state diagram for the following language:

\[\{w \in \{0, 1\}^{\ast} | w \text{ contains } 00 \text{ or } 11 \text{ as a substring}\}\]

DFA Union Closure

Regular languages are closed under union.

What does "closed" mean?

A set \(S\) is closed under operation \(O\) if \(O(S) \in S\).

Let \(S = \{a, b, c\}\). Define \(O\) as such: \(O(a) = b\), \(O(b) = c\), and \(O(c) = a\).

Notice that applying \(O\) yields elements that are all in set \(S\). So \(S\) is closed under \(O\). If \(O\) were defined the same but \(O(c) = z\), then \(S\) is no longer closed under \(O\).

 

Kleene Star Proof

Prove that regular languages are closed under Kleene star.

 

Reduction Discussion

Reduction...

Problem A: Will Ammar Brush His Hair?

Problem B: Is Angela Happy?

Reduction:

\[A \longrightarrow B\]

"A reduces to B"

The outcome of \(A\) relies on the outcome of \(B\).

 

Tutorial 03 - Regular Expressions

Question 3.1

Design a regular expression for the following languages over the alphabet \(\Sigma = \{0, 1\}\):

(a) \(L_{1} = \{w | \text{every odd position of } w \text{ is a } 1\}\)

(b) \(L_{2} = \{w | w \text{ is a string of length at most } 5\}\)

(c) \(L_{3} = \{w | w \text{ contains an even number of } 0 \text{'s or exactly two } 1 \text{'s}\}\)

Question 3.2

Convert the following regular expression to an NFA:

\[R_{1} = (a \cup b^{\ast})a\]

DFA to Regular Expression

If a language is regular, then there exists some regular expression that describes it.

Transform the following Deterministic Finite Automata (DFA) into a Regular Expression:

DFA

where the DFA can be describe by the following:

\[DFA = (\{q_1, q_2\}, \{a, b\}, \delta, q_1, \{q_2\})\]

and \(\delta\) is defined as:

DFA - Transition Table
\(\delta\) \(a\) \(b\)
\(q_1\) \(q_1\) \(q_2\)
\(q_2\) \(q_1\) \(q_2\)

 

Tutorial 04 - Pumping Lemma

Question 4.1

Prove that the following language is not regular using the pumping lemma.

\[L_{1} = \{0^{n}1^{n}2^{n} | n \geq 0\}\]

 

Question 4.2

Prove that the following language is not regular using the pumping lemma.

\[L_{2} = \{w^{r}w | w \in \{0, 1\}^{\ast}\}\]

 

Reflection on Question 4.2

Why is the string \(s = 0^{P}0^{P}\) not a good choice to devise a contradiction to prove \(L_{2}\) is not regular?

 

Tutorial 05 - CFG, and CNF

Question 5.1

Consider the following language over \(\Sigma = \{0, 1\}\), find a set of rules that defines a Context Free Grammar (CFG) that recognizes the language:

\[L_{1} = \{0^{n}1^{n} | n \geq 0\} \cup \{1^{n}0^{n} | n \geq 1\}\]

Question 5.2

Consider the following language over \(\Sigma = \{0, 1\}\), find a set of rules that defines a CFG that recognizes the language:

\[L_{2} = \{w | w \text{ starts and ends with the same symbol}\}\]

Question 5.3

Consider the following language over \(\Sigma = \{0, 1\}\), find a set of rules that defines a CFG that recognizes the language:

\[L_{3} = \emptyset\]

Question 5.4

Consider the following language over \(\Sigma = \{0, 1\}\), find a set of rules that defines a CFG that recognizes the language:

\[L_{4} = \{w | w \text{ contains at least three } 1 \text{s}\}\]

Question 5.5

Consider the following language over \(\Sigma = \{0, 1\}\), find a set of rules that defines a CFG that recognizes the language:

\[L_{5} = \{0^{n}1^{m} | 2n \leq m \leq 3n\}\]

Question 5.6

Consider the following language over \(\Sigma = \{0, 1\}\), create a parse tree and show sequence derivations for the string \(000111\):

\[L_{6} = \{0^{n}1^{n} | n \geq 0\}\]

Question 5.7

Derive or generate the string "aabaa" for the following grammar:

\[\begin{aligned} S &\longrightarrow aAS | aSS | \epsilon \\ A &\longrightarrow SbA | ba \end{aligned}\]

 

Question 5.8

Convert the following CFG into Chomsky Normal Form (CNF):

\[\begin{aligned} S & \longrightarrow ASB \\ A & \longrightarrow aAS | a | \epsilon \\ B & \longrightarrow SbS | A | bb \end{aligned}\]

 

Question 5.9

Convert the following CFG into CNF:

\[\begin{aligned} S & \longrightarrow aXbX \\ X & \longrightarrow aY | bY | \epsilon \\ B & \longrightarrow X | c \end{aligned}\]

 

Question 5.10

Convert the following CFG into CNF:

\[\begin{aligned} S &\longrightarrow AAA | \epsilon \\ A &\longrightarrow aa | Aa | \epsilon \end{aligned}\]

 

Question 5.11

Complete the state diagram by adding missing transitions so that it describes a Push Down Automata (PDA) that recognizes the following language:

\[L = \{a^{m}b^{n} | m,n \geq 0 \text{ and (either } m = n \text{ or } m = n + 2 \text{)}\}\]

where the start state is \(s_1\), and state \(s_6\) is the accept state

and is described by the following transition table:

PDA - Transition Table
State Input Symbol Stack Symbol Next State Stack Operation
\(s_1\) \(s_2\)
\(s_1\) \(s_3\)
\(s_2\) \(s_2\)
\(s_2\) \(s_4\)
\(s_3\) \(s_3\)
\(s_3\) \(s_5\)
\(s_4\) \(s_4\)
\(s_4\) \(\epsilon\) \(\$\) \(s_6\) \(\epsilon\)
\(s_5\) \(s_4\)

 

Question 5.12

Prove or disprove that every subset of a Context Free Language (CFL) is a regular language.

 

Tutorial 06 - CFL Pumping Lemma, and TM

Question 6.1

Show that the following language is not a Context Free Language (CFL) using the CFL pumping lemma:

\[A = \{a^ib^jc^k | 0 \leq i \leq j \leq k\}\]

 

Question 6.2

Show that the following language is not CFL using the CFL pumping lemma:

\[B = \{0^{n} \# 0^{2n} \# 0^{3n}| n \geq 0\}\]

 

Question 6.3

Give a high level description of a Turing Machine which decides:

\[C = \{0^{2^{n}} | n \geq 0\}\]

Hint: Review page 143 in the Textbook.

Tutorial 07 - PDA, TM

Question 7.1

Construct a Push Down Automata (PDA) from the following Context Free Grammar (CFG):

\[S \longrightarrow S1 | 1S0S | \epsilon\]

 

Question 7.2

Give a high level description of a Turing Machine which decides:

\[A = \{0^{2^{n}} | n \geq 0\}\]

 

Question 7.3

Give a high level description of a Turing Machine which decides:

\[B = \{a^ib^jc^k | i \times j = k \text{ and } i, j, k \geq 1\}\]

 

Question 7.4

Give a high level description of a 2-tape Turing Machine which recognizes the language (binary palindromes):

\[L = \{w \in \{0, 1\}^{\ast} | w = w^r\}\]

 

Question 7.5

Give a high level description of a Non-Deterministic Turing Machine which recognizes the language:

\[L = \{1^n | n \text{ is a composite number}\}\]

 

Question 7.6

Prove that the following language is decidable by constructing a high level Turing Machine which decides the language:

\[A_{DFA} = \{ \langle B, w \rangle | B \text{ is a DFA that accepts input string } w\}\]

 

Question 7.7

Prove that the following language is decidable by constructing a high level Turing Machine which decides the language:

\[E_{DFA} = \{ \langle A \rangle | A \text{ is a DFA and } L(A) = \emptyset\}\]

 

Question 7.8

Prove that the following language is decidable by constructing a high level Turing Machine which decides the language:

\[EQ_{DFA} = \{ \langle A, B \rangle | A \text{ and } B \text{ are DFAs and } L(A) = L(B)\}\]

 

Tutorial 08 - TM, and Decidability

Question 8.1

Prove that the following language is decidable by constructing a high level Turing Machine which decides the language:

\[A_{DFA} = \{ \langle B, w \rangle | B \text{ is a DFA that accepts input string } w\}\]

 

Question 8.2

Prove that the following language is decidable by constructing a high level Turing Machine which decides the language:

\[E_{DFA} = \{ \langle A \rangle | A \text{ is a DFA and } L(A) = \emptyset\}\]

 

Question 8.3

Prove that the following language is decidable by constructing a high level Turing Machine which decides the language:

\[EQ_{DFA} = \{ \langle A, B \rangle | A \text{ and } B \text{ are DFAs and } L(A) = L(B)\}\]

 

Tutorial 09 - TM, Reduction, and Undecidability

Question 9.1

Prove that the following language is undecidable by reduction from \(A_{TM}\).

\[A_{TM} = \{\langle M, w \rangle | M \text{ is a TM and } M \text{ accepts } w\}\]

\[\text{Regular}_{TM} = \{\langle M \rangle | M \text{ is a TM and } L(M) \text{ is a regular language}\}\]

 

Question 9.2

Prove that the following language is undecidable by reduction from \(A_{TM}\).

\[A_{TM} = \{\langle M, w \rangle | M \text{ is a TM and } M \text{ accepts } w\}\]

\[S_{TM} = \{\langle M \rangle | M \text{ is a TM that accepts } w^r \text{ whenever it accepts } w\}\]

 

Question 9.3

Prove that the following language is undecidable by reduction from \(A_{TM}\).

\[A_{TM} = \{\langle M, w \rangle | M \text{ is a TM and } M \text{ accepts } w\}\]

\[S_{TM} = \{\langle A \rangle | A \text{ is a DFA and } L(A) = \emptyset\}\]

 

Question 9.4

Prove that the following language is undecidable by reduction from \(A_{TM}\).

\[A_{TM} = \{\langle M, w \rangle | M \text{ is a TM and } M \text{ accepts } w\}\]

\[E_{TM} = \{\langle M \rangle | M \text{ is a TM and } L(M) = \emptyset\}\]

 

Question 9.5

Prove that the following language is undecidable by reduction from \(ALL_{CFG}\).

\[ALL_{CFG} = \{\langle G \rangle | G \text{ is a CFG and } L(G) = \Sigma^{\ast}\}\]

\[EQ_{CFG} = \{\langle G, H \rangle | G \text{ and } H \text{ are CFGs and } L(G) = L(H)\}\]

 

Tutorial 10 - Polynomial Time, and Reduction

Question 10.1

NP-Completeness - Polynomial Time Reductions

Given an input \(\langle G, k \rangle\) for Clique, where \(G = (V, E)\) is an undirected graph and \(k\) is a positive integer. Use reduction to prove the following:

\[\text{Clique} \leq_{\text{p}} \text{Independent Set (IS)}\]

 

Question 10.2

NP-Completeness - Polynomial Time Reductions

Given an input \(\langle G, k \rangle\) for IS, where \(G = (V, E)\) is an undirected graph and \(k\) is a positive integer. Use reduction to prove the following:

\[\text{Independent Set (IS)} \leq_{\text{p}} \text{Vertex Cover (VC)}\]

 

Question 10.3

NP-Completeness - Polynomial Time Reductions

Let \(\langle G, k \rangle\), \(G = (V, E)\) and \(k \in \mathbb{N}\), be an instance for VC. Use reduction to prove the following:

\[\text{Vertex Cover (VC)} \leq_{\text{p}} \text{Dominating Set (DS)}\]

for graphs without singletons.

 

Question 10.4

NP-Completeness - Polynomial Time Reductions

Given an input \(\langle G, k \rangle\) for VC, where \(G = (V, E)\) is an undirected graph and \(k\) is a positive integer. Use reduction to prove the following:

\[\text{Vertex Cover (VC)} \leq_{\text{p}} \text{Independent Set (IS)}\]

 

Question 10.5

NP-Completeness - Polynomial Time Reductions

Given an input \(\langle G, k \rangle\) for IS, where \(G = (V, E)\) is an undirected graph and \(k\) is a positive integer. Use reduction to prove the following:

\[\text{Independent Set (IS)} \leq_{\text{p}} \text{Clique}\]

 

Question 10.6

Membership in NP - Verifiers

We remember that Non-Deterministic Polynomial Time (NP) is the set of languages for which there exists a polynomial time verifier. Thus, we can prove something is in NP by writing a verifier!

Verifiers

Verifiers take a problem and a potential solution \(C\) and checks if \(C\) is actually a solution or not.

Consider the following Graph Colouring problem:

Question 10.7

Membership in NP - Verifiers

Prove is in NP. \[\text{CLIQUE} = \{\langle G, k \rangle \: | \: G \text{ is a graph, } k \in \mathbb{Z}, k \geq 0.\}\] where there is a clique of at least size \(k\) in \(G\).

 

Question 10.8

Membership in NP - Verifiers

Prove is in NP. \[\text{INDSET} = \{\langle G, k \rangle \: | \: G \text{ is a graph, } k \in \mathbb{Z}, k \geq 0.\}\] where there is an independent set of at least \(k\) in \(G\).