0% found this document useful (0 votes)
136 views14 pages

Final Exam Study Guide - Automata ADU

Uploaded by

abinetblackman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views14 pages

Final Exam Study Guide - Automata ADU

Uploaded by

abinetblackman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Final Exam Study Guide

Coverage:
 Formal Language and Automata Theory, Regular Expression and Regular Languages,
Context Free Languages, Push Down Automata, Turing Machines, Computability and
Computational Complexity
Note: These are just guidelines; the exam may include some broader concepts.
You need to be able to understand, define and describe the following concepts in each
topic:
1. Formal Language and Automata Theory
- Formal Language: Elements, Properties and Types
- Finite Automata: Application, Types and Properties
2. Regular Expression and Regular Languages
- Algebraic Properties
- Describing regular languages
- Designing Finite Automata
3. Context Free Languages
- Derivation
- Properties
- Ambiguity and Parse Tree
- Simplification
4. Push Down Automata
- Description and Properties of PDA
5. Turing Machines
- Languages of TM
- Algorithm vs Procedure
- Computability Vs Decidability
- Undesirability
6. Computational Complexity
- P Class Problems
- NP Class Problems
- P vs NP Class Problems

In simple terms, when we say that recursively enumerable (RE) languages are accepted or
recognized by Turing Machines (TMs), we are referring to the ability of TMs to process and
determine if a given input string belongs to a certain language.

In the context of RE languages, there are two classes:


1. Class 1 (recursive language): For languages in this class, there exists a TM (which can be
thought of as an algorithm) that not only accepts strings belonging to the language but also
halts and provides an answer if a given input string is not part of the language.

1|Page
2. Class 2 (RE but not recursive): For languages in this class, there exists a TM that can
accept strings belonging to the language, but it may not halt or provide an answer if a given
input string is not part of the language.

In essence, Class 1 languages have TMs that can efficiently determine both membership
and non-membership of strings in the language, while Class 2 languages have TMs that may
not always be able to conclusively determine non-membership.

1. Formal Language and Automata Theory:


 Formal Language: A formal language is a set of strings over an alphabet. It consists of a set
of strings, each string being a finite sequence of symbols from the alphabet. The properties
of a formal language include:
 Closure: If L1 and L2 are formal languages, then the union, intersection, and concatenation
of L1 and L2 are also formal languages.
 Complement: The complement of a formal language L is the set of all strings not in L.
 Countability: A formal language is countable if there is a bijection between the strings in
the language and the natural numbers.
 Finite Automata: A finite automaton (FA) is a finite-state machine that can be in exactly one
of a finite number of states at any given time. There are three types of finite automata:
Deterministic Finite Automata (DFA), Non-deterministic Finite Automata (NFA), and ε-NFA
(NFA with empty transitions). The properties of a finite automaton include:
 Recognition: A finite automaton recognizes a language L if there is a sequence of states that
leads to an accepting state for every string in L.
 Emptiness: A finite automaton is empty if it has no accepting states.
 Universality: A finite automaton is universal if it can recognize any regular language.
2. Regular Expression and Regular Languages:
 Algebraic Properties: Regular expressions have the following algebraic properties:
 Closure: The union, intersection, and concatenation of regular expressions are also regular
expressions.
 Idempotence: The union or intersection of a regular expression with itself is the same
regular expression.

2|Page
 Nullability: The empty string is in every regular language.
 Describing Regular Languages: Regular languages can be described using regular
expressions, which are strings of symbols from a given alphabet. The symbols can be:
 Literals: Characters from the alphabet.
 ε: The empty string.
 ∪: Union of two languages.
 ∩: Intersection of two languages.
 *: Kleene star, representing zero or more occurrences of a language.
 Designing Finite Automata: To design a finite automaton for a given regular expression, we
can follow these steps:
 Start with the initial state.
 For each symbol in the regular expression, create a new state and add a transition from the
current state to the new state labeled with the symbol.
 If the symbol is a union or intersection, create a new state and add transitions from the
current states to the new state labeled with the symbol.
 If the symbol is a Kleene star, create a loop from the current state to itself labeled with the
symbol.
3. Context Free Languages:
 Derivation: A derivation is a sequence of rewrite rules that transforms a start symbol into a
string in a context-free language.
 Properties: Context-free languages have the following properties:
 Closure: If L1 and L2 are context-free languages, then the union, intersection, and
concatenation of L1 and L2 are also context-free languages.
 Emptiness: A context-free grammar is empty if it has no rules.
 Universality: A context-free grammar can generate any context-free language.
 Ambiguity and Parse Tree: An ambiguous grammar is a context-free grammar that has
more than one leftmost derivation for a given string. A parse tree is a tree representation of
a string in a context-free language, where each internal node represents a non-terminal
symbol, and each leaf node represents a terminal symbol.
 Simplification: To simplify a context-free grammar, we can remove unproductive symbols
