Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
6.6 KiB

  1. This a very high level review post that I am making for myself and other people taking CS Theory.
  2. If you want to lean about the theory behind the content in this blog post I recommed looking else where.
  3. This post will cover how to solve typical problems relating to topics covered by my second CS Theory exam.
  4. # Myhill-Nerode Theorem
  5. ## Definition
  6. L is regular if and only if it has a finite index. The index is the maximum number of elements thar are pairwise distibguishable.
  7. Two strings are said to be pairwise distinguishable if you can append something to both of the strings and it makes one string
  8. accepted by the language and the other string non-accepting.
  9. The size of an index set X equals the number of equivalence classes it has. Each element in the language is accepted by only
  10. one equivalence class.
  11. ## Problem Approach
  12. Prove that language L is regular.
  13. 1) Define a set X which is infinite in size - this doesn;t necesarrily need to be in the language.
  14. 2) Make a general argument that show that each element in X is pairwise distinguishable.
  15. Pick any two elements x, y in X and show that if you append z to them one is accepted by the language and
  16. the other is not in the language.
  17. ## Example
  18. Prove the following language is non-regular:
  19. $$
  20. L={ww^r | w \in {0,1}^*}
  21. $$
  22. answer:
  23. 1)
  24. $$
  25. X = {(01)^i | i \geq 0}
  26. $$
  27. Pick any 2 elements of X and show pairwise distinguishable
  28. $$
  29. x = (01)^i, y = (01)^j | i \neq j
  30. $$
  31. suppose we pick
  32. $$
  33. z = (10)^i\\
  34. xz \in L\\
  35. yz \notin L
  36. $$
  37. # DFA minimization algorithm
  38. Types of Problems:
  39. - Prove DFA is minimal
  40. - Minimize the DFA
  41. The argument for DFA minimization comes from the Myhill-Nerode theorem. Given
  42. a DFA, if you can form a set of strings which represent each state and they are all
  43. pairwise distinguishable, then the DFA is minimal with that many states.
  44. ## Prove DFA is minimal
  45. For these types of problems you simply construct a table and show that each state is pairwise distinguishable.
  46. To show pairwise distinguishably you have to show that there exists a string where if appended to one element
  47. makes it accepted by the language but pushes the other string out of the language.
  48. ### Example
  49. Prove the following DFA is minimal.
  50. ![DFA Example](media/CSTHEORY/DFAMinimalProof.png)
  51. Find a set of strings which represent the minimal path to each state in the DFA.
  52. $$
  53. X = \{\epsilon, b, bb, ba\}
  54. $$
  55. Show that each state is pairwise distinguishable.
  56. ![DFA Example](media/CSTHEORY/DFAMinimalTable.png)
  57. ## Minimize the DFA
  58. To use this concept of being indistinguishable to minimize a DFA, you can use a table to keep track which
  59. states are distinguishable from each other. The states which are not indistinguishable can
  60. be combined. To solve one of these problems you start by creating a table which compares each of the
  61. states in the DFA. You then go through and mark the states which are indistinguishable -- start with
  62. the ones with different accepting statuses. Then you continue marking off states where if you transition with
  63. a symbol on the DFA you are distinguishable and the other state is non-distinguishable according to the table.
  64. ### Example
  65. Minify the Following DFA:
  66. ![DFA Example](media/CSTHEORY/DFAMinification.png)
  67. After marking the states with different accepting criteria as being distinguishable you get this table:
  68. ![Half Complete Table](media/CSTHEORY/MinificationTable.svg)
  69. After looping through all pairs and marking them on the table if there exists symbol which results in one state
  70. to be distinguishable and one to be indistinguishable you get this table:
  71. ![Min TableTable](media/CSTHEORY/MinTable2.svg)
  72. According to the table you are able to combine {D, A, B}, {C, F}, and {E, G}.
  73. Minimal DFA:
  74. ![Min DFA](media/CSTHEORY/MinimalDFA.svg)
  75. # Pumping lemma for regular languages
  76. The pumping lemma cannot prove that a language is regular, however, you can use it
  77. to show that some languages are non-regular. This theory gets at the idea that if
  78. a regular language is long enough/infinite, it will have a state somewhere which is
  79. repeated on the path that accepts the string.
  80. The accepted strings can be divided into three parts:
  81. - Symbols leading up to the loop
  82. - Symbols which complete a loop and come back to start of loop
  83. - Symbols at the end of the string
  84. ![Min DFA](media/CSTHEORY/PumpingLemmaTheory.svg)
  85. To Show that a language L is not regular using pumping lemma:
  86. - Proof by Contradiction
  87. - Assume L is regular
  88. - Choose a representative string S which is just barely in the language and is represented in terms of p.
  89. - Express S = xyz such that |xy| < p and y > 0
  90. - Show that you can pump y some amount of times such that it is not in the language.
  91. - This contradicts the pumping lemma.
  92. - The assumption that L is regular is wrong.
  93. - L must not be regular.
  94. ## Example
  95. Show that the following language is non-regular.
  96. $$
  97. {0^n1^n | n \geq 0}
  98. $$
  99. Proof by contradiction
  100. Assume that L is regular.
  101. Let p be the pumping length associated with L
  102. $$
  103. S = o^p1^p
  104. $$
  105. S is valid since
  106. $$
  107. |s| \geq p, S \in L
  108. $$
  109. For any valid decomposition
  110. S = xyz
  111. such that |xy| <= p and |y| > 0
  112. Consider:
  113. $$
  114. xy^2z
  115. $$
  116. By the pumping lemma this should be in the language but it is not. Therefore our assumption that the
  117. language is regular is false.
  118. ![Min DFA](media/CSTHEORY/PumpingLemmaExample.svg)
  119. # Context-free grammars, closure properties for CFLs
  120. The context-free grammars are a superset of the regular languages. This means that CFG's can represent
  121. some non-regular languages and every regular language is also a CFL. Contest-free Languages are defined by Context-Free Grammars and accepted using
  122. Pushdown Automata machines.
  123. Context Free Grammars are Represented using:
  124. - **Terminals** = Set of symbols in that language
  125. - **Variables** = Set of symbols representing categories
  126. - **Start Symbol** = Variable which you start with- written on top
  127. - **Substitution Rules** = Set of rules that recursively define the language.
  128. ## Example 1
  129. Grammar G:
  130. $$
  131. A \rightarrow 0A1 \\
  132. A \rightarrow B \\
  133. B \rightarrow \# \\
  134. $$
  135. This grammar describes the following language:
  136. $$
  137. L = \{0^k\#1^k | k \geq 0\}
  138. $$
  139. ## Example 2
  140. Give CFG for non-Palindromes
  141. $$
  142. S \rightarrow aXb | bXa | aSa | bSb | ab | ba \\
  143. X \rightarrow aX | bX | a | b \\
  144. $$
  145. In this example, the S rule states in that recursive state until something that is not a palindrome is found.
  146. Once you exit the S state, you can finish by appending anything to the middle of the string.
  147. ## Example 3
  148. Give CFG for the following language:
  149. $$
  150. \{a^ib^jc^kd^l | i+k = j + l\}
  151. $$
  152. $$
  153. S \rightarrow aSd | XYZ \\
  154. X \rightarrow aXb | \epsilon\\
  155. Y \rightarrow bYc | \epsilon\\
  156. Z \rightarrow cZd | \epsilon
  157. $$
  158. # Parse trees, ambiguity
  159. # Chomsky Normal Form
  160. # Pushdown automata
  161. # Construction to convert CFG to a PDA