(symbols that do not appear on the right-hand side of any rule) and unreachable symbols
(symbols that cannot be derived from the start symbol).
4. Push Down Automata:
 Description and Properties of PDA: A pushdown automaton (PDA) is a finite-state machine
with a stack. It can read input symbols, push symbols onto the stack, and pop symbols from
the stack. The properties of a pushdown automaton include:

3|Page
 Recognition: A pushdown automaton recognizes a language L if there is a sequence of
states and stack operations that leads to an empty stack for every string in L.
 Emptiness: A pushdown automaton is empty if it has no accepting states

Final Exam Study Guide: Formal Languages and Automata Theory

This guide helps you prepare for an exam covering Formal Languages and Automata
Theory. Remember, these are just guidelines, so the actual exam might include broader
concepts.
1. Formal Language and Automata Theory:
 Formal Language:
o Elements: Alphabets, strings, languages.
o Properties: Finiteness, emptiness, infiniteness, closure under operations (union,
concatenation, complement).
o Types: Regular languages, context-free languages, recursive languages.
 Finite Automata (FA):
o Application: Recognizing/generating strings in a language.
o Types: Deterministic Finite Automata (DFA), Non-Deterministic Finite Automata (NFA).
o Properties: Regularity, equivalence between DFA and NFA.
2. Regular Expression and Regular Languages:
 Algebraic Properties: Union, concatenation, closure.
 Describing Regular Languages: Using regular expressions.
 Designing Finite Automata: From regular expressions or given languages.
3. Context Free Languages (CFL):
 Derivation: Generating strings using grammar rules.
 Properties: Closure under concatenation, union, not closure under complement.
 Ambiguity and Parse Tree: Different derivations for the same string.
 Simplification: Removing useless symbols and productions.
4. Pushdown Automata (PDA):
 Description: Stack-based machines with states and transition rules.
 Properties: Recognizing context-free languages.

4|Page
5. Turing Machines (TM):
 Languages of TM: Any language, including non-computable ones.
 Algorithm vs Procedure: Algorithms have a guaranteed termination, procedures might
not.
 Computability vs Decidability: TM decides a language if it always halts with "accept"
or "reject".
 Undesirability Some languages are not decidable by any TM (e.g., Halting Problem).
6. Computational Complexity:
 P Class Problems: Solvable in polynomial time by a TM.
 NP Class Problems: Verifiable in polynomial time by a TM.
 P vs NP Class Problems: One of the biggest open questions: Is P equal to NP?
Additional Tips:
 Focus on understanding core concepts instead of just memorizing.
 Practice by solving problems from textbooks, past exams, or online resources.
 Form study groups to discuss and explain concepts to each other.
 Clarify any doubts with your instructor during office hours.
 Manage your time effectively during the exam, prioritizing concepts you understand
better.
Remember, this guide is a starting point. Explore additional resources, ask questions,
and practice actively to solidify your understanding and ace your exam!

HTML and XHTML Differences (with Examples):


 Structure: Both define webpage structure, but XHTML adheres to stricter XML syntax
(case-sensitivity, tags closed).
 Doctype: HTML utilizes <DOCTYPE html>, while XHTML uses <DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">.

5|Page
 Attributes: XHTML mandates quoting all attributes, even if empty. Example: <img
src="image.jpg" alt="My Image" /> (HTML) vs. <img src="image.jpg" alt="My

Image" /> (XHTML).

DOM (Document Object Model):


 A tree-like representation of an HTML document in JavaScript.
 Accessed using document.getElementById, document.getElementsByClassName, etc.
 Manipulated to dynamically change HTML content, attributes, and styles.
Text Highlighting Tag:
 Although no direct tag exists, various methods achieve highlighting:
o <mark>: Creates a highlighted area, but limited styling options.
o <span> with inline styles (e.g., background-color: yellow) for greater control.

o JavaScript for interactive and dynamic highlighting.


HTML Tags and Attributes:
 Tags: Define elements (headings, paragraphs, images, etc.), with <h1>-<h6> for
headings, <p> for paragraphs, <img> for images, <a> for links, and many more.
 Attributes: Provide additional information about tags (e.g., <img src="image.jpg"
alt="My Image">, <a href="https://www.example.com" target="_blank">Visit

Us</a>).

URL Components:
 Domain Name: Identifies the website (e.g., www.example.com).
 Port: Communication channel (usually 80 or 443).
 Path: Directory locating the specific content (e.g., /articles/2023/01/my-article).
 Query String: Parameters after ? (e.g., ?id=123&page=2).
 Fragment: Specific section within the content (e.g., #section2).
CSS Syntax:
 Selectors: Target HTML elements (e.g., h1, .my-class, #unique-id).
 Properties: Style aspects (e.g., color, font-family, background-color).
 Values: Define property behavior (e.g., red, Arial, #f0f).
 Declaration: Selector + property + value (e.g., h1 { color: red; }).
JS Variable Declaration:

6|Page
 var (functionally scoped, avoid due to hoisting issues).

 let (block-scoped, preferred for modern JavaScript).

 const (block-scoped, immutable value).

 Example: let age = 25; const firstName = "John";.


Content Management:
 Creating, editing, and managing website content without direct code modification.
 Systems like WordPress, Drupal, or Joomla provide user-friendly interfaces.
CSS Code and Explanation (3 marks):
CSS
h1 {
color: blue;
font-size: 2em;
text-align: center;
}

p {
margin: 1em 0;
line-height: 1.5;
}

Explanation:
 h1 styles: Sets heading text to blue, double the default size, and centers it.
 p styles: Adds 1em margin above and below paragraphs, and increases line spacing
for better readability.
Stylesheet Function and Output (5 marks):
 Function: Provide the stylesheet code you'd like explained.
JavaScript Output Question:
 Provide the JavaScript code you'd like the output for.
I'm ready to assist with these once you provide them!
I hope this improved response is helpful and informative!

1. Scheme :
https://
The protocol or scheme part of the URL and indicates the set of rules that will
decide the transmission and exchange of data. HTTPS which stands for
Hyper Text Transfer Protocol Secure tells the browser to display the page in
Hyper Text (HTML) format as well as encrypt any information that the user
enters in the page. Other protocols include the FTP or File Transfer Protocol
7|Page
which is used for transferring files between client and server, SMTP or Single
Mail Transfer Protocol which is used for sending emails.
2. Subdomain :
https://www.
The subdomain is used to separate different sections of the website as
it specifies the type of resource to be delivered to the client. Here the
subdomain used ‘www’ is a general symbol for any resource on the web.
Subdomains like ‘blog’ direct to a blog page, ‘audio’ indicates the resource type
as audio.
3. Domain Name :
https://www.example.
Domain name specifies the organization or entity that the URL belongs to.
Like in www.facebook.com the domain name ‘facebook’ indicates the
organization that owns the site.
4. Top-level Domain :
https://www.example.co.uk
The TLD (top-level domain) indicates the type of organization the website is
registered to. Like the .com in www.facebook.com indicates a commercial
entity. Similarly, .org indicates organization, .co.uk a commercial entity in the
UK.
5. Port Number :
https://www.example.co.uk:443
A port number specifies the type of service that is requested by the client
since servers often deliver multiple services. Some default port numbers
include 80 for HTTP and 443 for HTTPS servers.
6. Path :
https://www.example.co.uk:443/blog/article/search
Path specifies the exact location of the web page, file, or any resource that
the user wants access to. Like here the path indicates a specific article in the
blog webpage.
7. Query String Separator :
https://www.example.co.uk:443/blog/article/search?
The query string which contains specific parameters of the search is preceded
by a question mark (?). The question mark tells the browser that a specific
query is being performed.
8. Query String :
https://www.example.co.uk:443/blog/article/search?
docid=720&hl=en
The query string specifies the parameters of the data that is being queried
from a website’s database. Each query string is made up of a parameter and
a value joined by the equals (=) sign. In case of multiple parameters, query
strings are joined using the ampersand (&) sign. The parameter can be a
number, string, encrypted value, or any other form of data on the database.

8|Page
9. Fragment :
https://www.example.co.uk:443/blog/article/search?
docid=720&hl=en#dayone
The fragment identifier of a URL is optional, usually appears at the end, and
begins with a hash (#). It indicates a specific location within a page such as
the ‘id’ or ‘name’ attribute for an HTML element.
You might be surprised that though URLs seem to be trivial in nature, what your
URL looks like is actually a significant factor in Search Engine Optimization
(SEO). Feel free to check out more on URLs from here:
 https://developer.mozilla.org/enUS/docs/Learn/Common_questions/
What_is_a_URL
 https://www.hostgator.com/blog/best-url-structure-seo/
 Source: https://amberwilson.co.uk/blog/urls/

Automata theory, compatibility theory, and complexity theory are all fascinating
subfields of computer science, yet each explores different aspects of computation. Let's
dive into their distinctions and delve into examples:
Automata Theory:
 Focus: Abstract models of computation called automata. These automata, like finite
automata or Turing machines, manipulate symbols according to rules, simulating real-
world computations.
 Objective: Understand what languages (sets of strings) these automata can recognize
and process.
 Example: Imagine a vending machine recognizing valid coin sequences (e.g., "nickel-
dollar-quarter") using a finite automaton. Automata theory helps analyze if the machine
accepts only legitimate combinations.
Compatibility Theory:
 Focus: Relationships between different automata or formal languages.
 Objective: Determine if two automata can "mimic" each other's behavior or if two
languages share similar properties.
 Example: Consider two search algorithms for finding a specific word in a dictionary.
Compatibility theory checks if both algorithms produce the same results (compatible) or
differ fundamentally (incompatible).

9|Page
Complexity Theory:
 Focus: Resource requirements (e.g., time, memory) for solving computational
problems.
 Objective: Classify problems based on their difficulty and identify efficient solutions.
 Example: Sorting a list of numbers can be done quickly with simple algorithms, while
factoring large numbers is computationally expensive. Complexity theory classifies
these problems based on their inherent difficulty.
Key Differences:
 Automata theory studies the "what" (recognizable languages) of computation, while
compatibility theory focuses on the "how" (relationships between models) and
complexity theory on the "cost" (resource requirements).
 Automata and languages serve as building blocks in all three theories, but each
emphasizes different aspects.
I hope these explanations and examples clarify the unique perspectives each theory
offers on the vast world of computation!

## JavaScript and HTML DOM Explained with Examples

I'd be glad to explain the HTML DOM document object and its methods for finding,
changing, adding, and deleting elements, combining the strengths of previous responses
and addressing their shortcomings:

**HTML DOM Document Object:**

- The `document` object represents the entire HTML document loaded in the browser.
- It serves as the root node of the DOM tree, providing access to all other elements (child
nodes).
- Use JavaScript methods offered by the `document` object to interact with your web page
dynamically.

**Finding HTML Elements:**

**1. By ID:**

- Use `document.getElementById(id)` to find an element with a specific `id` attribute.


- Example:

10 | P a g e
```html
<button id="myButton">Click Me</button>

<script>
const button = document.getElementById("myButton");
button.addEventListener("click", function() {
alert("Button clicked!");
});
</script>
```

**2. By Tag Name:**

- Use `document.getElementsByTagName(name)` to find all elements with a particular tag


name.
- Note that this returns a live collection, so changes to the DOM will affect the result.
- Example:

```html
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<script>
const paragraphs = document.getElementsByTagName("p");
for (let i = 0; i < paragraphs.length; i++) {
paragraphs[i].style.color = "blue"; // Change all paragraphs to blue
}
</script>
```

**3. By Class Name:**

- Use `document.getElementsByClassName(name)` to find all elements with a specific class


name.
- Similar to `getElementsByTagName`, returns a live collection.
- Example:

```html
<h2 class="heading">This is a heading</h2>
<h3 class="heading">This is another heading</h3>

11 | P a g e
<script>
const headings = document.getElementsByClassName("heading");
for (let i = 0; i < headings.length; i++) {
headings[i].style.fontWeight = "bold"; // Make all headings bold
}
</script>
```

**Changing HTML Elements:**

**1. Inner HTML:**

- Use `element.innerHTML = new html content` to replace the entire HTML content within
an element.
- Example:

```html
<div id="message">Initial message</div>

<script>
const message = document.getElementById("message");
message.innerHTML = "<b>Updated message</b>"; // Make the message bold
</script>
```

**2. Attribute Value:**

- Use `element.attribute = new value` to directly change an attribute's value (not


recommended due to potential issues).
- Or, use `element.setAttribute(attribute, value)` for safer attribute manipulation.
- Example:

```html
<img src="image.jpg" alt="My Image">

<script>
const image = document.getElementById("myImage");
image.alt = "Updated image description"; // Set the alt text
// Or, using setAttribute:
image.setAttribute("alt", "Updated image description");
</script>
```

12 | P a g e
**3. Style:**

- Use `element.style.property = new style` to directly modify element styles.


- Example:

```html
<p id="myParagraph">Default paragraph</p>

<script>
const paragraph = document.getElementById("myParagraph");
paragraph.style.color = "red";
paragraph.style.fontSize = "1.5em"; // Make the paragraph red and larger
</script>
```

**Adding and Deleting Elements:**

**1. Create Element:**

- Use `document.createElement(element)` to create a new HTML element.


- Remember to append it to the DOM using `appendChild`.
- Example:

```html
<div id="container"></div>

<script>
const container = document.getElementById("container");
const newElement = document.createElement("p");
newElement.textContent = "This is a new paragraph";
container.appendChild(newElement); // Add the new paragraph to the container
</script>
```

**2. Remove Element:**

- Use `document.removeChild(element)` to remove an element from the DOM.


- Example:

```html
<button id="removeButton">Remove Paragraph</button>

13 | P a g e
<p id="removableParagraph">This paragraph will be removed</p>

<script>
const removeButton = document.getElementById("removeButton");
const paragraph = document.

14 | P a g e

You might also like