<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.categories.acsl.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Carlen</id>
	<title>ACSL Category Descriptions - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.categories.acsl.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Carlen"/>
	<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Special:Contributions/Carlen"/>
	<updated>2026-04-19T00:59:41Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&amp;diff=641</id>
		<title>Boolean Algebra</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&amp;diff=641"/>
		<updated>2020-03-17T15:27:45Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Laws */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;#039;&amp;#039;Boolean algebra&amp;#039;&amp;#039; is the branch of algebra in which the values of the variables and constants have exactly two values: &amp;#039;&amp;#039;true&amp;#039;&amp;#039; and &amp;#039;&amp;#039;false&amp;#039;&amp;#039;, usually denoted 1 and 0 respectively. &lt;br /&gt;
&lt;br /&gt;
The basic operators in Boolean algebra are &amp;#039;&amp;#039;and&amp;#039;&amp;#039;, &amp;#039;&amp;#039;or&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;not&amp;#039;&amp;#039;. The secondary operators are &amp;#039;&amp;#039;exclusive or&amp;#039;&amp;#039; (often called &amp;#039;&amp;#039;xor&amp;#039;&amp;#039;) and &amp;#039;&amp;#039;exclusive nor&amp;#039;&amp;#039; (sometimes called &amp;#039;&amp;#039;equivalence&amp;#039;&amp;#039;). They are secondary in the sense that they &lt;br /&gt;
can be composed from the basic operators.&lt;br /&gt;
*The &amp;#039;&amp;#039;and&amp;#039;&amp;#039; of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of  &amp;#039;&amp;#039;and&amp;#039;&amp;#039; for all possible inputs is shown in the following truth table:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x  y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
|} &lt;br /&gt;
&lt;br /&gt;
* The &amp;#039;&amp;#039;or&amp;#039;&amp;#039; of two values is true whenever either or both values are true. It is written as $x+y$. The values of  &amp;#039;&amp;#039;or&amp;#039;&amp;#039; for all possible inputs is shown in the following truth table:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x + y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
|} &lt;br /&gt;
&lt;br /&gt;
* The &amp;#039;&amp;#039;not&amp;#039;&amp;#039; of  a value is its opposite; that is, the &amp;#039;&amp;#039;not&amp;#039;&amp;#039; of a true value is false whereas the &amp;#039;&amp;#039;not&amp;#039;&amp;#039; of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of  &amp;#039;&amp;#039;not&amp;#039;&amp;#039; for all possible inputs is shown in the following truth table:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{x}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
|} &lt;br /&gt;
&lt;br /&gt;
* The &amp;#039;&amp;#039;xor&amp;#039;&amp;#039; of two values is true whenever the values are different.  It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of  &amp;#039;&amp;#039;xor&amp;#039;&amp;#039; for all possible inputs is shown in the following truth table:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x \oplus y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 0&lt;br /&gt;
|} &lt;br /&gt;
&lt;br /&gt;
*The &amp;#039;&amp;#039;xnor&amp;#039;&amp;#039; of two values is true whenever the values are the same. It is the &amp;#039;&amp;#039;not&amp;#039;&amp;#039; of the &amp;#039;&amp;#039;xor&amp;#039;&amp;#039; function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The &amp;#039;&amp;#039;xnor&amp;#039;&amp;#039; can be built from basic operators: $x \odot y = x  y + \overline{x}  \overline{y}$ The values of  &amp;#039;&amp;#039;xnor&amp;#039;&amp;#039; for all possible inputs is shown in the following truth table:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x \odot y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 1&lt;br /&gt;
|} &lt;br /&gt;
 &lt;br /&gt;
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.&lt;br /&gt;
&lt;br /&gt;
==Why is Boolean Algebra Important for ACSL Students?==&lt;br /&gt;
&lt;br /&gt;
Boolean algebra is important to programmers, computer scientists, and the general population. &lt;br /&gt;
&lt;br /&gt;
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
s = 0&lt;br /&gt;
x = 1&lt;br /&gt;
while (s &amp;lt; 100):&lt;br /&gt;
    if (x % 2 == 0) and (x % 3 != 0)&lt;br /&gt;
        then s = s + x&lt;br /&gt;
    x = x + 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Both the conditional statement &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;s &amp;lt; 100&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and the Boolean expression with 2 conditional statements  &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(x % 2 == 0) and (x % 3 != 0)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
evaluate to &amp;#039;&amp;#039;true&amp;#039;&amp;#039; or &amp;#039;&amp;#039;false&amp;#039;&amp;#039;. &lt;br /&gt;
&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer&amp;#039;s hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. &lt;br /&gt;
 &lt;br /&gt;
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression &amp;quot;jaguar speed -car is the Boolean expression &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;&amp;quot;jaguar&amp;quot; and &amp;quot;car&amp;quot; and not &amp;quot;speed&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;; it returns pages about the speed of the jaguar animal, not the Jaguar car.&lt;br /&gt;
&lt;br /&gt;
==Laws==&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;law&amp;#039;&amp;#039;&amp;#039; of Boolean algebra is an identity such as &amp;lt;math&amp;gt;x + (y + z) = (x + y) + z&amp;lt;/math&amp;gt;&lt;br /&gt;
between two Boolean terms, where a &amp;#039;&amp;#039;&amp;#039;Boolean term&amp;#039;&amp;#039;&amp;#039; is defined as an expression built up from variables,  the constants 0 and 1, and operations &amp;#039;&amp;#039;and&amp;#039;&amp;#039;, &amp;#039;&amp;#039;or&amp;#039;&amp;#039;, &amp;#039;&amp;#039;not&amp;#039;&amp;#039;, &amp;#039;&amp;#039;xor&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;xnor&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
Like ordinary algebra, parentheses are used to group terms. When a &amp;#039;&amp;#039;not&amp;#039;&amp;#039; is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$&lt;br /&gt;
&lt;br /&gt;
===Order of Precedence===&lt;br /&gt;
&lt;br /&gt;
The order of operator precedence is &amp;#039;&amp;#039;not&amp;#039;&amp;#039;; then &amp;#039;&amp;#039;and&amp;#039;&amp;#039;; then &amp;#039;&amp;#039;xor&amp;#039;&amp;#039; and &amp;#039;&amp;#039;xnor&amp;#039;&amp;#039;; and finally &amp;#039;&amp;#039;or&amp;#039;&amp;#039;. Operators with the same level of precedence are evaluated from left-to-right. &lt;br /&gt;
 &lt;br /&gt;
===Fundamental Identities===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ &lt;br /&gt;
|- &lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Associative Law – Regrouping of the terms in an expression doesn&amp;#039;t change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Idempotent Law – A term that is &amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;´ed or &amp;#039;&amp;#039;and&amp;#039;&amp;#039;´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Annihilator Law – A term that is &amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;´ed with 1 is 1; a term &amp;#039;&amp;#039;and&amp;#039;&amp;#039;´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Identity Law – A term &amp;#039;&amp;#039;or&amp;#039;&amp;#039;´ed 0 or  &amp;#039;&amp;#039;and&amp;#039;&amp;#039;´ed with a 1 will always equal that term. || $x + 0 = x$  || $x \cdot 1 = x$&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Complement Law – A term &amp;#039;&amp;#039;or&amp;#039;&amp;#039;´ed with its complement equals 1 and a term &amp;#039;&amp;#039;and&amp;#039;&amp;#039;´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|&lt;br /&gt;
$x+x  y = x$&lt;br /&gt;
&lt;br /&gt;
$ x +\overline{x}y = x + y $&lt;br /&gt;
&lt;br /&gt;
$x  (x+y) = x$&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Distributive Law – It&amp;#039;s OK to multiply or factor-out an expression.||colspan=2|&lt;br /&gt;
&lt;br /&gt;
$x \cdot (y + z) = xy + xz$&lt;br /&gt;
&lt;br /&gt;
$(x+y) \cdot (p + q) = xp + xq +yp + yq$&lt;br /&gt;
&lt;br /&gt;
$(x+y)(x+z)=x + yz $&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | DeMorgan&amp;#039;s Law – An &amp;#039;&amp;#039;or&amp;#039;&amp;#039; (&amp;#039;&amp;#039;and&amp;#039;&amp;#039;) expression that is negated is equal to the &amp;#039;&amp;#039;and&amp;#039;&amp;#039; (&amp;#039;&amp;#039;or&amp;#039;&amp;#039;) of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$&lt;br /&gt;
|- &lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ &lt;br /&gt;
|- &lt;br /&gt;
| style=&amp;quot;text-align: left&amp;quot; | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
Problems in this category are typically of the form &amp;quot;Given a Boolean expression, simplify it as much as possible&amp;quot; or &amp;quot;Given a Boolean expression,&lt;br /&gt;
find the values of all possible inputs that make the expression &amp;#039;&amp;#039;true&amp;#039;&amp;#039;.&amp;quot;  Simplify means writing an equivalent expression using the fewest number of operators.&lt;br /&gt;
&lt;br /&gt;
=== Problem 1: Simplify the Expression ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem:&amp;#039;&amp;#039;&amp;#039; Simplify the following expression as much as possible:&lt;br /&gt;
$ \overline{ \overline{A(A+B)} + B\overline{A}}$&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The simplification proceeds as follows:&lt;br /&gt;
&lt;br /&gt;
:$\overline{ \overline{A(A+B)} + B\overline{A}}$&lt;br /&gt;
::{| &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;math&amp;gt;= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)&amp;lt;/math&amp;gt; ||&lt;br /&gt;
|  (DeMorgan&amp;#039;s Law)&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)&amp;lt;/math&amp;gt; ||&lt;br /&gt;
|  (Double Negation; DeMorgan&amp;#039;s Law)&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;= A \cdot \left( \overline{B}+A\right)&amp;lt;/math&amp;gt; ||&lt;br /&gt;
|  (Absorption; Double Negation)&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;=A&amp;lt;/math&amp;gt;  || &lt;br /&gt;
| (Absorption)&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Problem 2: Find Solutions ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem:&amp;#039;&amp;#039;&amp;#039; Find all orderd pairs $(A,B)$ that make the following expression &amp;#039;&amp;#039;true&amp;#039;&amp;#039;:&lt;br /&gt;
$ \overline{ \overline{(A+B)} + \overline{A}B }$&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until&lt;br /&gt;
it&amp;#039;s obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.&lt;br /&gt;
&lt;br /&gt;
The simplification approach is as following:&lt;br /&gt;
:$ \overline{\overline{(A+B)} + \overline{A}B}$&lt;br /&gt;
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ &lt;br /&gt;
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ &lt;br /&gt;
::$= (A+B) \cdot (A+\overline{B}) $ &lt;br /&gt;
::$= AA + A\overline{B} + BA + B\overline{B} $ &lt;br /&gt;
::$= A + A(\overline{B} + B) + 0 $ &lt;br /&gt;
::$= A + A(1)$ &lt;br /&gt;
::$= A + A$ &lt;br /&gt;
::$=A$&lt;br /&gt;
This means that all inputs are valid whenever $A$ is &amp;#039;&amp;#039;true&amp;#039;&amp;#039;: $(1,0)$ and $(1,1)$&lt;br /&gt;
&lt;br /&gt;
The truth table approach is as following. Each column is the result of a basic operation on two other columns. &lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#1&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#2&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#3 &lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#4&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#5&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#6&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#7&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |#8&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff&amp;quot;|&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff&amp;quot;|&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |OR of Col#1, Col#2&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |NOT of Col#3&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |NOT of Col#1&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |ADD of Col#1, Col#2&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |OR of Col#4, Col#6&lt;br /&gt;
!style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; |NOT of Col#7 &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;A+B&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{A+B}&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{A}&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{A}B&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{A+B} + \overline{A}B&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{\overline{A+B} + \overline{A}B}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
!0&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
&lt;br /&gt;
|1&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
!0&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
&lt;br /&gt;
|1&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
!1&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
&lt;br /&gt;
|1&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
!1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The rightmost column is the expression we are solving; it is &amp;#039;&amp;#039;true&amp;#039;&amp;#039; for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.&lt;br /&gt;
&lt;br /&gt;
== Online Resources ==&lt;br /&gt;
&lt;br /&gt;
===Websites===&lt;br /&gt;
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan&amp;#039;s Tutorials].&lt;br /&gt;
&lt;br /&gt;
===Videos===&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you&amp;#039;ll &lt;br /&gt;
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/1cwO-FtybNw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/1cwO-FtybNw &amp;#039;&amp;#039;ACSL Prep - Mrs. Gupta - Boolean Algebra&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;MegaChristian5555&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/HJdhEjpVYsY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/HJdhEjpVYsY &amp;#039;&amp;#039;ACSL Boolean Algebra Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have&lt;br /&gt;
appeared in recent years. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/4io6xgz8Zwk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/4io6xgz8Zwk &amp;#039;&amp;#039;ACSL Boolean Algebra Contest 2 Worksheet 2&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;) ]&lt;br /&gt;
&lt;br /&gt;
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have&lt;br /&gt;
appeared in recent years. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/6vI1mO1XOjQ&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/6vI1mO1XOjQ &amp;#039;&amp;#039;ACSL 3 13-14 #1 - AM&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Gordon Campbell&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video walks through the solution to finding all ordered triples that make the following&lt;br /&gt;
Boolean expression &amp;#039;&amp;#039;true&amp;#039;&amp;#039;:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
This problem appeared in 2013-2014 in the Senior Division, Contest #3.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/KRKTbAZYlLM&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/KRKTbAZYlLM &amp;#039;&amp;#039;ACSL 3 #1 14-15 - AM&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Gordon Campbell&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video walks through the simplification of the expression:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
This problem appeared in 2014-2015 in the Senior Division, Contest #3.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jDnni-zm2g8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jDnni-zm2g8 &amp;#039;&amp;#039;A general tutorial on boolean algebra that can be used for American Computer Science League.&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through the simplification of the following Boolean expression:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\overline{ (\overline{A + \overline{B}})(AB)} +&lt;br /&gt;
\overline{ (A+B)(\overline{\overline{A}B})}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aGJALO57X7o&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aGJALO57X7o &amp;#039;&amp;#039;Boolean Algebra by Ravi Yeluru&amp;#039;&amp;#039; ]&lt;br /&gt;
&lt;br /&gt;
Walks through solving a handful of ACSL problems.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/-Iagy51n5bQ&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/-Iagy51n5bQ &amp;#039;&amp;#039;Boolean Algebra by Ravi Yeluru&amp;#039;&amp;#039; ]&lt;br /&gt;
&lt;br /&gt;
Walks through solving 4 ACSL problems.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=605</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=605"/>
		<updated>2018-10-10T01:26:45Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Sample Problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising all 4 of the following: 1) a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; 2) &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change the active state; 3) an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and 4) one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle, the final state as a double circle, the start state as the only state with an incoming arrow, and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules:  seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  &amp;quot;ab&amp;quot; (a followed by b).&lt;br /&gt;
::b. UNION. &amp;quot;aUb&amp;quot; or &amp;quot;a|b&amp;quot; (a or b).  &lt;br /&gt;
::c. CLOSURE. &amp;quot;a*&amp;quot; (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. &lt;br /&gt;
Similar to standard Algebra, parentheses can be used to group sub-expressions. &lt;br /&gt;
For example, &amp;quot;dca*b&amp;quot; generates strings dcb, dcab, dcaab, and so on, whereas&lt;br /&gt;
&amp;quot;d(ca)*b&amp;quot; generates strings db, dcab, dcacab, dcacacab, and so on.&lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A &amp;quot;most simplified&amp;quot; Regular Expression or FSA is not always well defined.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= RegEx in Practice =&lt;br /&gt;
&lt;br /&gt;
Programmers use Regular Expressions (usually referred to as &amp;#039;&amp;#039;&amp;#039;regex&amp;#039;&amp;#039;&amp;#039;) extensively for&lt;br /&gt;
expressing patterns to search for. All modern programming languages have regular expression libraries.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the specific syntax rules vary depending on the specific &lt;br /&gt;
implementation, programming language, or library in use. &lt;br /&gt;
Interactive websites for testing regexes are a useful resource for &lt;br /&gt;
learning regexes by experimentation. &lt;br /&gt;
An excellent online tool is [https://regex101.com/ https://regex101.com/]. &lt;br /&gt;
&lt;br /&gt;
Here are the additional syntax rules that we will use. They are pretty universal across all&lt;br /&gt;
regex packages. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|As described above, a vertical bar separates alternatives. For example, gray&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;grey can match &amp;quot;gray&amp;quot; or &amp;quot;grey&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
!*&lt;br /&gt;
|As described above, the asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches &amp;quot;ac&amp;quot;, &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on.&lt;br /&gt;
|-&lt;br /&gt;
!?&lt;br /&gt;
| The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both &amp;quot;color&amp;quot; and &amp;quot;colour&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! +&lt;br /&gt;
| The plus sign indicates one or more occurrences of the preceding element. For example, ab+c matches &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on, but not &amp;quot;ac&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! .&lt;br /&gt;
| The wildcard . matches any character. For example, a.b matches any string that contains an &amp;quot;a&amp;quot;, then any other character, and then a &amp;quot;b&amp;quot; such as &amp;quot;a7b&amp;quot;, &amp;quot;a&amp;amp;b&amp;quot;, or &amp;quot;arb&amp;quot;, but not &amp;quot;abbb&amp;quot;. Therefore, a.*b matches any string that contains an &amp;quot;a&amp;quot; and a &amp;quot;b&amp;quot; with 0 or more characters in between.  This includes &amp;quot;ab&amp;quot;, &amp;quot;acb&amp;quot;, or &amp;quot;a123456789b&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! [ ]&lt;br /&gt;
| A bracket expression matches a single character that is contained within the brackets. For example, [abc] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [a-z] specifies a range which matches any lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. These forms can be mixed: [abcx-z] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;, or &amp;quot;z&amp;quot;, as does [a-cx-z].&lt;br /&gt;
|-&lt;br /&gt;
! [^ ]&lt;br /&gt;
|Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [^a-z] matches any single character that is not a lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. Likewise, literal characters and ranges can be mixed.&lt;br /&gt;
|-&lt;br /&gt;
!( )&lt;br /&gt;
| As described above, parentheses define a sub-expression. For example, &lt;br /&gt;
the pattern H(ä|ae?)ndel  matches &amp;quot;Handel&amp;quot;, &amp;quot;Händel&amp;quot;, and &amp;quot;Haendel&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include:  translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 matches strings starting with one or more 0s followed by one or more 1s:  01, 001, 0001111, and so on. The RE 11*0*0 matches strings with one or more 1s followed by one or more 0s:  10, 1110, 1111100, and so on.  In other words, strings of the form:  0s followed by some 1s; or 1s followed by some 0s.  Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-D]*[a-d]*[0-9]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. ABCD8&lt;br /&gt;
::2. abcd5&lt;br /&gt;
::3. ABcd9&lt;br /&gt;
::4. AbCd7&lt;br /&gt;
::5. X&lt;br /&gt;
::6. abCD7&lt;br /&gt;
::7. DCCBBBaaaa5&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The pattern describes strings the start with zero or more uppercase letters A, B, C, or D (in any order), followed&lt;br /&gt;
by zero or more lowercase letter a, b, c, or d (in any order), followed by a single digit.&lt;br /&gt;
The strings that are represented by this pattern are 1, 2, 3, and 7.&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;Hi?g+h+[^a-ceiou]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. Highb&lt;br /&gt;
::2. HiiighS&lt;br /&gt;
::3. HigghhhC&lt;br /&gt;
::4. Hih&lt;br /&gt;
::5. Hghe&lt;br /&gt;
::6. Highd&lt;br /&gt;
::7. HgggggghX&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The ? indicates 0 or 1 &amp;quot;i&amp;quot;s. The + indicates 1 or more &amp;quot;g&amp;quot;s followed by 1 or more &amp;quot;h&amp;quot;s. &lt;br /&gt;
The ^ indicates that the last character cannot be lower-case a, b, c, e, i, o, or u.&lt;br /&gt;
The strings that are represented by this pattern are 3, 6, and 7. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 5 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-E|a-e]*(00[01])|([10]11)&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. DAD001&lt;br /&gt;
::2. bad000&lt;br /&gt;
::3. aCe0011&lt;br /&gt;
::4. AbE111&lt;br /&gt;
::5. AAAbbC&lt;br /&gt;
::6. aBBBe011&lt;br /&gt;
::7. 001011&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The [A-E|a-e]* allows for any of those letters in any order 0 or more times. Therefore, all of the &lt;br /&gt;
choices match at the beginning of the string. The end of the string must match &amp;quot;000&amp;quot;, &amp;quot;001&amp;quot;, &amp;quot;111&amp;quot;, &lt;br /&gt;
or &amp;quot;011&amp;quot;. That means that 1, 2, 4, and 6 match.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=604</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=604"/>
		<updated>2018-10-10T01:23:53Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Sample Problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising all 4 of the following: 1) a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; 2) &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change the active state; 3) an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and 4) one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle, the final state as a double circle, the start state as the only state with an incoming arrow, and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules:  seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  &amp;quot;ab&amp;quot; (a followed by b).&lt;br /&gt;
::b. UNION. &amp;quot;aUb&amp;quot; or &amp;quot;a|b&amp;quot; (a or b).  &lt;br /&gt;
::c. CLOSURE. &amp;quot;a*&amp;quot; (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. &lt;br /&gt;
Similar to standard Algebra, parentheses can be used to group sub-expressions. &lt;br /&gt;
For example, &amp;quot;dca*b&amp;quot; generates strings dcb, dcab, dcaab, and so on, whereas&lt;br /&gt;
&amp;quot;d(ca)*b&amp;quot; generates strings db, dcab, dcacab, dcacacab, and so on.&lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A &amp;quot;most simplified&amp;quot; Regular Expression or FSA is not always well defined.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= RegEx in Practice =&lt;br /&gt;
&lt;br /&gt;
Programmers use Regular Expressions (usually referred to as &amp;#039;&amp;#039;&amp;#039;regex&amp;#039;&amp;#039;&amp;#039;) extensively for&lt;br /&gt;
expressing patterns to search for. All modern programming languages have regular expression libraries.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the specific syntax rules vary depending on the specific &lt;br /&gt;
implementation, programming language, or library in use. &lt;br /&gt;
Interactive websites for testing regexes are a useful resource for &lt;br /&gt;
learning regexes by experimentation. &lt;br /&gt;
An excellent online tool is [https://regex101.com/ https://regex101.com/]. &lt;br /&gt;
&lt;br /&gt;
Here are the additional syntax rules that we will use. They are pretty universal across all&lt;br /&gt;
regex packages. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|As described above, a vertical bar separates alternatives. For example, gray&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;grey can match &amp;quot;gray&amp;quot; or &amp;quot;grey&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
!*&lt;br /&gt;
|As described above, the asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches &amp;quot;ac&amp;quot;, &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on.&lt;br /&gt;
|-&lt;br /&gt;
!?&lt;br /&gt;
| The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both &amp;quot;color&amp;quot; and &amp;quot;colour&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! +&lt;br /&gt;
| The plus sign indicates one or more occurrences of the preceding element. For example, ab+c matches &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on, but not &amp;quot;ac&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! .&lt;br /&gt;
| The wildcard . matches any character. For example, a.b matches any string that contains an &amp;quot;a&amp;quot;, then any other character, and then a &amp;quot;b&amp;quot; such as &amp;quot;a7b&amp;quot;, &amp;quot;a&amp;amp;b&amp;quot;, or &amp;quot;arb&amp;quot;, but not &amp;quot;abbb&amp;quot;. Therefore, a.*b matches any string that contains an &amp;quot;a&amp;quot; and a &amp;quot;b&amp;quot; with 0 or more characters in between.  This includes &amp;quot;ab&amp;quot;, &amp;quot;acb&amp;quot;, or &amp;quot;a123456789b&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! [ ]&lt;br /&gt;
| A bracket expression matches a single character that is contained within the brackets. For example, [abc] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [a-z] specifies a range which matches any lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. These forms can be mixed: [abcx-z] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;, or &amp;quot;z&amp;quot;, as does [a-cx-z].&lt;br /&gt;
|-&lt;br /&gt;
! [^ ]&lt;br /&gt;
|Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [^a-z] matches any single character that is not a lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. Likewise, literal characters and ranges can be mixed.&lt;br /&gt;
|-&lt;br /&gt;
!( )&lt;br /&gt;
| As described above, parentheses define a sub-expression. For example, &lt;br /&gt;
the pattern H(ä|ae?)ndel  matches &amp;quot;Handel&amp;quot;, &amp;quot;Händel&amp;quot;, and &amp;quot;Haendel&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include:  translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 matches strings starting with one or more 0s followed by one or more 1s:  01, 001, 0001111, and so on. The RE 11*0*0 matches strings with one or more 1s followed by one or more 0s:  10, 1110, 1111100, and so on.  In other words, strings of the form:  0s followed by some 1s; or 1s followed by some 0s.  Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-D]*[a-d]*[0-9]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. ABCD8&lt;br /&gt;
::2. abcd5&lt;br /&gt;
::3. ABcd9&lt;br /&gt;
::4. AbCd7&lt;br /&gt;
::5. X&lt;br /&gt;
::6. abCD7&lt;br /&gt;
::7. DCCBBBaaaa5&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The pattern describes strings the start with zero or more uppercase letters A, B, C, or D (in any order), followed&lt;br /&gt;
by zero or more lowercase letter a, b, c, or d (in any order), followed by a single digit.&lt;br /&gt;
The strings that are represented by this pattern are 1, 2, 3, and 7.&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;Hi?g+h+[^a-ceiou]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. Highb&lt;br /&gt;
::2. HiiighS&lt;br /&gt;
::3. HigghhhC&lt;br /&gt;
::4. Hih&lt;br /&gt;
::5. Hghe&lt;br /&gt;
::6. Highd&lt;br /&gt;
::7. HgggggghX&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The ? indicates 0 or 1 &amp;quot;i&amp;quot;s. The + indicates 1 or more &amp;quot;g&amp;quot;s followed by 1 or more &amp;quot;h&amp;quot;s. &lt;br /&gt;
The ^ indicates that the last character cannot be lower-case a, b, c, e, i, o, or u.&lt;br /&gt;
The strings that are represented by this pattern are 3, 6, and 7. &lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 5 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-E|a-e]*(00[01])|([10]11)&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. DAD001&lt;br /&gt;
::2. bad000&lt;br /&gt;
::3. aCe0011&lt;br /&gt;
::4. AbE111&lt;br /&gt;
::5. AAAbbC&lt;br /&gt;
::6. aBBBe011&lt;br /&gt;
::7. 001011&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The [A-E|a-e]* allows for any of those letters in any order 0 or more times. Therefore, all of the &lt;br /&gt;
choices match at the beginning of the string. The end of the string must match &amp;quot;000&amp;quot;, &amp;quot;001&amp;quot;, &amp;quot;111&amp;quot;, &lt;br /&gt;
or &amp;quot;011&amp;quot;. That means that 1, 2, 4, and 6 match.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=602</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=602"/>
		<updated>2018-10-08T19:14:58Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising all 4 of the following: 1) a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; 2) &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change the active state; 3) an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and 4) one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle, the final state as a double circle, the start state as the only state with an incoming arrow, and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules:  seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  &amp;quot;ab&amp;quot; (a followed by b).&lt;br /&gt;
::b. UNION. &amp;quot;aUb&amp;quot; or &amp;quot;a|b&amp;quot; (a or b).  &lt;br /&gt;
::c. CLOSURE. &amp;quot;a*&amp;quot; (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. &lt;br /&gt;
Similar to standard Algebra, parentheses can be used to group sub-expressions. &lt;br /&gt;
For example, &amp;quot;dca*b&amp;quot; generates strings dcb, dcab, dcaab, and so on, whereas&lt;br /&gt;
&amp;quot;d(ca)*b&amp;quot; generates strings db, dcab, dcacab, dcacacab, and so on.&lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A &amp;quot;most simplified&amp;quot; Regular Expression or FSA is not always well defined.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= RegEx in Practice =&lt;br /&gt;
&lt;br /&gt;
Programmers use Regular Expressions (usually referred to as &amp;#039;&amp;#039;&amp;#039;regex&amp;#039;&amp;#039;&amp;#039;) extensively for&lt;br /&gt;
expressing patterns to search for. All modern programming languages have regular expression libraries.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the specific syntax rules vary depending on the specific &lt;br /&gt;
implementation, programming language, or library in use. &lt;br /&gt;
Interactive websites for testing regexes are a useful resource for &lt;br /&gt;
learning regexes by experimentation. &lt;br /&gt;
An excellent online tool is [https://regex101.com/ https://regex101.com/]. &lt;br /&gt;
&lt;br /&gt;
Here are the additional syntax rules that we will use. They are pretty universal across all&lt;br /&gt;
regex packages. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|As described above, a vertical bar separates alternatives. For example, gray&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;grey can match &amp;quot;gray&amp;quot; or &amp;quot;grey&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
!*&lt;br /&gt;
|As described above, the asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches &amp;quot;ac&amp;quot;, &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on.&lt;br /&gt;
|-&lt;br /&gt;
!?&lt;br /&gt;
| The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both &amp;quot;color&amp;quot; and &amp;quot;colour&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! +&lt;br /&gt;
| The plus sign indicates one or more occurrences of the preceding element. For example, ab+c matches &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on, but not &amp;quot;ac&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! .&lt;br /&gt;
| The wildcard . matches any character. For example, a.b matches any string that contains an &amp;quot;a&amp;quot;, then any other character, and then a &amp;quot;b&amp;quot; such as &amp;quot;a7b&amp;quot;, &amp;quot;a&amp;amp;b&amp;quot;, or &amp;quot;arb&amp;quot;, but not &amp;quot;abbb&amp;quot;. Therefore, a.*b matches any string that contains an &amp;quot;a&amp;quot; and a &amp;quot;b&amp;quot; with 0 or more characters in between.  This includes &amp;quot;ab&amp;quot;, &amp;quot;acb&amp;quot;, or &amp;quot;a123456789b&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! [ ]&lt;br /&gt;
| A bracket expression matches a single character that is contained within the brackets. For example, [abc] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [a-z] specifies a range which matches any lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. These forms can be mixed: [abcx-z] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;, or &amp;quot;z&amp;quot;, as does [a-cx-z].&lt;br /&gt;
|-&lt;br /&gt;
! [^ ]&lt;br /&gt;
|Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [^a-z] matches any single character that is not a lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. Likewise, literal characters and ranges can be mixed.&lt;br /&gt;
|-&lt;br /&gt;
!( )&lt;br /&gt;
| As described above, parentheses define a sub-expression. For example, &lt;br /&gt;
the pattern H(ä|ae?)ndel  matches &amp;quot;Handel&amp;quot;, &amp;quot;Händel&amp;quot;, and &amp;quot;Haendel&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include:  translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 matches strings starting with one or more 0s followed by one or more 1s:  01, 001, 0001111, and so on. The RE 11*0*0 matches strings with one or more 1s followed by one or more 0s:  10, 1110, 1111100, and so on.  In other words, strings of the form:  0s followed by some 1s; or 1s followed by some 0s.  Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-D]*[a-d]*[0-9]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. ABCD8&lt;br /&gt;
::2. abcd5&lt;br /&gt;
::3. ABcd9&lt;br /&gt;
::4. AbCd7&lt;br /&gt;
::5. X&lt;br /&gt;
::6. abCD7&lt;br /&gt;
::7. DCCBBBaaaa5&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The pattern describes strings the start with zero or more uppercase letters A, B, C, or D (in any order), followed&lt;br /&gt;
by zero or more lowercase letter a, b, c, or d (in any order), followed by a single digit.&lt;br /&gt;
The strings that are represented by this pattern are 1, 2, 3, and 7.&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;Hi?g+h+[^a-ceiou]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. Highb&lt;br /&gt;
::2. HiiighS&lt;br /&gt;
::3. HigghhhC&lt;br /&gt;
::4. Hih&lt;br /&gt;
::5. Hghe&lt;br /&gt;
::6. Highd&lt;br /&gt;
::7. HgggggghX&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The ? indicates 0 or 1 &amp;quot;i&amp;quot;s. The + indicates 1 or more &amp;quot;g&amp;quot;s followed by 1 or more &amp;quot;h&amp;quot;s. &lt;br /&gt;
The ^ indicates that the last character cannot be lower-case a, b, c, e, i, o, or u.&lt;br /&gt;
The strings that are represented by this pattern are 3, 6, and 7. &lt;br /&gt;
&lt;br /&gt;
== Problem 5 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-E|a-e]*00[0?|1+]11&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. DAD0011111111&lt;br /&gt;
::2. bad0000000111&lt;br /&gt;
::3. aCe0010101011&lt;br /&gt;
::4. AbE000111&lt;br /&gt;
::5. AAAbbC0011&lt;br /&gt;
::6. aBBBe01&lt;br /&gt;
::7. 000000111111&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The [A-E|a-e]* allows for any of those letters in any order 0 or more times. Therefore, all of the&lt;br /&gt;
choices match at the beginning of the string. The end of the string must start with 00 and end with 11. &lt;br /&gt;
In between, there must be 0 or 1 &amp;quot;0&amp;quot;s or 1 or more &amp;quot;1&amp;quot;s.  That means that 1, 2, 4, and 7 match.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=600</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=600"/>
		<updated>2018-10-07T18:28:43Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising all 4 of the following: 1) a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; 2) &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change the active state; 3) an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and 4) one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle, the final state as a double circle, the start state as the only state with an incoming arrow, and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules:  seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  &amp;quot;ab&amp;quot; (a followed by b).&lt;br /&gt;
::b. UNION. &amp;quot;aUb&amp;quot; or &amp;quot;a|b&amp;quot; (a or b).  &lt;br /&gt;
::c. CLOSURE. &amp;quot;a*&amp;quot; (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. &lt;br /&gt;
Similar to standard Algebra, parentheses can be used to group sub-expressions. &lt;br /&gt;
For example, &amp;quot;dca*b&amp;quot; generates strings dcb, dcab, dcaab, and so on, whereas&lt;br /&gt;
&amp;quot;d(ca)*b&amp;quot; generates strings db, dcab, dcacab, dcacacab, and so on.&lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A &amp;quot;most simplified&amp;quot; Regular Expression or FSA is not always well defined.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= RegEx in Practice =&lt;br /&gt;
&lt;br /&gt;
Programmers use Regular Expressions (usually referred to as &amp;#039;&amp;#039;&amp;#039;regex&amp;#039;&amp;#039;&amp;#039;) extensively for&lt;br /&gt;
expressing patterns to search for. All modern programming languages have regular expression libraries.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the specific syntax rules vary depending on the specific &lt;br /&gt;
implementation, programming language, or library in use. &lt;br /&gt;
Interactive websites for testing regexes are a useful resource for &lt;br /&gt;
learning regexes by experimentation. &lt;br /&gt;
An excellent online tool is [https://regex101.com/ https://regex101.com/]. &lt;br /&gt;
&lt;br /&gt;
Here are the additional syntax rules that we will use. They are pretty universal across all&lt;br /&gt;
regex packages. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
! &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|As described above, a vertical bar separates alternatives. For example, gray&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;grey can match &amp;quot;gray&amp;quot; or &amp;quot;grey&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
!*&lt;br /&gt;
|As described above, the asterisk indicates zero or more occurrences of the preceding element. For example, ab*c matches &amp;quot;ac&amp;quot;, &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on.&lt;br /&gt;
|-&lt;br /&gt;
!?&lt;br /&gt;
| The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both &amp;quot;color&amp;quot; and &amp;quot;colour&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! +&lt;br /&gt;
| The plus sign indicates one or more occurrences of the preceding element. For example, ab+c matches &amp;quot;abc&amp;quot;, &amp;quot;abbc&amp;quot;, &amp;quot;abbbc&amp;quot;, and so on, but not &amp;quot;ac&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! .&lt;br /&gt;
| The wildcard . matches any character. For example, a.b matches any string that contains an &amp;quot;a&amp;quot;, then any other character, and then a &amp;quot;b&amp;quot; such as &amp;quot;a7b&amp;quot;, &amp;quot;a&amp;amp;b&amp;quot;, or &amp;quot;arb&amp;quot;, but not &amp;quot;abbb&amp;quot;. Therefore, a.*b matches any string that contains an &amp;quot;a&amp;quot; and a &amp;quot;b&amp;quot; with 0 or more characters in between.  This includes &amp;quot;ab&amp;quot;, &amp;quot;acb&amp;quot;, or &amp;quot;a123456789b&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! [ ]&lt;br /&gt;
| A bracket expression matches a single character that is contained within the brackets. For example, [abc] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [a-z] specifies a range which matches any lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. These forms can be mixed: [abcx-z] matches &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;, or &amp;quot;z&amp;quot;, as does [a-cx-z].&lt;br /&gt;
|-&lt;br /&gt;
! [^ ]&lt;br /&gt;
|Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, or &amp;quot;c&amp;quot;. [^a-z] matches any single character that is not a lowercase letter from &amp;quot;a&amp;quot; to &amp;quot;z&amp;quot;. Likewise, literal characters and ranges can be mixed.&lt;br /&gt;
|-&lt;br /&gt;
!( )&lt;br /&gt;
| As described above, parentheses define a sub-expression. For example, &lt;br /&gt;
the pattern H(ä|ae?)ndel  matches &amp;quot;Handel&amp;quot;, &amp;quot;Händel&amp;quot;, and &amp;quot;Haendel&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include:  translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 matches strings starting with one or more 0s followed by one or more 1s:  01, 001, 0001111, and so on. The RE 11*0*0 matches strings with one or more 1s followed by one or more 0s:  10, 1110, 1111100, and so on.  In other words, strings of the form:  0s followed by some 1s; or 1s followed by some 0s.  Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-D]*[a-d]*[0-9]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. ABCD8&lt;br /&gt;
::2. abcd5&lt;br /&gt;
::3. ABcd9&lt;br /&gt;
::4. AbCd7&lt;br /&gt;
::5. X&lt;br /&gt;
::6. abCD7&lt;br /&gt;
::7. DCCBBBaaaa5&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The pattern describes strings the start with zero or more uppercase letters A, B, C, or D (in any order), followed&lt;br /&gt;
by zero or more lowercase letter a, b, c, or d (in any order), followed by a single digit.&lt;br /&gt;
The strings that are represented by this pattern are 1, 2, 3, and 7.&lt;br /&gt;
&lt;br /&gt;
== Problem 5 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;Hi?g+h+[^a-ceiou]&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. Highb&lt;br /&gt;
::2. HiiighS&lt;br /&gt;
::3. HigghhhC&lt;br /&gt;
::4. Hih&lt;br /&gt;
::5. Hghe&lt;br /&gt;
::6. Highd&lt;br /&gt;
::7. HgggggghX&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The ? indicates 0 or 1 &amp;quot;i&amp;quot;s. The + indicates 1 or more &amp;quot;g&amp;quot;s followed by 1 or more &amp;quot;h&amp;quot;s. &lt;br /&gt;
The ^ indicates that the last character cannot be lower-case a, b, c, e, i, o, or u.&lt;br /&gt;
The strings that are represented by this pattern are 3, 6, and 7. &lt;br /&gt;
&lt;br /&gt;
== Problem 6 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;[A-E|a-e]*01[0?|1+]10&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::1. DAD0111111110&lt;br /&gt;
::2. bad01110&lt;br /&gt;
::3. aCe01000110&lt;br /&gt;
::4. AbE0101110&lt;br /&gt;
::5. AAAbbC01000001&lt;br /&gt;
::6. aBBBe010110&lt;br /&gt;
::7. 011111110&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The [A-E|a-e]* allows for any of those letters in any order 0 or more times. Therefore, all of the&lt;br /&gt;
choices match at the beginning of the string. The end of the string must start with 01 and end with 10. &lt;br /&gt;
In between, there must be 0 or 1 &amp;quot;0&amp;quot;s or 1 or more &amp;quot;1&amp;quot;s.  That means that 1, 2, 4, 6, and 7 match. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=593</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=593"/>
		<updated>2018-09-13T10:57:34Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change&lt;br /&gt;
the active state; an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA.  For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  “ab” (a followed by b).&lt;br /&gt;
::b. UNION. “aUb” (a or b).  &lt;br /&gt;
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
Identities for Regular Expressions appear in the next section.  The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union.  &lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined.  &lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Regular expressions are used in search engines, find and replace algorithms, and text editors.  Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|?&lt;br /&gt;
|Any single character&lt;br /&gt;
|-&lt;br /&gt;
|*&lt;br /&gt;
|Zero or more of the preceding character&lt;br /&gt;
|-&lt;br /&gt;
|#&lt;br /&gt;
|Any single digit&lt;br /&gt;
|-&lt;br /&gt;
|[char-char,char,…]&lt;br /&gt;
|Any inclusive range or list of characters&lt;br /&gt;
|-&lt;br /&gt;
|{![charlist]}&lt;br /&gt;
|Any character not in a given range or list&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!YES&lt;br /&gt;
!NO&lt;br /&gt;
!Why not?&lt;br /&gt;
|-&lt;br /&gt;
|App$5.java&lt;br /&gt;
|Help1.&lt;br /&gt;
|	E is not in the range [o-z].&lt;br /&gt;
|-&lt;br /&gt;
|Dog&amp;amp;2.py&lt;br /&gt;
|IoU$5&lt;br /&gt;
|There is no . at the end.&lt;br /&gt;
|-&lt;br /&gt;
|LzyG3.txt&lt;br /&gt;
|move6.py&lt;br /&gt;
|The m is not in the range [A-M].&lt;br /&gt;
|-&lt;br /&gt;
|Hot90.&lt;br /&gt;
|MaX7A.txt&lt;br /&gt;
|The A is not a digit from 0 to 9.&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 are strings starting with one or more 0s followed by one or more 1s:  01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s:  10, 1110, 1111100, and so on.  In other words, strings of the form:  0s followed by some 1s; or 1s followed by some 0s.  Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;?[A-D]*[a-d]*#&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 8AAAabd4&lt;br /&gt;
::B. MM5&lt;br /&gt;
::C. AAAAAAAA7&lt;br /&gt;
::D. Abcd9&lt;br /&gt;
::E. &amp;amp;dd88&lt;br /&gt;
::F. &amp;gt;BAD0&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The answer is A, C, D, and F.  In B, the character M is not in the range A-D or a-d.  In E, there cannot be more than 1 digit at the end of the string.  Remember that an asterisk represents 0 or more of that character or range of characters.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=592</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=592"/>
		<updated>2018-09-13T01:25:03Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Sample Problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change&lt;br /&gt;
the active state; an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA.  For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  “ab” (a followed by b).&lt;br /&gt;
::b. UNION. “aUb” (a or b).  &lt;br /&gt;
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
Identities for Regular Expressions appear in the next section.  The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union.  &lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined.  &lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|?&lt;br /&gt;
|Any single character&lt;br /&gt;
|-&lt;br /&gt;
|*&lt;br /&gt;
|Zero or more of the preceding character&lt;br /&gt;
|-&lt;br /&gt;
|#&lt;br /&gt;
|Any single digit&lt;br /&gt;
|-&lt;br /&gt;
|[char-char,char,…]&lt;br /&gt;
|Any inclusive range or list of characters&lt;br /&gt;
|-&lt;br /&gt;
|{![charlist]}&lt;br /&gt;
|Any character not in a given range or list&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!YES&lt;br /&gt;
!NO&lt;br /&gt;
!Why not?&lt;br /&gt;
|-&lt;br /&gt;
|App$5.java&lt;br /&gt;
|Help1.&lt;br /&gt;
|	E is not in the range [o-z].&lt;br /&gt;
|-&lt;br /&gt;
|Dog&amp;amp;2.py&lt;br /&gt;
|IoU$5&lt;br /&gt;
|There is no . at the end.&lt;br /&gt;
|-&lt;br /&gt;
|LzyG3.txt&lt;br /&gt;
|move6.py&lt;br /&gt;
|The m is not in the range [A-M].&lt;br /&gt;
|-&lt;br /&gt;
|Hot90.&lt;br /&gt;
|MaX7A.txt&lt;br /&gt;
|The A is not a digit from 0 to 9.&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 are strings starting with one or more 0s followed by one or more 1s:  01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s:  10, 1110, 1111100, and so on.  In other words, strings of the form:  0s followed by some 1s; or 1s followed by some 0s.  Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;?[A-D]*[a-d]*#&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 8AAAabd4&lt;br /&gt;
::B. MM5&lt;br /&gt;
::C. AAAAAAAA7&lt;br /&gt;
::D. Abcd9&lt;br /&gt;
::E. &amp;amp;dd88&lt;br /&gt;
::F. &amp;gt;BAD0&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The answer is A, C, D, and F.  In B, the character M is not in the range A-D or a-d.  In E, there cannot be more than 1 digit at the end of the string.  Remember that an asterisk represents 0 or more of that character or range of characters.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=591</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=591"/>
		<updated>2018-09-13T01:22:05Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of &amp;#039;&amp;#039;states&amp;#039;&amp;#039;, of which exactly one is &amp;#039;&amp;#039;active&amp;#039;&amp;#039; at any given time; &amp;#039;&amp;#039;transition rules&amp;#039;&amp;#039; to change&lt;br /&gt;
the active state; an &amp;#039;&amp;#039;initial state&amp;#039;&amp;#039;; and one or more &amp;#039;&amp;#039;final states&amp;#039;&amp;#039;. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. &lt;br /&gt;
&lt;br /&gt;
= Basics =&lt;br /&gt;
&lt;br /&gt;
Here is a drawing of an FSA that is used to parse strings consisting of x&amp;#039;s and y&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[File:fsa.svg|250px]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by &amp;#039;&amp;#039;seeing&amp;#039;&amp;#039; the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state so if the string being parsed is completed and the FSA is in State C, the input string is said to be &amp;#039;&amp;#039;accepted&amp;#039;&amp;#039; by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy).  &lt;br /&gt;
 &lt;br /&gt;
A Regular Expression (RE) is an algebraic representation of an FSA.  For example, the regular expression corresponding to the first FSA given above is xx*yy*. &lt;br /&gt;
&lt;br /&gt;
The rules for forming a Regular Expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  “ab” (a followed by b).&lt;br /&gt;
::b. UNION. “aUb” (a or b).  &lt;br /&gt;
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.&lt;br /&gt;
&lt;br /&gt;
Identities for Regular Expressions appear in the next section.  The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union.  &lt;br /&gt;
&lt;br /&gt;
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression.  Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA.  For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined.  &lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|?&lt;br /&gt;
|Any single character&lt;br /&gt;
|-&lt;br /&gt;
|*&lt;br /&gt;
|Zero or more of the preceding character&lt;br /&gt;
|-&lt;br /&gt;
|#&lt;br /&gt;
|Any single digit&lt;br /&gt;
|-&lt;br /&gt;
|[char-char,char,…]&lt;br /&gt;
|Any inclusive range or list of characters&lt;br /&gt;
|-&lt;br /&gt;
|{![charlist]}&lt;br /&gt;
|Any character not in a given range or list&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!YES&lt;br /&gt;
!NO&lt;br /&gt;
!Why not?&lt;br /&gt;
|-&lt;br /&gt;
|App$5.java&lt;br /&gt;
|Help1.&lt;br /&gt;
|	E is not in the range [o-z].&lt;br /&gt;
|-&lt;br /&gt;
|Dog&amp;amp;2.py&lt;br /&gt;
|IoU$5&lt;br /&gt;
|There is no . at the end.&lt;br /&gt;
|-&lt;br /&gt;
|LzyG3.txt&lt;br /&gt;
|move6.py&lt;br /&gt;
|The m is not in the range [A-M].&lt;br /&gt;
|-&lt;br /&gt;
|Hot90.&lt;br /&gt;
|MaX7A.txt&lt;br /&gt;
|The A is not a digit from 0 to 9.&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.&lt;br /&gt;
&lt;br /&gt;
= Regular Expression Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|-&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified Regular Expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following Regular Expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0.  The RE 00*1*1 are strings starting with one or more 0s followed by one or more 1s: 01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s: 10, 1110, 1111100, and so on. In other words, strings of the form: 0s followed by some 1s; or 1s &lt;br /&gt;
followed by some 0s. Choice A and E following this pattern.&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (a U b)(ab*)(b* U a)&lt;br /&gt;
::B. (aab* U bab*)a&lt;br /&gt;
::C. aab* U bab* U aaba U bab*a&lt;br /&gt;
::D. aab* U bab* U aab*a U bab*a&lt;br /&gt;
::E. a* U b*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Choice B can be discarded because it is the only RE whose strings &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; end with an a.  Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal.  After expanding choice A, we must compare it to choices C and D.  It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;?[A-D]*[a-d]*#&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 8AAAabd4&lt;br /&gt;
::B. MM5&lt;br /&gt;
::C. AAAAAAAA7&lt;br /&gt;
::D. Abcd9&lt;br /&gt;
::E. &amp;amp;dd88&lt;br /&gt;
::F. &amp;gt;BAD0&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The answer is A, C, D, and F.  In B, the character M is not in the range A-D or a-d.  In E, there cannot be more than 1 digit at the end of the string.  Remember that an asterisk represents 0 or more of that character or range of characters.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
Nice two-part video showing the relationship between FSAs and REs. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/GwsU2LPs85U&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/GwsU2LPs85U &amp;#039;&amp;#039;1 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/shN_kHBFOUE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/shN_kHBFOUE &amp;#039;&amp;#039;2 - Convert Regular Expression to Finite-State Automaton&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Barry Brown&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video uses the symbol &amp;quot;+&amp;quot; to mean &amp;quot;1 or more matches of the previous term&amp;quot;. For example, &amp;quot;ab+&amp;quot; is the same as &amp;quot;abb*&amp;quot;.  In terms of the Kleene Star, zz* = z*z = z+.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=570</id>
		<title>Data Structures</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=570"/>
		<updated>2018-09-09T22:09:45Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;At the heart of virtually every computer program are its algorithms and its data structures.  It is hard to separate these two items, for data structures are meaningless without algorithms to create and manipulate them, and algorithms are usually trivial unless there are data structures on which to operate.  The bigger the data sets, the more important data structures are in various algorithms.&lt;br /&gt;
&lt;br /&gt;
This category concentrates on four of the most basic structures:  &amp;#039;&amp;#039;&amp;#039;stacks&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;queues&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;binary search trees&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;priority queues&amp;#039;&amp;#039;&amp;#039;.  Questions will cover these data structures and implicit algorithms, not specific to implementation language details.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;stack&amp;#039;&amp;#039; is usually used to save information that will need to be processed later.  Items are processed in a “last-in, first-out” (LIFO) order.  A &amp;#039;&amp;#039;queue&amp;#039;&amp;#039; is usually used to process items in the order in which requests are generated; a new item is not processed until all items currently on the queue are processed.  This is also known as “first-in, first-out” (FIFO) order.  A &amp;#039;&amp;#039;binary search tree&amp;#039;&amp;#039; is used when one is storing items and needs to be able to efficiently process the operations of insertion, deletion, and query (i.e. find out if a particular item is found in the list of items and if not, which item is close to the item in question).  A &amp;#039;&amp;#039;priority queue&amp;#039;&amp;#039; is used like a binary search tree, except one cannot delete an arbitrary item, nor can one make an arbitrary query.  One can only find out or delete the smallest element of the list.&lt;br /&gt;
&lt;br /&gt;
There are many online resources covering these basic data structures; indeed there are many books and entire courses devoted to fundamental data structures. Implementation varies by computer language, but for our purposes, they can all be represented as a list of items that might contain duplicates.  The rest of this page is an overview of these structures.&lt;br /&gt;
&lt;br /&gt;
== Stacks and Queues ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;stack&amp;#039;&amp;#039; supports two operations:  PUSH and POP.  A command of the form PUSH(&amp;quot;A&amp;quot;) puts the key &amp;quot;A&amp;quot; at the top of the stack; the command “X = POP()” removes the top item from the stack and stores its value into variable X.  If the stack was empty (because nothing had ever been pushed on it, or if all elements have been popped off of it), then X is given the special value of NIL.  An analogy to this is a stack of books on a desk:  a new book is placed on the top of the stack (pushed) and a book is removed from the top also (popped).  Some textbooks call this data structure a “push-down stack” or a “LIFO stack”.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Queues&amp;#039;&amp;#039; operate just like stacks, except items are removed from the bottom instead of the top.  A command of the form PUSH(&amp;quot;A&amp;quot;) puts the key &amp;quot;A&amp;quot; at the top of the queue; the command “X = POP()” removes the item from the bottom of the queue and stores its value into variable X.  If the queue was empty (because nothing had ever been pushed on it, or if all elements have been popped off of it), then X is given the special value of NIL.  A good physical analogy of this is the way a train conductor or newspaper boy uses a coin machine to give change:  new coins are added to the tops of the piles, and change is given from the bottom of each.  Sometimes the top and bottom of a queue are referred to as the rear and the front respectively.  Therefore, items are pushed/enqueued at the rear of the queue and popped/dequeued at the front of the queue.  There is a similarity to the Britsh &amp;quot;queueing up&amp;quot;.  Some textbooks refer to this data structure as a “FIFO stack”.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence of 14 operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
PUSH(&amp;quot;A&amp;quot;)&lt;br /&gt;
PUSH(&amp;quot;M&amp;quot;)&lt;br /&gt;
PUSH(&amp;quot;E&amp;quot;)&lt;br /&gt;
X = POP()&lt;br /&gt;
PUSH(&amp;quot;R&amp;quot;)&lt;br /&gt;
X = POP()&lt;br /&gt;
PUSH(&amp;quot;I&amp;quot;)&lt;br /&gt;
X = POP()&lt;br /&gt;
X = POP()&lt;br /&gt;
X = POP()&lt;br /&gt;
X = POP()&lt;br /&gt;
PUSH(&amp;quot;C&amp;quot;)&lt;br /&gt;
PUSH(&amp;quot;A&amp;quot;)&lt;br /&gt;
PUSH(&amp;quot;N&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If these operations are applied to a stack, then the values of the pops are: E, R, I, M, A and NIL.  After all of the operations, there are three items still on the stack:  the N is at the top (it will be the next to be popped, if nothing else is pushed before the pop command), and C is at the bottom.  If, instead of using a stack we used a queue, then the values popped would be: A, M, E, R, I and NIL.  There would be three items still on the queue:  N at the top and C on the bottom.  Since items are removed from the bottom of a queue, C would be the next item to be popped regardless of any additional pushes.&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Trees&amp;#039;&amp;#039;, in general, use the following terminology:  the &amp;#039;&amp;#039;root&amp;#039;&amp;#039; is the top node in the tree; &amp;#039;&amp;#039;children&amp;#039;&amp;#039; are the nodes that are immediately below a &amp;#039;&amp;#039;parent&amp;#039;&amp;#039; node; &amp;#039;&amp;#039;leaves&amp;#039;&amp;#039; are the bottom-most nodes on every branch of the tree; and &amp;#039;&amp;#039;siblings&amp;#039;&amp;#039; are nodes that have the same immediate parent.  &lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;binary search tree&amp;#039;&amp;#039; is composed of nodes having three parts:  information (or a key), a pointer to a left child, and a pointer to a right child.  It has the property that the key at every node is always greater than or equal to the key of its left child, and less than the key of its right child.&lt;br /&gt;
&lt;br /&gt;
The following tree is built from the keys A, M, E, R, I, C, A, N in that order:&lt;br /&gt;
&lt;br /&gt;
[[File:bst-american.svg|200px]]&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;root&amp;#039;&amp;#039; of the resulting tree is the node containing the key A.  Our ACSL convention places duplicate keys into the tree as if they were less than their equal key.  (In some textbooks and software libraries, duplicate keys may be considered larger than their equal key.)  The tree has a &amp;#039;&amp;#039;depth&amp;#039;&amp;#039; (sometimes called height) of 3 because the deepest node is 3 nodes below the root.  The root node has a depth of 0.  Nodes with no children are called leaf nodes; there are four of them in the tree:  A, C, I and N.  Our ACSL convention is that an &amp;#039;&amp;#039;external node&amp;#039;&amp;#039; is the name given to a place where a new node could be attached to the tree. (In some textbooks, an external node is synonymous with a leaf node.)  In the final tree above, there are 9 external nodes; these are not drawn.  The tree has an &amp;#039;&amp;#039;internal path length&amp;#039;&amp;#039; of 15 which is the sum of the depths of all nodes.  It has an &amp;#039;&amp;#039;external path length&amp;#039;&amp;#039; of 31 which is the sum of the depths of all external nodes.  To insert the N (the last key inserted), 3 &amp;#039;&amp;#039;comparisons&amp;#039;&amp;#039; were needed against the root A (&amp;gt;), the M (&amp;gt;), and the R (≤).&lt;br /&gt;
&lt;br /&gt;
To perform an &amp;#039;&amp;#039;inorder&amp;#039;&amp;#039; traversal of the tree, recursively traverse the tree by first visiting the left child, then the root, then the right child.  In the tree above, the nodes are visited in the following order: A, A, C, E, I, M, N, and R.  A &amp;#039;&amp;#039;preorder&amp;#039;&amp;#039; travel (root, left, right) visits in the following order: A, A, M, E, C, I, R, and N.  A &amp;#039;&amp;#039;postorder&amp;#039;&amp;#039; traversal (left, right, root) is: A, C, I, E, N, R, M, A.  Inorder traversals are typically used to list the contents of the tree in sorted order. &lt;br /&gt;
&lt;br /&gt;
A binary search tree can support the operations insert, delete, and search.  Moreover, it handles the operations efficiently for &amp;#039;&amp;#039;balanced&amp;#039;&amp;#039; trees. In a tree with 1 million items, one can search for a particular value in about log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; 1,000,000 ≈ 20 steps.  Items can be inserted or deleted in about as many steps, too.  However, consider the binary search tree resulting from inserting the keys A, E, I, O, U, Y which places all of the other letters on the right side of the root &amp;quot;A&amp;quot;.  This is very unbalanced; therefore, sophisticated algorithms can be used to maintain balanced trees.  Binary search trees are “dynamic” data structures that can support many operations in any order and introduces or removes nodes as needed. &lt;br /&gt;
&lt;br /&gt;
To search for a node in a binary tree, the following algorithm (in pseudo-code) is used:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
p = root&lt;br /&gt;
found = FALSE&lt;br /&gt;
while (p ≠ NIL) and (not found)&lt;br /&gt;
  if (x &amp;lt; p’s key)&lt;br /&gt;
    p = p’s left child&lt;br /&gt;
  else if (x &amp;gt; p’s key)&lt;br /&gt;
    p = p’s right child&lt;br /&gt;
  else&lt;br /&gt;
    found = TRUE&lt;br /&gt;
  end if&lt;br /&gt;
end while&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Deleting from a binary search tree is a bit more complicated.  The algorithm we’ll use is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
p = node to delete&lt;br /&gt;
f = father of p&lt;br /&gt;
if (p has no children)&lt;br /&gt;
  delete p&lt;br /&gt;
else if (p has one child)&lt;br /&gt;
  make p’s child become f’s child&lt;br /&gt;
  delete p&lt;br /&gt;
else if (p has two children)&lt;br /&gt;
  l = p’s left child (it might also have children)&lt;br /&gt;
  r = p’s right child (it might also have children)&lt;br /&gt;
  make l become f’s child instead of p&lt;br /&gt;
  stick r onto the l tree&lt;br /&gt;
  delete p&lt;br /&gt;
end if&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These diagrams illustrate the algorithm using the tree above.  At the left, we delete I (0 children); in the middle, we delete the R (1 child); and at the right, we delete the M (2 children).&lt;br /&gt;
&lt;br /&gt;
{| class =&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:bst-american-del-i.svg|200px]]&lt;br /&gt;
|[[File:bst-american-del-r.svg|200px]]&lt;br /&gt;
|[[File:bst-american-del-m.svg|200px]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There are also general trees that use the same terminology, but they have 0 or more &amp;#039;&amp;#039;subnodes&amp;#039;&amp;#039; which can be accessed with an array or linked list of pointers.  &amp;#039;&amp;#039;Pre-order&amp;#039;&amp;#039; and &amp;#039;&amp;#039;post-order&amp;#039;&amp;#039; traversals are possible with these trees, but the other algorithms do not work in the same way.  Applications of general trees include game theory, organizational charts, family trees, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Balanced&amp;#039;&amp;#039; trees minimize searching time when every leaf node has a depth of within 1 of every other leaf node.  &amp;#039;&amp;#039;Complete&amp;#039;&amp;#039; trees are filled in at every level and are always balanced.  &amp;#039;&amp;#039;Strictly binary&amp;#039;&amp;#039; trees ensure that every node has either 0 or 2 subnodes.  You may want to consider how there are exactly 5 strictly binary trees with 7 nodes.&lt;br /&gt;
&lt;br /&gt;
== Priority Queues ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;priority queue&amp;#039;&amp;#039; is quite similar to a binary search tree, but one can only delete the smallest item and retrieve the smallest item only.  These insert and delete operations can be done in a guaranteed time proportional to the log (base 2) of the number of items; the retrieve-the-smallest can be done in constant time.  &lt;br /&gt;
&lt;br /&gt;
The standard way to implement a priority queue is using a &amp;#039;&amp;#039;heap&amp;#039;&amp;#039; data structure.  A heap uses a binary tree (that is, a tree with two children) and maintains the following two properties:  every node is less than or equal to both of its two children (nothing is said about the relative magnitude of the two children), and the resulting tree contains no “holes”.  That is, all levels of the tree are completely filled, except the bottom level, which is filled in from the left to the right.&lt;br /&gt;
&lt;br /&gt;
The algorithm for insertion is not too difficult:  put the new node at the bottom of the tree and then go up the tree, making exchanges with its parent, until the tree is valid.  &lt;br /&gt;
&amp;lt;!--here would be the place to show building the heap with AMERICAN--&amp;gt;&lt;br /&gt;
The heap at the left&lt;br /&gt;
was building from the letters A, M, E, R, I, C, A, N (in that order); the heap at the right is after a C has been added.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:heap-american.svg|220px]]||&lt;br /&gt;
[[File:heap-american-insert-c.svg|220px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The smallest value is always the root.  To delete it (and one can only delete the smallest value), one replaces it with the bottom-most and right-most element, and then walks down the tree making exchanges with the smaller child in order to ensure that the tree is valid.  The following pseudo-code formalizes this notion:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
b = bottom-most and right-most element&lt;br /&gt;
p = root of tree&lt;br /&gt;
p’s key = b’s key&lt;br /&gt;
delete b&lt;br /&gt;
while (p is larger than either child)&lt;br /&gt;
  exchange p with smaller child&lt;br /&gt;
  p = smaller child&lt;br /&gt;
end while&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the smallest item is at the root of the heap, the heap is called a &amp;#039;&amp;#039;min-heap&amp;#039;&amp;#039;. Of course,  A &amp;#039;&amp;#039;max-heap&amp;#039;&amp;#039; is also possible and is common in practice.  An efficient implementation of a heap uses an array that can be understood conceptually by using a tree data structure.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Consider an initially empty stack.  What is the value of Z when these operations are performed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
PUSH(3)&lt;br /&gt;
PUSH(6)&lt;br /&gt;
PUSH(8)&lt;br /&gt;
Y = POP()&lt;br /&gt;
X = POP()&lt;br /&gt;
PUSH(X-Y)&lt;br /&gt;
Z = POP()	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; The first POP() stores 8 in Y. The POP() stores 6 in X. Then, 8-6=2 is pushed onto the stack. Finally, the last POP() removes the 2 and stores it in Z.&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Create a min-heap with the letters in the word PROGRAMMING.  What are the letters in the bottom-most row, from left to right?&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; The bottom row contains the letters RORN, from left-to-right. Here is the entire heap:&lt;br /&gt;
[[File:heap-programming.svg|200px]]&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Create a binary search tree from the letters in the word PROGRAM.  What is the internal path length?	&lt;br /&gt;
&lt;br /&gt;
Solution:  When drawing the tree, P has a depth of 0, O and R have a depth of 1, G and R have a depth of 2, and A and M have a depth of 3. Therefore, the internal path length is 2*1 + 2*2 + 2*3 = 12. Here is the tree:&lt;br /&gt;
&lt;br /&gt;
[[File:bst-program.svg|200px]]&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
== ACSL Videos ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/gXj7K_petqo&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXj7K_petqo &amp;#039;&amp;#039;Data Structures (Stacks and Queues)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A general tutorial on stacks and queues.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/_BnbbOhyroQ&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/_BnbbOhyroQ &amp;#039;&amp;#039;Construct a Binary Search Tree&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows how to build a binary search tree from the letters &amp;#039;&amp;#039;&amp;#039;S U S H I&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/l9aMO7lgHj0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/l9aMO7lgHj0 &amp;#039;&amp;#039;Binary Search Tree ACSL Problem (Internal Path Length)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A general tutorial on internal path length of a binary search tree&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Other Videos ==&lt;br /&gt;
&lt;br /&gt;
There is no shortage of instructional video material covering basic data structures.  Here is a series that combines teaching concepts with showing Java code that implements the concepts.  Most of the ACSL questions will not involve coding the basic operations on the data structures; rather, the problems will involve high-level understanding of them.  However, seeing the code is an excellent way to thoroughly understand these data structures, and what it takes to implement them.&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/wjI1WNcIntg&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/wjI1WNcIntg &amp;#039;&amp;#039;Data Structures: Stacks and Queues&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;HackerRank&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
The first half of the video is a nice description of stacks and queues; the second half walks through very clean Java code that implements the fundamental methods on these data structures.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/njTh_OwMljA&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/njTh_OwMljA &amp;#039;&amp;#039;Data Structures: Linked Lists&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;HackerRank&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Although ACSL does not cover linked lists per se, they are a great preliminary study for binary search trees. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/oSWTXtMglKE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/oSWTXtMglKE &amp;#039;&amp;#039;Data Structures: Trees&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;HackerRank&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Learn about binary search trees. This video is a part of HackerRank&amp;#039;s &amp;#039;&amp;#039;Cracking The Coding Interview Tutorial&amp;#039;&amp;#039; with Gayle Laakmann McDowell. The first half of the video is a clear and eloquent description of binary search trees; the second half walks through very clean Java code that implements the fundamental methods. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/t0Cq6tVNRBA&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/t0Cq6tVNRBA &amp;#039;&amp;#039;Data Structures: Heaps&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;HackerRank&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Learn about heaps. This video is a part of HackerRank&amp;#039;s &amp;#039;&amp;#039;Cracking The Coding Interview Tutorial&amp;#039;&amp;#039; with Gayle Laakmann McDowell. The first half of the video is a clear and eloquent description of heaps; the second half walks through very clean Java code that implements the fundamental methods. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here are a few more videos covering the basics of binary search trees.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/FvdPo8PBQtc&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/FvdPo8PBQtc &amp;#039;&amp;#039;How to Construct a Binary Search Tree&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;edutechional&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;In this algorithm tutorial, I walk through how to construct a binary search tree given an unordered array, and then how to find elements inside of the tree.&amp;#039;&amp;#039;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=538</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=538"/>
		<updated>2018-09-08T03:07:45Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Other Videos */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A,B,C,D,E,F,G,H} and the set of edges {AB,AD,DA,DB,EG,GE,HG,HE,GF,CF,FC}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row &amp;#039;&amp;#039;i&amp;#039;&amp;#039; and column &amp;#039;&amp;#039;j&amp;#039;&amp;#039; indicates that there is an edge from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to &amp;#039;&amp;#039;j&amp;#039;&amp;#039;., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the &amp;#039;&amp;#039;pth&amp;#039;&amp;#039; power, the resulting matrix indicates which paths of length &amp;#039;&amp;#039;p&amp;#039;&amp;#039; exist in the graph.  The value in $M^p(i,j)$ is the number of paths from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to vertex &amp;#039;&amp;#039;j&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: ABA, BCDB, and CDC.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices:  V = {A, B, C, D}. There must be be exactly 7 edges: E = {AB, AD, BA, BD, CA, DB, DC}.  Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are dozens of YouTube videos that provide an introduction to graph theory. The following are a couple that we found particularly well done.  Be aware that the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=537</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=537"/>
		<updated>2018-09-08T03:05:46Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Problem 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A,B,C,D,E,F,G,H} and the set of edges {AB,AD,DA,DB,EG,GE,HG,HE,GF,CF,FC}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row &amp;#039;&amp;#039;i&amp;#039;&amp;#039; and column &amp;#039;&amp;#039;j&amp;#039;&amp;#039; indicates that there is an edge from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to &amp;#039;&amp;#039;j&amp;#039;&amp;#039;., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the &amp;#039;&amp;#039;pth&amp;#039;&amp;#039; power, the resulting matrix indicates which paths of length &amp;#039;&amp;#039;p&amp;#039;&amp;#039; exist in the graph.  The value in $M^p(i,j)$ is the number of paths from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to vertex &amp;#039;&amp;#039;j&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: ABA, BCDB, and CDC.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices:  V = {A, B, C, D}. There must be be exactly 7 edges: E = {AB, AD, BA, BD, CA, DB, DC}.  Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=536</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=536"/>
		<updated>2018-09-08T03:03:27Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Problem 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A,B,C,D,E,F,G,H} and the set of edges {AB,AD,DA,DB,EG,GE,HG,HE,GF,CF,FC}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row &amp;#039;&amp;#039;i&amp;#039;&amp;#039; and column &amp;#039;&amp;#039;j&amp;#039;&amp;#039; indicates that there is an edge from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to &amp;#039;&amp;#039;j&amp;#039;&amp;#039;., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the &amp;#039;&amp;#039;pth&amp;#039;&amp;#039; power, the resulting matrix indicates which paths of length &amp;#039;&amp;#039;p&amp;#039;&amp;#039; exist in the graph.  The value in $M^p(i,j)$ is the number of paths from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to vertex &amp;#039;&amp;#039;j&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: ABA, BCDB, and CDC.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=535</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=535"/>
		<updated>2018-09-08T03:01:54Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Adjacency Matrices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A,B,C,D,E,F,G,H} and the set of edges {AB,AD,DA,DB,EG,GE,HG,HE,GF,CF,FC}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row &amp;#039;&amp;#039;i&amp;#039;&amp;#039; and column &amp;#039;&amp;#039;j&amp;#039;&amp;#039; indicates that there is an edge from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to &amp;#039;&amp;#039;j&amp;#039;&amp;#039;., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the &amp;#039;&amp;#039;pth&amp;#039;&amp;#039; power, the resulting matrix indicates which paths of length &amp;#039;&amp;#039;p&amp;#039;&amp;#039; exist in the graph.  The value in $M^p(i,j)$ is the number of paths from vertex &amp;#039;&amp;#039;i&amp;#039;&amp;#039; to vertex &amp;#039;&amp;#039;j&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=534</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=534"/>
		<updated>2018-09-08T00:07:50Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Adjacency Matrices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A,B,C,D,E,F,G,H} and the set of edges {AB,AD,DA,DB,EG,GE,HG,HE,GF,CF,FC}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=533</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=533"/>
		<updated>2018-09-08T00:05:40Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Directed Graphs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A,B,C,D,E,F,G,H} and the set of edges {AB,AD,DA,DB,EG,GE,HG,HE,GF,CF,FC}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value&lt;br /&gt;
in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=532</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=532"/>
		<updated>2018-09-08T00:02:27Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Directed Graphs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
This graph is defined as the set of vertices V = {A, B, C, D, E, F} and the set of edges {AB, BC, CD, DE, EF,FG,HI}.  There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value&lt;br /&gt;
in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=531</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=531"/>
		<updated>2018-09-07T23:58:15Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Directed Graphs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
There is one directed path from G to C (namely, GFC); however, there are no directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D.  These dual arrows indicate that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graph with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value&lt;br /&gt;
in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=530</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=530"/>
		<updated>2018-09-07T23:54:18Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Trees */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  Minimal spanning trees can be found for weighted graphs (i.e. each edge has a cost or distance associated with it) in order to minimize the cost or distance across an entire network.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
There is one directed path from G to C (namely, GFC); however, the is no&lt;br /&gt;
directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D. That dual arrows says that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graphs with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value&lt;br /&gt;
in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=529</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=529"/>
		<updated>2018-09-07T23:50:32Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Terminology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B, D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V and the number of edges by E.  Note that E can range anywhere from V to V&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (or V(V-1)/2 in an undirected graph).  Graphs with all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
There is one directed path from G to C (namely, GFC); however, the is no&lt;br /&gt;
directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D. That dual arrows says that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graphs with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value&lt;br /&gt;
in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=528</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=528"/>
		<updated>2018-09-07T23:46:18Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;graph&amp;#039;&amp;#039; is a collection of vertices and edges.  An &amp;#039;&amp;#039;edge&amp;#039;&amp;#039; is a connection between two &amp;#039;&amp;#039;vertices&amp;#039;&amp;#039; (sometimes referred to as &amp;#039;&amp;#039;nodes&amp;#039;&amp;#039;).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but the graph is defined independently of the visual representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
::[[File:Graph fig1a.svg|150px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph fig1b.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G}, and its set of edges between these vertices {AB, AD, BD, CF, FG, GH, GE, HE}.&lt;br /&gt;
&lt;br /&gt;
To be precise, the graph above is an &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039;; the edge from x to y is the same as from y to x.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;path&amp;#039;&amp;#039; from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, FGHE is path from F to E in the graph above.  A &amp;#039;&amp;#039;simple path&amp;#039;&amp;#039; is a path with no vertex repeated.  For example, FGHEG is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is &amp;#039;&amp;#039;connected&amp;#039;&amp;#039; if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of &amp;#039;&amp;#039;connected components&amp;#039;&amp;#039;.  For example, the graph above has two connected components: {A, B,D} and {C, E, F, G, H}.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;cycle&amp;#039;&amp;#039; is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path HEGH is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, HEGH and EHGE are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V, the number of edges by E.  Note that E can range anywhere from V to V2 (or 1/2 V(V-1) in an undirected graph).  Graphs will all edges present are called &amp;#039;&amp;#039;complete graphs&amp;#039;&amp;#039;; graphs with relatively few edges present (say less than V log(V)) are called &amp;#039;&amp;#039;sparse&amp;#039;&amp;#039;; graphs with relatively few edges missing are called &amp;#039;&amp;#039;dense.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a &amp;#039;&amp;#039;tree&amp;#039;&amp;#039;.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A &amp;#039;&amp;#039;spanning tree&amp;#039;&amp;#039; of a graph is a subgraph that contains all the vertices and forms a tree.  A group of disconnected trees is called a &amp;#039;&amp;#039;forest.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Directed Graphs ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Directed graphs&amp;#039;&amp;#039; are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:Graph fig1a directed.svg|150px]]&lt;br /&gt;
&lt;br /&gt;
There is one directed path from G to C (namely, GFC); however, the is no&lt;br /&gt;
directed paths from C to G.  Note that a few of the edges have arrows on both ends, such as the edge between A and D. That dual arrows says that there is an edge in each direction, which essentially makes an undirected edge.  An &amp;#039;&amp;#039;undirected graph&amp;#039;&amp;#039; can be thought of as a directed graph with all edges occurring in pairs in this way.  A directed graphs with no cycles is called a &amp;#039;&amp;#039;dag&amp;#039;&amp;#039; (directed acyclic graph).&lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is an edge from vertex i to j., whereas a &amp;quot;zero&amp;quot; indicates there is not an edge. If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  The value&lt;br /&gt;
in $M^p(i,j)$ is the number of paths from vertex i to vertex j.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample1.svg|196px]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
::[[File:graph sample3.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix $M$ represent the graph.  Recall that the number of paths from vertex $i$ to vertex $j$ of length $p$ equals $M^p[i,j]$.  The values of $M$, $M^2$ and $M^4$ are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) &lt;br /&gt;
and 3 paths of length 4 (cell [1,3] in $M^4$).&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
There must be exactly 4 vertices: A, B, C, and D. There must be be exactly 7 edges: AB, AD, BA, BD, CA, DB, and DC. Here are two valid drawings of the graph:&lt;br /&gt;
&lt;br /&gt;
: [[File:Graph sample4soln-a.svg|128px]] &amp;lt;span style=&amp;quot;display:inline-block; width: 5em;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;[[File:Graph sample4soln-d.svg|128px]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
===ACSL Videos===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/H96Lo2q_FSk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/H96Lo2q_FSk &amp;#039;&amp;#039;ACSL - Graph Theory Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the ACSL problem: &amp;#039;&amp;#039;&amp;#039;Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/y1fdIb_oNG0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/y1fdIb_oNG0 &amp;#039;&amp;#039;ACSL Graph Theory Worksheet 3&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vtTCRMGB0K8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vtTCRMGB0K8 &amp;#039;&amp;#039;Graph Theory ACSL Example Problem&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to an ACSL problem asking to find how many different cycles there are from a specific vertex in a specific directed graph.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Videos===&lt;br /&gt;
&lt;br /&gt;
There are many dozens of YouTube videos that cover introductions to graph theory. The following are a couple that we found particularly nicely done.  Be aware thqt the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/44sQJK4BycY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/44sQJK4BycY &amp;#039;&amp;#039;CS 106B Lecture: Graphs: basic concepts&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
This lecture from Stanford University is s wonderful introduction to graph theory. The lecture starts out with many examples of real world problems that are modeled by graphs, and then moves on to review basic terminology relating to graph theory. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt; https://youtu.be/gXgEDyodOJU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gXgEDyodOJU &amp;#039;&amp;#039;Data structures: Introduction to Graphs&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;(mycodeschool)&amp;#039;&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
A nice introduction to the fundamental concepts of graphs. &lt;br /&gt;
 &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=LISP&amp;diff=517</id>
		<title>LISP</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=LISP&amp;diff=517"/>
		<updated>2018-09-07T10:50:50Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* List Functions (CAR, CDR, CONS, REVERSE) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;LISP is one of the simplest computer languages in terms of syntax and semantics, and also one of the most powerful.  It was developed in the mid-1950’s by John McCarthy at M.I.T. as a “LISt Processing language.”  It has been historically used for virtually all Artificial Intelligence programs and is often the environment of choice for applications which require a powerful interactive working environment.  LISP presents a very different way to think about programming from the “algorithmic” languages, such as Python, C++, and Java.&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
As its name implies, the basis of LISP is a list.  One constructs a list by enumerating elements inside a pair of parentheses.  For example, here is a list with four elements (the second element is also a list):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;(23 (this is easy) hello 821)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The elements in the list, which are not lists, are called “atoms.”  For example, the atoms in the list above are: 23, ‘this, ‘hello, 821, ‘easy, and ‘is.  Literals are identified with a single leading quote.  Everything in LISP is either an atom or a list (but not both).  The only exception is “NIL,” which is both an atom and a list.  It can also be written as “()” – a pair of parentheses with nothing inside.&lt;br /&gt;
&lt;br /&gt;
All statements in LISP are function calls with the following syntax: (function arg1 arg2 arg3 … argn).  To evaluate a LISP statement, each of the arguments (possibly functions themselves) are evaluated, and then the function is invoked with the arguments.  For example, (MULT (ADD 2 3) (ADD 1 4 2)) has a value of 35, since (ADD 2 3) has a value of 5, (ADD 1 4 2) has a value of 7, and (MULT 5 7) has a value of 35.  Some functions have an arbitrary number of arguments; others require a fixed number.  All statements return a value, which is either an atom or a list. &lt;br /&gt;
&lt;br /&gt;
== Basic Functions (SET, SETQ, EVAL, ATOM) ==&lt;br /&gt;
&lt;br /&gt;
We may assign values to variables using the function SET.  For example, the statement (SET ’test 6) would have a value of a 6, and (more importantly, however) would also cause the atom ‘test to be bound to the atom 6.  The function SETQ is the same as SET, but it causes LISP to act as if the first argument was quoted.  &lt;br /&gt;
Observe the following examples:&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
!Statement || Value || Comment &lt;br /&gt;
|-&lt;br /&gt;
|(SET ’a ( MULT 2 3))&lt;br /&gt;
|6&lt;br /&gt;
|a is an atom with a vaue of 6&lt;br /&gt;
|-&lt;br /&gt;
|(SET ’a ’(MULT 2 3))&lt;br /&gt;
|(MULT 2 3)&lt;br /&gt;
|a is a list with 3 elements&lt;br /&gt;
|-&lt;br /&gt;
|(SET ’b ’a)&lt;br /&gt;
|a&lt;br /&gt;
|b is an atom with a value of the character a&lt;br /&gt;
|-&lt;br /&gt;
|(SET ’c a)&lt;br /&gt;
|(MULT 2 3)&lt;br /&gt;
|c is a list with 3 elements&lt;br /&gt;
|-&lt;br /&gt;
|(SETQ EX (ADD 3 (MULT 2 5)))&lt;br /&gt;
|13&lt;br /&gt;
|The variable EX has a value of 13&lt;br /&gt;
|-&lt;br /&gt;
|(SETQ VOWELS ’(A E I O U))&lt;br /&gt;
|(A E I O U)&lt;br /&gt;
|VOWELS is a list of 5 elements&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The function EVAL returns the value of its argument, after it has been evaluated.  For example, (SETQ z ’(ADD 2 3)) has a value of the list (ADD 2 3); the function (EVAL ’z) has a value of (ADD 2 3); the function (EVAL z) has a value of 5 (but the binding of the atom z has not changed).  In this last example, you can think of z being “resolved” twice: once because it is an argument to a function and LISP evaluates all arguments to functions before the function is invoked, and once when the function EVAL is invoked to resolve arguments.  The function ATOM can be used to determine whether an item is an atom or a list. It returns either &amp;quot;true&amp;quot;, or &amp;quot;NIL&amp;quot; for false. Consider the following examples:&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
!Statement || Value || Comment &lt;br /&gt;
|-&lt;br /&gt;
|(SETQ p &amp;#039;(ADD 1 2 3 4))&lt;br /&gt;
|(ADD 1 2 3 4)&lt;br /&gt;
|p is a list with 5 elements&lt;br /&gt;
|-&lt;br /&gt;
|(ATOM &amp;#039;p)&lt;br /&gt;
|true&lt;br /&gt;
|The argument to ATOM is the ato p&lt;br /&gt;
|-&lt;br /&gt;
|(ATOM p)&lt;br /&gt;
|NIL&lt;br /&gt;
|Because p is not quoted, it is evaluated to the 5-element list.&lt;br /&gt;
|-&lt;br /&gt;
|(EVAL p)&lt;br /&gt;
|10&lt;br /&gt;
|The argument to EVAL is the value of p; the value of p is 10. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== List Functions (CAR, CDR, CONS, REVERSE)==&lt;br /&gt;
&lt;br /&gt;
The two most famous LISP functions are CAR and CDR (pronounced: could-er), named after registers of a now long-forgotten IBM machine on which LISP was first developed.  The function (CAR x) returns the first item of the list x (and x must be a list or an error will occur); (CDR x) returns the list without its first element (again, x must be a list).  The function CONS takes two arguments, of which the second must be a list.  It returns a list which is composed by placing the first argument as the first element in the second argument’s list.  The function REVERSE returns a list which is its arguments in reverse order.  &lt;br /&gt;
&lt;br /&gt;
The CAR and CDR functions are used extensively to grab specific elements of a list or sublist, that there&amp;#039;s a shorthand for this: (CADR x) is the same as (CAR (CDR x)), which retrieves the second element of the list x; (CAADDAR x) is a shorthand for (CAR (CAR (CDR (CDR (CAR x))))), and so on.&lt;br /&gt;
&lt;br /&gt;
The following examples illustrate the use of CAR, CDR, CONS, and REVERSE: &lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
!Statement || Value&lt;br /&gt;
|-&lt;br /&gt;
|(CAR ’(This is a list))&lt;br /&gt;
|This&lt;br /&gt;
|-&lt;br /&gt;
|(CDR ’(This is a list)))&lt;br /&gt;
|(is a list)&lt;br /&gt;
|-&lt;br /&gt;
|(CONS &amp;#039;red &amp;#039;(white blue))&lt;br /&gt;
|(red white blue)&lt;br /&gt;
|-&lt;br /&gt;
|(SETQ z (CONS &amp;#039;(red white blue) (CDR ’(This is a list)))))&lt;br /&gt;
|((red white blue) is a list)&lt;br /&gt;
|-&lt;br /&gt;
|(REVERSE z)&lt;br /&gt;
|(list a is (red white blue))&lt;br /&gt;
|-&lt;br /&gt;
|(CDDAR z)&lt;br /&gt;
|(blue)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Arithmetic Functions (ADD, MULT, ...)==&lt;br /&gt;
&lt;br /&gt;
As you have probably already figured out, the function ADD simply summed its arguments.  We’ll also be using the following arithmetic functions:&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;Function&amp;#039;&amp;#039;&amp;#039; || &amp;#039;&amp;#039;&amp;#039;Result&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
|(ADD x1 x2 …)&lt;br /&gt;
|sum of all arguments&lt;br /&gt;
|-&lt;br /&gt;
|(SUB a b)&lt;br /&gt;
|a-b&lt;br /&gt;
|-&lt;br /&gt;
|(MULT x1 x2 …)&lt;br /&gt;
|product of all arguments&lt;br /&gt;
|-&lt;br /&gt;
|(DIV a b)&lt;br /&gt;
|a/b&lt;br /&gt;
|-&lt;br /&gt;
|(SQUARE a)&lt;br /&gt;
|a*a&lt;br /&gt;
|-&lt;br /&gt;
|(EXP a n)&lt;br /&gt;
|a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|(EQ a b)&lt;br /&gt;
|true if a and b are equal, NIL otherwise&lt;br /&gt;
|-&lt;br /&gt;
|(POS a)&lt;br /&gt;
|true if a is positive, NIL otherwise&lt;br /&gt;
|-&lt;br /&gt;
|(NEG a)&lt;br /&gt;
|true if a is negative, NIL otherwise&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Functions ADD, SUB, MULT, and DIV can be written as their common mathematical symbols, +, -, *, and /.  Here are some examples of these functions:&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;Statement&amp;#039;&amp;#039;&amp;#039; || &amp;#039;&amp;#039;&amp;#039;Value&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
|(ADD (EXP 2 3) (SUB 4 1) (DIV 54 4))&lt;br /&gt;
|24.5&lt;br /&gt;
|-&lt;br /&gt;
|(- (* 3 2) (- 12 (+ 1 2 1)))&lt;br /&gt;
| -2&lt;br /&gt;
|-&lt;br /&gt;
|(ADD (SQUARE 3) (SQUARE 4))&lt;br /&gt;
|25&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== User-defined Functions ==&lt;br /&gt;
&lt;br /&gt;
LISP also allows us to create our own functions using the DEF function. (We will sometimes use DEFUN rather than DEF, as it is a bit more standard terminology.)  For example,&lt;br /&gt;
 (DEF SECOND (args) (CAR (CDR args)))&lt;br /&gt;
defines a new function called SECOND which operates on a single parameter named “args”.  SECOND will take the CDR of the parameter and then the CAR of that result.  So, for example:&lt;br /&gt;
(SECOND ’(a b c d e))&lt;br /&gt;
would first CDR the list to give (b c d e), and then CAR that value returning the single character “b”.  Consider the following program fragment:&lt;br /&gt;
:(SETQ X ’(a c s l))&lt;br /&gt;
:(DEF WHAT(args) (CONS args (REVERSE (CDR args))))&lt;br /&gt;
:(DEF SECOND(args) (CONS (CAR (CDR args)) NIL))&lt;br /&gt;
&lt;br /&gt;
The following chart illustrates the use of the user-defined functions WHAT and SECOND:&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Statement || Value&lt;br /&gt;
|-&lt;br /&gt;
|(WHAT X) || ((a c s l) l s c)&lt;br /&gt;
|-&lt;br /&gt;
|(SECOND X) || (c)&lt;br /&gt;
|-&lt;br /&gt;
|(SECOND (WHAT X)) || (l)&lt;br /&gt;
|-&lt;br /&gt;
|(WHAT (SECOND X)) || ((c))&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Online Interpreters ==&lt;br /&gt;
&lt;br /&gt;
There are many online LISP interpreters available on the Internet. The one that ACSL uses for testing its programs is CLISP that is accessible from   [https://www.jdoodle.com/execute-clisp-online JDoodle]. This interpreter is nice because it is quite peppy in running programs, and functions are not case sensitive. So, &amp;lt;code&amp;gt;(CAR (CDR x))&amp;lt;/code&amp;gt; is legal as is &amp;lt;code&amp;gt;(car (cdr x))&amp;lt;/code&amp;gt; One drawback of this interpreter is the print function changes lowercase input into uppercase. &lt;br /&gt;
 &lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
Questions from this topic will typically present a line of LISP code or a short sequence of statements and ask what is the value of the (final) statement.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression. &amp;lt;code&amp;gt;(MULT (ADD 6 5 0) (MULT 5 1 2 2) (DIV 9 (SUB 2 5)))&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 (MULT (ADD 6 5 0) (MULT 5 1 2 2) (DIV 6 (SUB 2 5)))&lt;br /&gt;
 (MULT 11 20  (DIV 6 -3))&lt;br /&gt;
 (MULT 11 20 -2)&lt;br /&gt;
 -440&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression:  &amp;lt;code&amp;gt;(CDR ’((2 (3))(4 (5 6) 7)))&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The CDR function takes the first element of its parameter (which is assumed to be a list) and returns the list with the first element removed.  The first element of the list is (2  (3)) and the list without this element is&lt;br /&gt;
((4 (5 6) 7)), a list with one element.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
Consider the following program fragment:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
(SETQ X ’(RI VA FL CA TX))&lt;br /&gt;
(CAR (CDR (REVERSE X)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
What is the value of the CAR expression? &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The first statement binds variable X to the list ‘(RI VA FL CA TX).&lt;br /&gt;
The REVERSE of this list is ‘(TX CA FL VA RI)&lt;br /&gt;
whose CDR is ‘(CA FL VA RI).  The CAR of this list is just the atom CA (without the quote).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &lt;br /&gt;
&lt;br /&gt;
Too scary of a sample problem! --marc 9/3/2018&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Given the function definitions for HY and FY as follows:&lt;br /&gt;
   (DEFUN HY(PARM) (REVERSE (CDR PARM)))&lt;br /&gt;
   (DEFUN FY(PARM) (CAR (HY (CDR PARM))))&lt;br /&gt;
What is the value of the following?&lt;br /&gt;
     (FY ’(DO RE (MI FA) SO))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
To evaluate (FY ’(DO RE (MI FA) SO)), we must evaluate&lt;br /&gt;
     (CAR (HY (CDR ’(DO RE (MI FA) SO)))).&lt;br /&gt;
Thus, HY is invoked with &lt;br /&gt;
     PARM = ’(RE (MI FA) SO), and we evaluate&lt;br /&gt;
     (REVERSE (CDR ’(RE (MI FA) SO)))&lt;br /&gt;
This has a value of (SO (MI FA)) which is returned to FY.  FY now takes the CAR of this which is SO (without the quotes).&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jWFgmE279eQ&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jWFgmE279eQ &amp;#039;&amp;#039;LISP very gentle intro&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A very gentle introduction to the LISP category, covering the LISP syntax and the basic operators, SETQ, ADD, SUB, MULT, and DIV.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/mRpbbss48sw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/mRpbbss48sw &amp;#039;&amp;#039;LISP Basics (for ACSL)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Explains the LISP operators CAR, CDR, and REVERSE, in the context of solving an ACSL All-Star Contest problem.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/50wj_f51kBM&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/50wj_f51kBM &amp;#039;&amp;#039;LISP Basics (for ACSL)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Completes the problem that was started in the above video. &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&amp;diff=516</id>
		<title>What Does This Program Do?</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&amp;diff=516"/>
		<updated>2018-09-06T10:54:54Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Description of the ACSL Pseudo-code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, and documentation is, unfortunately,&lt;br /&gt;
not always available or sufficient, it is essential to be able to read and understand an arbitrary program.  &lt;br /&gt;
&lt;br /&gt;
This category presents a program and asks the student to determine that the program does. The programs are written using a pseudocode that&lt;br /&gt;
should be readily understandable by all programmers familiar with a high-level programming language, such as Python, Java, or C.&lt;br /&gt;
&lt;br /&gt;
= Description of the ACSL Pseudo-code =&lt;br /&gt;
&lt;br /&gt;
We will use the following constructs in writing this code for this topic in ACSL:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;Construct&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;Code Segment&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
|Operators&lt;br /&gt;
|! (not) , ^ or ↑(exponent), *, / (real division), % (modulus), +, -, &amp;gt;, &amp;lt;, &amp;gt;=, &amp;lt;=, !=, ==, &amp;amp;&amp;amp; (and), &amp;lt;math&amp;gt;||&amp;lt;/math&amp;gt; (or) in that order of precedence&lt;br /&gt;
|-&lt;br /&gt;
|Functions&lt;br /&gt;
|abs(x) - absolute value, sqrt(x) - square root, int(x) - greatest integer &amp;lt;= x&lt;br /&gt;
|-&lt;br /&gt;
|Variables&lt;br /&gt;
|Start with a letter, only letters and digits&lt;br /&gt;
|-&lt;br /&gt;
|Sequential statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|INPUT variable&lt;br /&gt;
|-&lt;br /&gt;
|variable = expression (assignment)&lt;br /&gt;
|-&lt;br /&gt;
|OUTPUT variable&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Decision statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|IF boolean expression THEN&lt;br /&gt;
|-&lt;br /&gt;
|Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|ELSE   (optional)&lt;br /&gt;
|-&lt;br /&gt;
|Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|END IF&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Indefinite Loop statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|WHILE Boolean expression&lt;br /&gt;
|-&lt;br /&gt;
|     Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|END WHILE&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Definite Loop statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|FOR variable = start TO end STEP increment&lt;br /&gt;
|-&lt;br /&gt;
|    Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|NEXT&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Arrays:&lt;br /&gt;
|1 dimensional  arrays use a single subscript such as A(5).  2 dimensional arrays use (row, col) order such as A(2,3).  Arrays can start at location 0 for 1 dimensional arrays and location (0,0) for 2 dimensional arrays.  Most ACSL past problems start with either A(1) or A(1,1).  The size of the array will usually be specified in the problem statement.&lt;br /&gt;
|-&lt;br /&gt;
|Strings:&lt;br /&gt;
|Strings can contain 0 or more characters and the indexed position starts with 0 at the first character.  An empty string has a length of 0.  Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger.  The len(A) function will find the length of the string which is the total number of characters.  Strings are identified with surrounding double quotes. Use [ ] for identifying the characters in a substring of a given string as follows:  &lt;br /&gt;
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)&lt;br /&gt;
&lt;br /&gt;
S[:3] = “ACS” (take the first 3 characters starting on the left) &lt;br /&gt;
&lt;br /&gt;
S[5:] = “WDTPD” (take the last 5 characters starting on the right) &lt;br /&gt;
&lt;br /&gt;
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)&lt;br /&gt;
&lt;br /&gt;
S[0] = “A” (position 0 only).  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division.  In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4.&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
input H, R&lt;br /&gt;
B = 0&lt;br /&gt;
if H&amp;gt;48 then&lt;br /&gt;
    B = B + (H - 48) * 2 * R&lt;br /&gt;
    H = 48&lt;br /&gt;
end if&lt;br /&gt;
if H&amp;gt;40 then&lt;br /&gt;
   B = B + (H - 40) * (3/2) * R&lt;br /&gt;
   H = 40&lt;br /&gt;
end if&lt;br /&gt;
B = B + H * R&lt;br /&gt;
output B&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H).  The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48.  The table monitors variables B and H:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! | B || H&lt;br /&gt;
|-&lt;br /&gt;
| | 0 || 50&lt;br /&gt;
|-&lt;br /&gt;
| | 40 || 48&lt;br /&gt;
|-&lt;br /&gt;
| | 160 || 40&lt;br /&gt;
|-&lt;br /&gt;
| | 560 || 40&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
After the following program is executed, what is the final value of NUM?&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
A = “BANANAS”&lt;br /&gt;
NUM = 0: T = “”&lt;br /&gt;
for J = len(A) - 1 to 0 step –1&lt;br /&gt;
     T = T + A[j]&lt;br /&gt;
next &lt;br /&gt;
for J = 0 to len(A) - 1&lt;br /&gt;
    if A[J] == T[J] then NUM = NUM + 1&lt;br /&gt;
next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.&lt;br /&gt;
Variable NUM is incremented each time a character at position x of A is the same as the character in position x of string T. There are 5 such positions: 1, 2, 3, 4, and 5.&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
After the following program is executed, what is the final value of C[4]?&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
A(0) = 12: A(1) = 41: A(2) = 52&lt;br /&gt;
A(3) = 57: A(4) = 77: A(5) = -100&lt;br /&gt;
B(0) = 17: B(1) = 34: B(20 = 81&lt;br /&gt;
J = 0: K = 0: N = 0&lt;br /&gt;
while A(J) &amp;gt; 0&lt;br /&gt;
  while B(K) &amp;lt;= A(J)&lt;br /&gt;
    C(N) = B(K)&lt;br /&gt;
    N = N + 1&lt;br /&gt;
    k = k + 1&lt;br /&gt;
  end while&lt;br /&gt;
  C(N) = A(J): N = N + 1: J = J + 1&lt;br /&gt;
end while&lt;br /&gt;
C(N) = B(K)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following table traces the variables through the execution of the program. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!J&lt;br /&gt;
!K&lt;br /&gt;
!N&lt;br /&gt;
!A(J)&lt;br /&gt;
!B(K)&lt;br /&gt;
!C(N)&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0  || 0  || 12 || 17 || 12&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 1 || 41 || 17 || 17&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 2 || 41 || 34 || 34&lt;br /&gt;
|-&lt;br /&gt;
|1 || 2 || 3 || 41 || 81 || 41&lt;br /&gt;
|-&lt;br /&gt;
|2 || 2 || 4 || 52 || 81 || 52&lt;br /&gt;
|-&lt;br /&gt;
|3 || 2 || 5 || 57 || 81 || 57&lt;br /&gt;
|-&lt;br /&gt;
|4 || 2 || 6 || 77 || 81 || 77&lt;br /&gt;
|-&lt;br /&gt;
|5 || 2 || 7 || -100 || 81 || 81&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Thus, the value of C(4) is 52.  Note that this program merges two arrays in increasing order into one array until a negative number is input.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&amp;diff=438</id>
		<title>Digital Electronics</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&amp;diff=438"/>
		<updated>2018-08-22T00:36:22Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Sample Problem 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A digital circuit is constructed from logic gates. Each logic gate performs a function of boolean logic based on its inputs, such as AND or OR. &lt;br /&gt;
Each circuit can be represented as a Boolean Algebra expression; &lt;br /&gt;
this topic is an extension of the topic of [[Boolean Algebra]], which includes &lt;br /&gt;
a thorough description of truth tables and simplifying expressions. &lt;br /&gt;
&lt;br /&gt;
= Definitions =&lt;br /&gt;
&lt;br /&gt;
The following table illustrates all logic gates. For each logic gate, the&lt;br /&gt;
table shows the equivalent Boolean algebra expression and truth table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NAME&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;GRAPHICAL SYMBOL&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;ALGEBRAIC EXPRESSION&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;TRUTH TABLE&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;BUFFER&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Buffer-gate-en.svg|128px]]&lt;br /&gt;
| X = A&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NOT&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Not-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{A}&amp;lt;/math&amp;gt; or  &amp;lt;math&amp;gt;\neg A&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;AND&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| |[[File:And-gate.png|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;AB&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;A \cdot B&amp;lt;/math&amp;gt; &lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|colspan=&amp;quot;1&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B ||  X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NAND&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Nand-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{AB}&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\overline{A\cdot B}&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;OR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Or-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;A+B&amp;lt;/math&amp;gt; &lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NOR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Nor-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{A+B}&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;XOR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|[[File:Xor-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;A \oplus B&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;XNOR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Xnor-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{A \oplus B} \text{ or } A \odot B&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that there is some ambiguity in the conversion from a diagram to a circuit. For example, is &amp;lt;math&amp;gt;\overline{A+B}&amp;lt;/math&amp;gt; an OR gate followed by a NOT gate, or smply&lt;br /&gt;
a NOT gate.&lt;br /&gt;
&lt;br /&gt;
=Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find all ordered triplets (A, B, C) which make the following circuit FALSE:&lt;br /&gt;
&lt;br /&gt;
::[[File:NotABorC.svg|200px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
One approach to solving this problem is to reason about that inputs and outputs are necessary at each gate. For the circuit to be FALSE, both inputs to the file OR gate must be false. Thus, input C must be FALSE, and the output of the NAND gate must also be false. The NAND gate is false only when both of its inputs are TRUE; thus, inputs A and B must both be TRUE. The final answer is (TRUE, TRUE, FALSE), or (1, 1, 0).&lt;br /&gt;
&lt;br /&gt;
Another approach to solving this problem is to translate the circuit into a Boolean Algebra expression and simplify &lt;br /&gt;
the expression using the laws of Boolean Algebra. This circuit translates to the Boolean expression &amp;lt;math&amp;gt;\overline{AB}+C&amp;lt;/math&amp;gt;.  &lt;br /&gt;
To find when this is FALSE we can equivalently find when the &amp;lt;math&amp;gt;\overline{\overline{AB}+C}&amp;lt;/math&amp;gt; is TRUE.  &lt;br /&gt;
The expression becomes &amp;lt;math&amp;gt;\overline{\overline{AB}}\cdot \overline{C}&amp;lt;/math&amp;gt; after applying DeMorgan’s Law.  The double NOT over the AB expression&lt;br /&gt;
cancels out, to become &amp;lt;math&amp;gt;AB\overline{C}&amp;lt;/math&amp;gt;.  The AND of 3 terms is TRUE when each term is TRUE, or A=1, B=1 and C=0.&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
How many ordered 4-tuples (A, B, C, D) make the following circuit TRUE?&lt;br /&gt;
&lt;br /&gt;
::[[File:circuit-sample2.svg |400px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll use a truth table to solve this problem. The rows in the truth table will correspond to all possible inputs - 16 in this case, since there are 4 inputs. The output columns will be the output of each gate, other than the NOT gates. The diagram below labels each of the gates; it&amp;#039;s useful to keep the column straight when working the truth table.&lt;br /&gt;
&lt;br /&gt;
::[[File:circuit-sample2-labels.svg |300px]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|colspan=&amp;quot;5&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | A&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | B&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | C&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | D&lt;br /&gt;
!  p&lt;br /&gt;
!  q&lt;br /&gt;
!  r&lt;br /&gt;
!  s&lt;br /&gt;
!  t&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{C+D}&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;p+\overline{B}&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{A}B&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;r \oplus q&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;s \oplus p&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 0 || 0 || 1 || 1 || 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 0 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 1 || 0 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 1 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 0 || 0 || 1 || 1 || 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 0 || 1 || 0 || 0 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 1 || 0 || 0 || 1 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 1 || 1 || 0 || 0 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 0 || 0 || 1 || 1 || 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 0 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 1 || 0 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 1 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 0 || 0 || 1 || 1 || 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 0 || 1 || 0 || 0 || 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 1 || 0 || 0 || 0 || 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 1 || 1 || 0 || 0 || 0 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
From the truth table, there are 10 rows where the final output is TRUE.&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
==ACSL Advisors==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/gxil9VyGTtE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gxil9VyGTtE &amp;#039;&amp;#039;Digital Electronics -1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru (hemsra)&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Introduces the AND, OR, and NOT gates, and works through a couple of simple circuits.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/m7-wa5ca_G8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/m7-wa5ca_G8 Digital Electronics -2&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru (hemsra)&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a 3-gate circuit (the AND of an OR and a NOR) given by the Boolean expression &amp;lt;math&amp;gt;(\overline{A}+B)(\overline{B+C})&amp;lt;/math&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/Eckd5UlJmB4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/Eckd5UlJmB4 &amp;#039;&amp;#039;Digital Electronics Boolean Algebra&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a 3-gate circuit (the AND of an OR and a NOR) given by the Boolean expression&lt;br /&gt;
&amp;lt;math&amp;gt;\overline{(A+B)}(B+C)&amp;lt;/math&amp;gt;. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/JJL6DsVCpHo&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/JJL6DsVCpHo &amp;#039;&amp;#039;ACSL Digital Electronics Worksheet Sample&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of ACSL problems.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Other Videos==&lt;br /&gt;
&lt;br /&gt;
The topic of Digital Electronics is fundamental in Computer Science and there are many videos on YouTube that teach this subject. We found the following videos to be&lt;br /&gt;
nice introductions to digital logic gates. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/s2MI_NgKD98&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/s2MI_NgKD98 &amp;#039;&amp;#039;Digital Electronics Basics&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Beginning Electronics&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/z9s8A8oBe7g&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/z9s8A8oBe7g &amp;#039;&amp;#039;Logic Gate Expressions&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Kevin Drumm&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/TLl4E3IV6Z0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/TLl4E3IV6Z0 &amp;#039;&amp;#039;Logic Gate Combinations&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Kevin Drumm&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/eroqZpbKrhc&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/eroqZpbKrhc &amp;#039;&amp;#039;Determining the truth table and logic statement&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Anna does some physics&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
Uses a truth table to find the inputs that make the circuit &amp;lt;math&amp;gt;\not(A+B)+(AB)&amp;lt;/math&amp;gt; true using a truth table.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&amp;diff=437</id>
		<title>Digital Electronics</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&amp;diff=437"/>
		<updated>2018-08-22T00:15:33Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Sample Problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A digital circuit is constructed from logic gates. Each logic gate performs a function of boolean logic based on its inputs, such as AND or OR. &lt;br /&gt;
Each circuit can be represented as a Boolean Algebra expression; &lt;br /&gt;
this topic is an extension of the topic of [[Boolean Algebra]], which includes &lt;br /&gt;
a thorough description of truth tables and simplifying expressions. &lt;br /&gt;
&lt;br /&gt;
= Definitions =&lt;br /&gt;
&lt;br /&gt;
The following table illustrates all logic gates. For each logic gate, the&lt;br /&gt;
table shows the equivalent Boolean algebra expression and truth table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NAME&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;GRAPHICAL SYMBOL&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;ALGEBRAIC EXPRESSION&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;TRUTH TABLE&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;BUFFER&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Buffer-gate-en.svg|128px]]&lt;br /&gt;
| X = A&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NOT&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Not-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{A}&amp;lt;/math&amp;gt; or  &amp;lt;math&amp;gt;\neg A&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;AND&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| |[[File:And-gate.png|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;AB&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;A \cdot B&amp;lt;/math&amp;gt; &lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|colspan=&amp;quot;1&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B ||  X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NAND&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Nand-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{AB}&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\overline{A\cdot B}&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;OR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Or-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;A+B&amp;lt;/math&amp;gt; &lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;NOR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Nor-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{A+B}&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;XOR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|[[File:Xor-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;A \oplus B&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 0&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;XNOR&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| [[File:Xnor-gate-en.svg|128px]]&lt;br /&gt;
| X = &amp;lt;math&amp;gt;\overline{A \oplus B} \text{ or } A \odot B&amp;lt;/math&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
! A || B || X&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || 1&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that there is some ambiguity in the conversion from a diagram to a circuit. For example, is &amp;lt;math&amp;gt;\overline{A+B}&amp;lt;/math&amp;gt; an OR gate followed by a NOT gate, or smply&lt;br /&gt;
a NOT gate.&lt;br /&gt;
&lt;br /&gt;
=Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find all ordered triplets (A, B, C) which make the following circuit FALSE:&lt;br /&gt;
&lt;br /&gt;
::[[File:NotABorC.svg|200px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
One approach to solving this problem is to reason about that inputs and outputs are necessary at each gate. For the circuit to be FALSE, both inputs to the file OR gate must be false. Thus, input C must be FALSE, and the output of the NAND gate must also be false. The NAND gate is false only when both of its inputs are TRUE; thus, inputs A and B must both be TRUE. The final answer is (TRUE, TRUE, FALSE), or (1, 1, 0).&lt;br /&gt;
&lt;br /&gt;
Another approach to solving this problem is to translate the circuit into a Boolean Algebra expression and simplify &lt;br /&gt;
the expression using the laws of Boolean Algebra. This circuit translates to the Boolean expression &amp;lt;math&amp;gt;\overline{AB}+C&amp;lt;/math&amp;gt;.  &lt;br /&gt;
To find when this is FALSE we can equivalently find when the &amp;lt;math&amp;gt;\overline{\overline{AB}+C}&amp;lt;/math&amp;gt; is TRUE.  &lt;br /&gt;
The expression becomes &amp;lt;math&amp;gt;\overline{\overline{AB}}\cdot C&amp;lt;/math&amp;gt; after applying DeMorgan’s Law.  The double NOT over the AB expression&lt;br /&gt;
cancels out, to become &amp;lt;math&amp;gt;AB\overline{C}&amp;lt;/math&amp;gt;.  The AND of 3 terms is TRUE when each term is TRUE, or A=1, B=1 and C=0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
How many ordered 4-tuples (A, B, C, D) make the following circuit TRUE?&lt;br /&gt;
&lt;br /&gt;
::[[File:circuit-sample2.svg |400px]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll use a truth table to solve this problem. The rows in the truth table will correspond to all possible inputs - 16 in this case, since there are 4 inputs. The output columns will be the output of each gate, other than the NOT gates. The diagram below labels each of the gates; it&amp;#039;s useful to keep the column straight when working the truth table.&lt;br /&gt;
&lt;br /&gt;
::[[File:circuit-sample2-labels.svg |300px]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|INPUT&lt;br /&gt;
|colspan=&amp;quot;5&amp;quot; style=&amp;quot;background-color: #cceeff; font-size: x-small&amp;quot; &amp;quot;|OUTPUT&lt;br /&gt;
|-&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | A&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | B&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | C&lt;br /&gt;
!rowspan=&amp;quot;2&amp;quot; | D&lt;br /&gt;
!  p&lt;br /&gt;
!  q&lt;br /&gt;
!  r&lt;br /&gt;
!  s&lt;br /&gt;
!  t&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{C+D}&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;p+\overline{B}&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;\overline{A}B&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;r \oplus q&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;s \oplus p&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 0 || 0 || 1 || 1 || 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 0 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 1 || 0 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0 || 1 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 0 || 0 || 1 || 1 || 1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 0 || 1 || 0 || 0 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 1 || 0 || 0 || 1 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|0 || 1 || 1 || 1 || 0 || 0 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 0 || 0 || 1 || 1 || 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 0 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 1 || 0 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 1 || 1 || 0 || 1 || 0 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 0 || 0 || 1 || 1 || 0 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 0 || 1 || 0 || 0 || 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 1 || 0 || 0 || 0 || 0 || 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 1 || 1 || 0 || 0 || 0 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
From the truth table, there are 10 rows where the final output is TRUE.&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
==ACSL Advisors==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/gxil9VyGTtE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/gxil9VyGTtE &amp;#039;&amp;#039;Digital Electronics -1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru (hemsra)&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Introduces the AND, OR, and NOT gates, and works through a couple of simple circuits.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/m7-wa5ca_G8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/m7-wa5ca_G8 Digital Electronics -2&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru (hemsra)&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a 3-gate circuit (the AND of an OR and a NOR) given by the Boolean expression &amp;lt;math&amp;gt;(\overline{A}+B)(\overline{B+C})&amp;lt;/math&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/Eckd5UlJmB4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/Eckd5UlJmB4 &amp;#039;&amp;#039;Digital Electronics Boolean Algebra&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a 3-gate circuit (the AND of an OR and a NOR) given by the Boolean expression&lt;br /&gt;
&amp;lt;math&amp;gt;\overline{(A+B)}(B+C)&amp;lt;/math&amp;gt;. &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/JJL6DsVCpHo&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/JJL6DsVCpHo &amp;#039;&amp;#039;ACSL Digital Electronics Worksheet Sample&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of ACSL problems.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Other Videos==&lt;br /&gt;
&lt;br /&gt;
The topic of Digital Electronics is fundamental in Computer Science and there are many videos on YouTube that teach this subject. We found the following videos to be&lt;br /&gt;
nice introductions to digital logic gates. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/s2MI_NgKD98&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/s2MI_NgKD98 &amp;#039;&amp;#039;Digital Electronics Basics&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Beginning Electronics&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/z9s8A8oBe7g&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/z9s8A8oBe7g &amp;#039;&amp;#039;Logic Gate Expressions&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Kevin Drumm&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/TLl4E3IV6Z0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/TLl4E3IV6Z0 &amp;#039;&amp;#039;Logic Gate Combinations&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Kevin Drumm&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/eroqZpbKrhc&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/eroqZpbKrhc &amp;#039;&amp;#039;Determining the truth table and logic statement&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Anna does some physics&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
Uses a truth table to find the inputs that make the circuit &amp;lt;math&amp;gt;\not(A+B)+(AB)&amp;lt;/math&amp;gt; true using a truth table.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=412</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=412"/>
		<updated>2018-08-21T15:58:10Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to the wiki describing the topics covered in the short programs section of the [http://www.acsl.org ACSL] contests.&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;d like to contribute to this wiki - and we&amp;#039;d love to improve it - please shoot us an email requesting an account. Conversely, if we&amp;#039;ve linked to your material (especially YouTube videos) that you&amp;#039;d prefer that we do not reference, let us know and we will promptly remove those links.&lt;br /&gt;
&lt;br /&gt;
Categories covered:&lt;br /&gt;
&lt;br /&gt;
* [[Assembly Language Programming]]  &lt;br /&gt;
* [[Bit-String Flicking]] &lt;br /&gt;
* [[Boolean Algebra]]&lt;br /&gt;
* [[Computer Number Systems]]&lt;br /&gt;
* [[Data Structures]] (needs to add videos)&lt;br /&gt;
* [[Digital Electronics]] (needs to add videos)&lt;br /&gt;
* [[Graph Theory]] (needs to add videos)&lt;br /&gt;
* [[LISP]] &lt;br /&gt;
* [[Prefix/Infix/Postfix Notation]]&lt;br /&gt;
* [[Recursive Functions]]&lt;br /&gt;
* [[Regular Expressions]] (needs to add videos)&lt;br /&gt;
* [[What Does This Program Do?]] (needs to add videos)&lt;br /&gt;
* [http://www.acsl.org/categories/C1Elem-ComputerNumberSystems.pdf Elementary Division: Computer Number Systems (Contest 1)]&lt;br /&gt;
* [http://www.acsl.org/categories/C2Elem-Prefix-Postfix-InfixNotation.pdf Elementary Division: Prefix-Postfix-Infix Notation (Contest 2)]]&lt;br /&gt;
* [http://www.acsl.org/categories/C3Elem-BooleanAlgebra.pdf Elementary Division: Boolean Algebra (Contest 3)]&lt;br /&gt;
* [http://www.acsl.org/categories/C4Elem-GraphTheory.pdf Elementary Division: Graph Theory (Contest 4)]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [//meta.wikimedia.org/wiki/Help:Contents User&amp;#039;s Guide] for information on using the wiki software&lt;br /&gt;
* [//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&amp;diff=411</id>
		<title>What Does This Program Do?</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&amp;diff=411"/>
		<updated>2018-08-21T15:57:00Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Frequently, one must use or modify sections of another programmer’s code.  Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program.  This category has been rewritten using pseudocode similar to the design of the AP CS Principles course.  Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.&lt;br /&gt;
&lt;br /&gt;
= Description of Pseudo-code =&lt;br /&gt;
&lt;br /&gt;
We will use the following constructs in writing this code for this topic in ACSL:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;Construct&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
!&amp;#039;&amp;#039;&amp;#039;Code Segment&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
|Operators&lt;br /&gt;
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, &amp;gt;, &amp;lt;, &amp;gt;=, &amp;lt;=, !=, ==, &amp;amp;&amp;amp; (and), &amp;lt;math&amp;gt;||&amp;lt;/math&amp;gt; (or) in that order of precedence&lt;br /&gt;
|-&lt;br /&gt;
|Variables&lt;br /&gt;
|Start with a letter, only letters and digits&lt;br /&gt;
|-&lt;br /&gt;
|Sequential statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|INPUT variable&lt;br /&gt;
|-&lt;br /&gt;
|variable = expression (assignment)&lt;br /&gt;
|-&lt;br /&gt;
|OUTPUT variable&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Decision statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|IF boolean expression THEN&lt;br /&gt;
|-&lt;br /&gt;
|Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|ELSE   (optional)&lt;br /&gt;
|-&lt;br /&gt;
|Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|END IF&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Indefinite Loop statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|WHILE Boolean expression&lt;br /&gt;
|-&lt;br /&gt;
|     Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|END WHILE&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Definite Loop statements&lt;br /&gt;
|&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|FOR variable = start TO end STEP increment&lt;br /&gt;
|-&lt;br /&gt;
|    Statement(s)&lt;br /&gt;
|-&lt;br /&gt;
|NEXT&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|Arrays:&lt;br /&gt;
|1D arrays use a single subscript such as A[5].  2D arrays use row major order starting with [0,0] in the upper left corner.  Use [] for identifying the subscript(s) so that A[5] is the 6th item in a list and A[2,3] is row 2 (third row) and column 3 (4th column).  The size of the array will be specified in the problem statement.&lt;br /&gt;
|-&lt;br /&gt;
|Strings:&lt;br /&gt;
|They can contain 0 or more characters and the indexed position starts with 0 as the first character.  An empty string has a length of 0.  Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger.  The len(A) function will find the length of the string which is the total characters.  Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows:  If S = “ACSL WDTPD”, then S[:3] = “ACSL” (positions 0 to 3), S[5:] = “WDTPD” (positions 5 to 9), S[2:6] = “SL WD” (positions 2 to 6), and S[0] = “A” (position 0 only).  The value of len(A) is 10.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division.  In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4.  Line numbers will be included for the purpose of explaining the solution.&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?&lt;br /&gt;
::10 input H, R&lt;br /&gt;
::20 B = 0&lt;br /&gt;
::30 if H&amp;gt;48 then&lt;br /&gt;
::40      B = B + (H - 48) * 2 * R&lt;br /&gt;
::50      H = 48&lt;br /&gt;
::60 end if&lt;br /&gt;
::70 if H&amp;gt;40 then&lt;br /&gt;
::80      B = B + (H - 40) * (3/2) * R&lt;br /&gt;
::90      H = 40&lt;br /&gt;
::100 end if&lt;br /&gt;
::110 B = B + H * R&lt;br /&gt;
::120 output B&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H).  The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48.  The table monitors variables B and H:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!LINE || B || H&lt;br /&gt;
|-&lt;br /&gt;
|20 || 0 || 50&lt;br /&gt;
|-&lt;br /&gt;
|50 || 40 || 48&lt;br /&gt;
|-&lt;br /&gt;
|90 || 160 || 40&lt;br /&gt;
|-&lt;br /&gt;
|110 || 560 || 40&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
After the following program is executed, what is the final value of NUM?&lt;br /&gt;
::10 A = “BANANAS”&lt;br /&gt;
::20 NUM = 0: T = “”&lt;br /&gt;
::30 for J = len(A) - 1 to 0 step –1&lt;br /&gt;
::40      T = T + A[j]&lt;br /&gt;
::50 next &lt;br /&gt;
::60 for J = 0 to len(A) - 1&lt;br /&gt;
::70     if A[J] == T[J] then NUM = NUM + 1&lt;br /&gt;
::80 next&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.&lt;br /&gt;
A	B	A	N	A	N	A	S&lt;br /&gt;
T	S	A	N	A	N	A	B&lt;br /&gt;
		*	*	*	*	*	&lt;br /&gt;
Those positions marked with an asterisk contribute one to the value of NUM.  There are 5 such positions. &lt;br /&gt;
&lt;br /&gt;
== Sample Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
After the following program is executed, what is the final value of C[4]?&lt;br /&gt;
::10 A[0] = 12: A[1] = 41: A[2] = 52&lt;br /&gt;
::20 A[3] = 57: A[4] = 77: A[5] = -100&lt;br /&gt;
::30 B[0] = 17: B[1] = 34: B[2] = 81&lt;br /&gt;
::40 J = 0: K = 0: N = 0&lt;br /&gt;
::50 while A[J] &amp;gt; 0&lt;br /&gt;
::60      while B[K] &amp;lt;= A[J]&lt;br /&gt;
::70             C[N] = B[K]&lt;br /&gt;
::80             N = N + 1&lt;br /&gt;
::90             k = k + 1&lt;br /&gt;
::100       end while&lt;br /&gt;
::110       C[N] = A[J]: N = N + 1: J = J + 1&lt;br /&gt;
::120 end while&lt;br /&gt;
::130 C[N] = B[K]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following table traces the variables through the execution of the program. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!J&lt;br /&gt;
!K&lt;br /&gt;
!N&lt;br /&gt;
!A[J]&lt;br /&gt;
!B[K]&lt;br /&gt;
!C[N]&lt;br /&gt;
|-&lt;br /&gt;
|0 || 0  || 0  || 12 || 17 || 12&lt;br /&gt;
|-&lt;br /&gt;
|1 || 0 || 1 || 41 || 17 || 17&lt;br /&gt;
|-&lt;br /&gt;
|1 || 1 || 2 || 41 || 34 || 34&lt;br /&gt;
|-&lt;br /&gt;
|1 || 2 || 3 || 41 || 81 || 41&lt;br /&gt;
|-&lt;br /&gt;
|2 || 2 || 4 || 52 || 81 || 52&lt;br /&gt;
|-&lt;br /&gt;
|3 || 2 || 5 || 57 || 81 || 57&lt;br /&gt;
|-&lt;br /&gt;
|4 || 2 || 6 || 77 || 81 || 77&lt;br /&gt;
|-&lt;br /&gt;
|5 || 2 || 7 || -100 || 81 || 81&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Thus, the value of C[4] is 52.  Note that this program merges two arrays in increasing order into one array until a negative number is input.&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=410</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=410"/>
		<updated>2018-08-21T15:52:08Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A Finite State Automation (FSA) has four components: an input alphabet (those letters or strings which are legal inputs); a set of transition rules to advance from state to state (given a current state and an element of the input alphabet, what is the next state); a unique start state; and one or more final states.  We can draw the FSA, as shown below, by representing each state as a circular node; the final state as a double circle; the start state as the only node with an incoming arrow; and the transition rules by the strings on the edges connecting the nodes.  When labels are assigned to states, they appear inside the circle representing the state.  &lt;br /&gt;
&lt;br /&gt;
[[File:fsa_1.png]]&lt;br /&gt;
&lt;br /&gt;
If there is a path from the start state to a final state by which an input string can be parsed, then the input string is said to be “accepted” by the FSA.  The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy).  &lt;br /&gt;
&lt;br /&gt;
= Definitions =&lt;br /&gt;
&lt;br /&gt;
Just like [[Boolean Algebra]] is a convenient algebraic representation of [[Digital Electronics]] Circuits, a regular expression is an algebraic representation of an FSA.  For example, the regular expression corresponding to the first FSA given above is xx*yy*.  The regular expression for the second FSA is extremely complex!  The following simple FSAs and REs illustrate  the correspondence:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|[[File:fsas_2-3.png|512px]]&lt;br /&gt;
|-&lt;br /&gt;
|ab*c ___________________ (aUb)c or acUbc&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The rules for forming a regular expression (RE) are as follows:&lt;br /&gt;
:1. The null string (λ) is a RE.&lt;br /&gt;
:2. If the string a is in the input alphabet, then it is a RE.&lt;br /&gt;
:3. if the strings a and b are both REs, then so are the strings built up using the following rules:&lt;br /&gt;
::a. CONCATENATION.  “ab” (a followed by b).&lt;br /&gt;
::b. UNION. “aUb” (a or b).  &lt;br /&gt;
::c. CLOSURE. “a*” (a repeated zero or more times).&lt;br /&gt;
&lt;br /&gt;
If we have a regular expression, then we can mechanically build an FSA to accept the strings which are generated by the regular expression.  Conversely, if we have an FSA, we can mechanically develop a regular expression which will describe the strings which can be parsed by the FSA.  For a given FSA or regular expression, there are many others which are equivalent to it.  A “most simplified” regular expression or FSA is not always well defined.  &lt;br /&gt;
&lt;br /&gt;
Identities for regular expressions appear below.  The order of precedence for regular expression operators is: Kleene Star, concatenation, and then union.  The Kleene Star binds from right to left; concatenation and union both bind from left to right. &lt;br /&gt;
&lt;br /&gt;
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily.  Visual BASIC has the LIKE operator that is very easy to use.  We will use these “basic” symbols in our category description.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!Pattern&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|?&lt;br /&gt;
|Any single character&lt;br /&gt;
|-&lt;br /&gt;
|*&lt;br /&gt;
|Zero or more of the preceding character&lt;br /&gt;
|-&lt;br /&gt;
|#&lt;br /&gt;
|Any single digit&lt;br /&gt;
|-&lt;br /&gt;
|[ char-char,char,…]&lt;br /&gt;
|Any inclusive range or list of characters&lt;br /&gt;
|-&lt;br /&gt;
|{![charlist]}&lt;br /&gt;
|Any character not in a given range or list&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!YES&lt;br /&gt;
!NO&lt;br /&gt;
!Why not?&lt;br /&gt;
|-&lt;br /&gt;
|App$5.java&lt;br /&gt;
|Help1.&lt;br /&gt;
|	E is not in the range [o-z].&lt;br /&gt;
|-&lt;br /&gt;
|Dog&amp;amp;2.py&lt;br /&gt;
|IoU$5&lt;br /&gt;
|There is no . at the end.&lt;br /&gt;
|-&lt;br /&gt;
|LzyG3.txt&lt;br /&gt;
|move6.py&lt;br /&gt;
|The m is not in the range [A-M].&lt;br /&gt;
|-&lt;br /&gt;
|Hot90.&lt;br /&gt;
|MaX7A.txt&lt;br /&gt;
|The A is not a digit from 0 to 9.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Typical problems in the category will include: translate an FSA to a regular expression; simplify a regular expression (possibly to minimize the number of states or transitions); determine which regular expressions are equivalent; and determine which strings are accepted by either an FSA or a regular expression.&lt;br /&gt;
&lt;br /&gt;
= Basic Identities =&lt;br /&gt;
&lt;br /&gt;
{| Class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|1.  (a*)*  = a*&lt;br /&gt;
|5.  a(ba)* = (ab)*a&lt;br /&gt;
|-&lt;br /&gt;
|2.  aa*    = a*a&lt;br /&gt;
|6.  (a U b)* = (a* U b*)*&lt;br /&gt;
|-&lt;br /&gt;
|3.  aa* U λ  = a*&lt;br /&gt;
|7.  (a U b)* = (a*b*)*&lt;br /&gt;
|-&lt;br /&gt;
|4.  a(b U c) = ab U ac&lt;br /&gt;
|8.  (a U b)* = a*(ba*)*&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Sample Problems =&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 1 ==&lt;br /&gt;
&lt;br /&gt;
Find a simplified regular expression for the following FSA:&lt;br /&gt;
&lt;br /&gt;
[[File:fsa_s1.png]]&lt;br /&gt;
 	&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The expression 01*01 is read directly from the FSA.  It is in its most simplified form.&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 2 ==&lt;br /&gt;
&lt;br /&gt;
Which, if any, of the following Regular Expressions are equivalent?&lt;br /&gt;
::A. (aUb)(ab*)(b*Ua)&lt;br /&gt;
::B. (aab*Ubab*)a&lt;br /&gt;
::C. aab*Ubab*UaabaUbab*a&lt;br /&gt;
::D. aab*Ubab*Uaab*aUbab*a&lt;br /&gt;
::E. a*Ub*	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
On first inspection, B can be discarded because it is the only RE whose strings must end in an a.  E can also be discarded since it is the only RE that can accept a null string.  C and D are not equal.  After expanding A, we must compare it to C and D.  It is equal to D, but not to C.  A and D.&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 3 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings match the regular expression pattern &amp;quot;?[A-D]*[a-d]*#&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 8AAAabd4&lt;br /&gt;
::B. MM5&lt;br /&gt;
::C. AAAAAAAA7&lt;br /&gt;
::D. Abcd9&lt;br /&gt;
::E. &amp;amp;dd88&lt;br /&gt;
::F. &amp;gt;BAD0&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The answer is A, C, D, and F.  In B the character M is not in the range A-D or a-d.  In E, there cannot be more than 1 digit at the end of the string.  Remember that an asterisk represents 0 or more of that character or rangle of characters.&lt;br /&gt;
&lt;br /&gt;
== Sample Problem 4 ==&lt;br /&gt;
&lt;br /&gt;
Which of the following strings are accepted by the following regular expression &amp;quot;00*1*1U11*0*0&amp;quot; ?&lt;br /&gt;
&lt;br /&gt;
::A. 0000001111111&lt;br /&gt;
::B. 1010101010&lt;br /&gt;
::C. 1111111&lt;br /&gt;
::D. 0110&lt;br /&gt;
::E. 10	&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The answer is A and E.  A uses the left hand pattern and E uses the right hand pattern.  Every string must stat and end in the opposite digit so C and D don’t work.  B doesn’t work because all 1’s and all 0’s must be together.&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=409</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=409"/>
		<updated>2018-08-21T14:57:42Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A graph is a collection of vertices and edges.  An edge is a connection between two vertices (or nodes).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but it must be borne in mind that the graph is defined independently of the representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:graph_1.png]] || [[File:graph_3.png]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G, H, I, J, K, L, M}, and its set of edges between these vertices {AG, AB, AC, LM, JM, JL, JK, ED,  FD, HI, FE, AF, GE}.&lt;br /&gt;
&lt;br /&gt;
A path from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, BAFEG is path from B to G in the graph above.  A simple path is a path with no vertex repeated.  For example, BAFEGAC is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is connected if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of connected components.  For example, the graph above has three connected components: {I, H}, {J, K, L, M} and {A, B, C, D, E, F, G}.&lt;br /&gt;
&lt;br /&gt;
A cycle is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path AFEGA is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, FEGAF and GAFEG are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V, the number of edges by E.  Note that E can range anywhere from V to V2 (or 1/2 V(V-1) in an undirected graph).  Graphs will all edges present are called complete graphs; graphs with relatively few edges present (say less than V log(V)) are called sparse; graphs with relatively few edges missing are called dense.&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a tree.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A spanning tree of a graph is a subgraph that contains all the vertices and forms a tree.  A group of disconnected trees is called a forest.&lt;br /&gt;
&lt;br /&gt;
Directed graphs are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_4.png]]&lt;br /&gt;
&lt;br /&gt;
There is only one directed path from D to F.  Note that there are two edges between H and I, one each direction, which essentially makes an undirected edge.  An undirected graph can be thought of as a directed graph with all edges occurring in pairs in this way.  A dag (directed acyclic graph) is a directed graph with no cycles.  &lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is a path from vertex i to j.  If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  In fact, the quantity Mp(i,j) is the number of paths.&lt;br /&gt;
&lt;br /&gt;
== Traversability ==&lt;br /&gt;
&lt;br /&gt;
There are many applications of graphs and associated algorithms that will not be included in this topic except for the Elementary Division.  A Hamiltonian circuit is finding a path by which every vertex can be visited once and only once.  An Euler circuit is finding a path by which every edge can be used once and only once.  Graphs are traversable if there exists an Euler circuit unlike the famous Seven Bridges of Königsberg:&lt;br /&gt;
&lt;br /&gt;
:::::[[File:konigsberg.png]]&lt;br /&gt;
&lt;br /&gt;
Rules of traversability show that vertices can be either odd or even based on how many edges are incident on it.  A graph is traversable if there are 0 or 2 odd vertices.  If there are 2 odd vertices, then the path must begin with one of them and end with the other.  With no odd edges, the path can begin with any vertex in the graph.  Conflict theory and proof of the Four Color Theorem also use principles of graph theory.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s3.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix M represent the graph.  Recall that the number of paths from vertex i to vertex j of length p equals M p[i,j].  The values of M, M 2 and M 4 are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 (M 2[1,3]) and 3 paths of length 4 (M 4[1,3]).&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s4.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The vertices do not have to be in those exact locations, but the edges must be the same.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s4.png]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s &amp;#039;&amp;#039;Graph Theory (Intro)&amp;#039;&amp;#039;]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_3.png&amp;diff=408</id>
		<title>File:Graph 3.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_3.png&amp;diff=408"/>
		<updated>2018-08-21T14:53:58Z</updated>

		<summary type="html">&lt;p&gt;Carlen: Carlen uploaded a new version of File:Graph 3.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_2.png&amp;diff=407</id>
		<title>File:Graph 2.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_2.png&amp;diff=407"/>
		<updated>2018-08-21T14:51:55Z</updated>

		<summary type="html">&lt;p&gt;Carlen: Carlen uploaded a new version of File:Graph 2.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_1.png&amp;diff=406</id>
		<title>File:Graph 1.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_1.png&amp;diff=406"/>
		<updated>2018-08-21T14:51:07Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Matrix_s4.png&amp;diff=405</id>
		<title>File:Matrix s4.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Matrix_s4.png&amp;diff=405"/>
		<updated>2018-08-21T14:47:31Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=404</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=404"/>
		<updated>2018-08-21T14:47:12Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A graph is a collection of vertices and edges.  An edge is a connection between two vertices (or nodes).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but it must be borne in mind that the graph is defined independently of the representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:graph_1.png]] || [[File:graph_3.png]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G, H, I, J, K, L, M}, and its set of edges between these vertices {AG, AB, AC, LM, JM, JL, JK, ED,  FD, HI, FE, AF, GE}.&lt;br /&gt;
&lt;br /&gt;
A path from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, BAFEG is path from B to G in the graph above.  A simple path is a path with no vertex repeated.  For example, BAFEGAC is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is connected if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of connected components.  For example, the graph above has three connected components: {I, H}, {J, K, L, M} and {A, B, C, D, E, F, G}.&lt;br /&gt;
&lt;br /&gt;
A cycle is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path AFEGA is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, FEGAF and GAFEG are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V, the number of edges by E.  Note that E can range anywhere from V to V2 (or 1/2 V(V-1) in an undirected graph).  Graphs will all edges present are called complete graphs; graphs with relatively few edges present (say less than V log(V)) are called sparse; graphs with relatively few edges missing are called dense.&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a tree.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A spanning tree of a graph is a subgraph that contains all the vertices and forms a tree.  A group of disconnected trees is called a forest.&lt;br /&gt;
&lt;br /&gt;
Directed graphs are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_4.png]]&lt;br /&gt;
&lt;br /&gt;
There is only one directed path from D to F.  Note that there are two edges between H and I, one each direction, which essentially makes an undirected edge.  An undirected graph can be thought of as a directed graph with all edges occurring in pairs in this way.  A dag (directed acyclic graph) is a directed graph with no cycles.  &lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is a path from vertex i to j.  If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  In fact, the quantity Mp(i,j) is the number of paths.&lt;br /&gt;
&lt;br /&gt;
== Traversability ==&lt;br /&gt;
&lt;br /&gt;
There are many applications of graphs and associated algorithms that will not be included in this topic except for the Elementary Division.  A Hamiltonian circuit is finding a path by which every vertex can be visited once and only once.  An Euler circuit is finding a path by which every edge can be used once and only once.  Graphs are traversable if there exists an Euler circuit unlike the famous Seven Bridges of Königsberg:&lt;br /&gt;
&lt;br /&gt;
:::::[[File:konigsberg.png]]&lt;br /&gt;
&lt;br /&gt;
Rules of traversability show that vertices can be either odd or even based on how many edges are incident on it.  A graph is traversable if there are 0 or 2 odd vertices.  If there are 2 odd vertices, then the path must begin with one of them and end with the other.  With no odd edges, the path can begin with any vertex in the graph.  Conflict theory and proof of the Four Color Theorem also use principles of graph theory.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
&lt;br /&gt;
[[File:matrix1_s2.png]]&lt;br /&gt;
&lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix2_s2.png]]&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s3.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix M represent the graph.  Recall that the number of paths from vertex i to vertex j of length p equals M p[i,j].  The values of M, M 2 and M 4 are:&lt;br /&gt;
&lt;br /&gt;
[[File:matrix_s3.png]]&lt;br /&gt;
&lt;br /&gt;
There is 1 path of length 2 (M 2[1,3]) and 3 paths of length 4 (M 4[1,3]).&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The vertices do not have to be in those exact locations, but the edges must be the same.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s4.png]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s &amp;#039;&amp;#039;Graph Theory (Intro)&amp;#039;&amp;#039;]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Matrix2_s2.png&amp;diff=403</id>
		<title>File:Matrix2 s2.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Matrix2_s2.png&amp;diff=403"/>
		<updated>2018-08-21T14:43:00Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Matrix1_s2.png&amp;diff=402</id>
		<title>File:Matrix1 s2.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Matrix1_s2.png&amp;diff=402"/>
		<updated>2018-08-21T14:42:42Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Matrix_s3.png&amp;diff=401</id>
		<title>File:Matrix s3.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Matrix_s3.png&amp;diff=401"/>
		<updated>2018-08-21T14:42:19Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=400</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=400"/>
		<updated>2018-08-21T14:31:44Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A graph is a collection of vertices and edges.  An edge is a connection between two vertices (or nodes).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but it must be borne in mind that the graph is defined independently of the representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:graph_1.png]] || [[File:graph_2.png]] || [[File:graph_3.png]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G, H, I, J, K, L, M}, and its set of edges between these vertices {AG, AB, AC, LM, JM, JL, JK, ED,  FD, HI, FE, AF, GE}.&lt;br /&gt;
&lt;br /&gt;
A path from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, BAFEG is path from B to G in the graph above.  A simple path is a path with no vertex repeated.  For example, BAFEGAC is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is connected if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of connected components.  For example, the graph above has three connected components: {I, H}, {J, K, L, M} and {A, B, C, D, E, F, G}.&lt;br /&gt;
&lt;br /&gt;
A cycle is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path AFEGA is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, FEGAF and GAFEG are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V, the number of edges by E.  Note that E can range anywhere from V to V2 (or 1/2 V(V-1) in an undirected graph).  Graphs will all edges present are called complete graphs; graphs with relatively few edges present (say less than V log(V)) are called sparse; graphs with relatively few edges missing are called dense.&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a tree.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A spanning tree of a graph is a subgraph that contains all the vertices and forms a tree.  A group of disconnected trees is called a forest.&lt;br /&gt;
&lt;br /&gt;
Directed graphs are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_4.png]]&lt;br /&gt;
&lt;br /&gt;
There is only one directed path from D to F.  Note that there are two edges between H and I, one each direction, which essentially makes an undirected edge.  An undirected graph can be thought of as a directed graph with all edges occurring in pairs in this way.  A dag (directed acyclic graph) is a directed graph with no cycles.  &lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is a path from vertex i to j.  If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  In fact, the quantity Mp(i,j) is the number of paths.&lt;br /&gt;
&lt;br /&gt;
== Traversability ==&lt;br /&gt;
&lt;br /&gt;
There are many applications of graphs and associated algorithms that will not be included in this topic except for the Elementary Division.  A Hamiltonian circuit is finding a path by which every vertex can be visited once and only once.  An Euler circuit is finding a path by which every edge can be used once and only once.  Graphs are traversable if there exists an Euler circuit unlike the famous Seven Bridges of Königsberg:&lt;br /&gt;
&lt;br /&gt;
:::::[[File:konigsburg.png]]&lt;br /&gt;
&lt;br /&gt;
Rules of traversability show that vertices can be either odd or even based on how many edges are incident on it.  A graph is traversable if there are 0 or 2 odd vertices.  If there are 2 odd vertices, then the path must begin with one of them and end with the other.  With no odd edges, the path can begin with any vertex in the graph.  Conflict theory and proof of the Four Color Theorem also use principles of graph theory.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
 &lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s3.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix M represent the graph.  Recall that the number of paths from vertex i to vertex j of length p equals M p[i,j].  The values of M, M 2 and M 4 are:&lt;br /&gt;
   &lt;br /&gt;
There is 1 path of length 2 (M 2[1,3]) and 3 paths of length 4 (M 4[1,3]).&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The vertices do not have to be in those exact locations, but the edges must be the same.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s4.png]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s &amp;#039;&amp;#039;Graph Theory (Intro)&amp;#039;&amp;#039;]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_s3.png&amp;diff=399</id>
		<title>File:Graph s3.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_s3.png&amp;diff=399"/>
		<updated>2018-08-21T14:27:16Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_3.png&amp;diff=398</id>
		<title>File:Graph 3.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_3.png&amp;diff=398"/>
		<updated>2018-08-21T14:26:55Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=397</id>
		<title>Graph Theory</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&amp;diff=397"/>
		<updated>2018-08-21T14:19:31Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Many problems are naturally formulated in terms of points and connections between them.  For example, a computer network has PCs connected by cables, an airline map has cities connected by routes, and a school has rooms connected by hallways.  A graph is a mathematical object which models such situations.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
A graph is a collection of vertices and edges.  An edge is a connection between two vertices (or nodes).  One can draw a graph by marking points for the vertices and drawing lines connecting them for the edges, but it must be borne in mind that the graph is defined independently of the representation.  For example, the following two drawings represent the same graph:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:graph_1.png]] || [[File:graph_2.png]] || [[File:graph_3.png]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
The precise way to represent this graph is to identify its set of vertices {A, B, C, D, E, F, G, H, I, J, K, L, M}, and its set of edges between these vertices {AG, AB, AC, LM, JM, JL, JK, ED,  FD, HI, FE, AF, GE}.&lt;br /&gt;
&lt;br /&gt;
A path from vertex x to y in a graph is a list of vertices, in which successive vertices are connected by edges in the graph.  For example, BAFEG is path from B to G in the graph above.  A simple path is a path with no vertex repeated.  For example, BAFEGAC is not a simple path.  &lt;br /&gt;
&lt;br /&gt;
A graph is connected if there is a path from every vertex to every other vertex in the graph.  Intuitively, if the vertices were physical objects and the edges were strings connecting them, a connected graph would stay in one piece if picked up by any vertex.  A graph which is not connected is made up of connected components.  For example, the graph above has three connected components: {I, H}, {J, K, L, M} and {A, B, C, D, E, F, G}.&lt;br /&gt;
&lt;br /&gt;
A cycle is a path, which is simple except that the first and last vertex are the same (a path from a point back to itself).  For example, the path AFEGA is a cycle in our example.  Vertices must be listed in the order that they are traveled to make the path; any of the vertices may be listed first.  Thus, FEGAF and GAFEG are different ways to identify the same cycle.  For clarity, we list the start / end vertex twice: once at the start of the cycle and once at the end.&lt;br /&gt;
&lt;br /&gt;
We’ll denote the number of vertices in a given graph by V, the number of edges by E.  Note that E can range anywhere from V to V2 (or 1/2 V(V-1) in an undirected graph).  Graphs will all edges present are called complete graphs; graphs with relatively few edges present (say less than V log(V)) are called sparse; graphs with relatively few edges missing are called dense.&lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
A graph with no cycles is called a tree.  There is only one path between any two nodes in a tree.  A tree on N vertices contains exactly N-1 edges.  A spanning tree of a graph is a subgraph that contains all the vertices and forms a tree.  A group of disconnected trees is called a forest.&lt;br /&gt;
&lt;br /&gt;
Directed graphs are graphs which have a direction associated with each edge.  An edge xy in a directed graph can be used in a path that goes from x to y but not necessarily from y to x.  For example, a directed graph similar to our example graph is drawn below:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_4.png]]&lt;br /&gt;
&lt;br /&gt;
There is only one directed path from D to F.  Note that there are two edges between H and I, one each direction, which essentially makes an undirected edge.  An undirected graph can be thought of as a directed graph with all edges occurring in pairs in this way.  A dag (directed acyclic graph) is a directed graph with no cycles.  &lt;br /&gt;
&lt;br /&gt;
== Adjacency Matrices ==&lt;br /&gt;
&lt;br /&gt;
It is frequently convenient to represent a graph by a matrix, as shown in the second sample problem below.  If we consider vertex A as 1, B as 2, etc., then a “one” in M at row i and column j indicates that there is a path from vertex i to j.  If we raise M to the pth power, the resulting matrix indicates which paths of length p exist in the graph.  In fact, the quantity Mp(i,j) is the number of paths.&lt;br /&gt;
&lt;br /&gt;
== Traversability ==&lt;br /&gt;
&lt;br /&gt;
There are many applications of graphs and associated algorithms that will not be included in this topic except for the Elementary Division.  A Hamiltonian circuit is finding a path by which every vertex can be visited once and only once.  An Euler circuit is finding a path by which every edge can be used once and only once.  Graphs are traversable if there exists an Euler circuit unlike the famous Seven Bridges of Königsberg:&lt;br /&gt;
&lt;br /&gt;
:::::[[File:konigsburg.png]]&lt;br /&gt;
&lt;br /&gt;
Rules of traversability show that vertices can be either odd or even based on how many edges are incident on it.  A graph is traversable if there are 0 or 2 odd vertices.  If there are 2 odd vertices, then the path must begin with one of them and end with the other.  With no odd edges, the path can begin with any vertex in the graph.  Conflict theory and proof of the Four Color Theorem also use principles of graph theory.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Find the number of different cycles contained in the directed graph with vertices {A, B, C, D, E} and edges {AB, BA, BC, CD, DC, DB, DE}.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The graph is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s1.png]&lt;br /&gt;
&lt;br /&gt;
By inspection, the cycles are: {A,B}, {B,C,D} and {C,D}.  Thus, there are 3 cycles in the graph.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s2.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
By using adjacency matrices, the current one is&lt;br /&gt;
 &lt;br /&gt;
After adding edges AE and EA, the matrices are:&lt;br /&gt;
&lt;br /&gt;
There are 6 more paths of length 2 since 16 – 10 = 6.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s3.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Let matrix M represent the graph.  Recall that the number of paths from vertex i to vertex j of length p equals M p[i,j].  The values of M, M 2 and M 4 are:&lt;br /&gt;
   &lt;br /&gt;
There is 1 path of length 2 (M 2[1,3]) and 3 paths of length 4 (M 4[1,3]).&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Given the adjacency matrix, draw the directed graph.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The vertices do not have to be in those exact locations, but the edges must be the same.&lt;br /&gt;
&lt;br /&gt;
[[File:graph_s4.png]]&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://www.youtube.com/watch?v=gXgEDyodOJU&amp;amp;t=319s &amp;#039;&amp;#039;Graph Theory (Intro)&amp;#039;&amp;#039;]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=396</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=396"/>
		<updated>2018-08-21T14:08:13Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to the wiki describing the topics covered in the short programs section of the [http://www.acsl.org ACSL] contests.&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;d like to contribute to this wiki - and we&amp;#039;d love to improve it - please shoot us an email requesting an account. Conversely, if we&amp;#039;ve linked to your material (especially YouTube videos) that you&amp;#039;d prefer that we do not reference, let us know and we will promptly remove those links.&lt;br /&gt;
&lt;br /&gt;
Categories covered:&lt;br /&gt;
&lt;br /&gt;
* [[Assembly Language Programming]]  &lt;br /&gt;
* [[Bit-String Flicking]] &lt;br /&gt;
* [[Boolean Algebra]]&lt;br /&gt;
* [[Computer Number Systems]]&lt;br /&gt;
* [[Data Structures]] (needs to add videos)&lt;br /&gt;
* [[Digital Electronics]] (needs to add videos)&lt;br /&gt;
* [[Graph Theory]] (needs to add videos)&lt;br /&gt;
* [[LISP]] &lt;br /&gt;
* [[Prefix/Infix/Postfix Notation]]&lt;br /&gt;
* [[Recursive Functions]]&lt;br /&gt;
* [[Regular Expressions]] (needs to add videos)&lt;br /&gt;
* [[What Does This Program Do?]] (needs to add images and videos)&lt;br /&gt;
* [http://www.acsl.org/categories/C1Elem-ComputerNumberSystems.pdf Elementary DIvision: Computer Number Systems (Contest 1)]&lt;br /&gt;
* [http://www.acsl.org/categories/C2Elem-Prefix-Postfix-InfixNotation.pdf Elementary DIvision: Prefix-Postfix-Infix Notation (Contest 2)]]&lt;br /&gt;
* [http://www.acsl.org/categories/C3Elem-BooleanAlgebra.pdf Elementary DIvision: Boolean Algebra (Contest 3)]&lt;br /&gt;
* [http://www.acsl.org/categories/C4Elem-GraphTheory.pdf Elementary DIvision: Graph Theory (Contest 4)]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [//meta.wikimedia.org/wiki/Help:Contents User&amp;#039;s Guide] for information on using the wiki software&lt;br /&gt;
* [//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [//www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=395</id>
		<title>Data Structures</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=395"/>
		<updated>2018-08-21T14:07:08Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Trees */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;At the heart of virtually every computer program are its algorithms and its data structures.  It is hard to separate these two items, for data structures are meaningless without algorithms to create and manipulate them, and algorithms are usually trivial unless there are data structures on which to operate.  The bigger the data sets, the more important data structures are in various algorithms.&lt;br /&gt;
&lt;br /&gt;
This category concentrates on four of the most basic structures:  &amp;#039;&amp;#039;&amp;#039;stacks&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;queues&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;binary search trees&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;priority queues&amp;#039;&amp;#039;&amp;#039;.  Questions will cover these data structures and implicit algorithms, not specific to implementation language details.&lt;br /&gt;
A &amp;#039;&amp;#039;stack&amp;#039;&amp;#039; is usually used to save information that will need to be processed later.  Items are processed in a “last-in, first-out” (LIFO) order.  A &amp;#039;&amp;#039;queue&amp;#039;&amp;#039; is usually used to process items in the order in which requests are generated; a new item is not processed until all items currently on the queue are processed.  This is also known as “first-in, first-out” (FIFO) order.  A &amp;#039;&amp;#039;binary search tree&amp;#039;&amp;#039; is used when one is storing a set of items and needs to be able to efficiently process the operations of insertion, deletion, and query (i.e. find out if a particular item is part of the set and if not, which item in the set is close to the item in question).  A &amp;#039;&amp;#039;priority queue&amp;#039; is used like a binary search tree, except one cannot delete an arbitrary item, nor can one make an arbitrary query.  One can only find out or delete the smallest element of the set.&lt;br /&gt;
&lt;br /&gt;
== Stacks and Queues ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;stack&amp;#039;&amp;#039; supports two operations:  PUSH and POP.  A command of the form “PUSH(A)” puts the key A at the top of the stack; the command “POP(X)” removes the top item from the stack and stores its value into variable X.  If the stack was empty (because nothing had ever been pushed on it, or if all elements have been popped off of it), then X is given the special value of NIL.  An analogy to this is a stack of books on a desk:  a new book is placed on the top of the stack (pushed) and a book is removed from the top also (popped).  Some textbooks call this data structure a “push-down stack” or a “LIFO stack”.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Queues&amp;#039;&amp;#039; operate just like stacks, except items are removed from the bottom instead of the top.  A good physical analogy of this is the way a train conductor or newspaper boy uses a coin machine to give change:  new coins are added to the tops of the piles, and change is given from the bottom of each.  Some textbooks refer to this data structure as a “FIFO stack”.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence of 14 operations:&lt;br /&gt;
: PUSH(A), PUSH(M), PUSH(E), POP(X), PUSH(R), POP(X), PUSH(I),&lt;br /&gt;
: POP(X), POP(X), POP(X), POP(X), PUSH(C), PUSH(A), PUSH(N)&lt;br /&gt;
&lt;br /&gt;
If these operations are applied to a stack, then the values of the pops are: E, R, I, M, A and NIL.  After all of the operations, there are three items still on the stack:  the N is at the top (it will be the next to be popped, if nothing else is pushed before the pop command), and C is at the bottom.  If, instead of using a stack we used a queue, then the values popped would be: A, M, E, R, I and NIL.  There would be three items still on the queue:  N at the top and C on the bottom.  Since items are removed from the bottom of a queue, C would be the next item to be popped regardless of any additional pushes.  Sometimes the top and bottom of a queue are referred to as the rear and the front respectively.  Therefore, items are pushed/enqueued at the rear of the queue and popped/dequeued at the front of the queue.  There is a similarity to the Britsh “queueing up”. &lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Trees&amp;#039;&amp;#039;, in general, use the following terminology:  the &amp;#039;&amp;#039;root&amp;#039;&amp;#039; is the top node in the tree; &amp;#039;&amp;#039;children&amp;#039;&amp;#039; are the nodes that are immediately below a &amp;#039;&amp;#039;parent&amp;#039;&amp;#039; node; &amp;#039;&amp;#039;leaves&amp;#039;&amp;#039; are the bottom-most nodes on every branch of the tree; and &amp;#039;&amp;#039;siblings&amp;#039;&amp;#039; are nodes that have the same immediate parent.  &lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;binary search tree&amp;#039;&amp;#039; is composed of nodes having three parts:  information (or a key), a pointer to a left child, and a pointer to a right child.  It has the property that the key at every node is always greater than or equal to the key of its left child, and less than the key of its right child.&lt;br /&gt;
&lt;br /&gt;
The following tree is built from the keys A, M, E, R, I, C, A, N in that order:&lt;br /&gt;
&lt;br /&gt;
[[File:tree_1.png]]&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;root&amp;#039;&amp;#039; of the resulting tree is the node containing the key A; note that duplicate keys are inserted into the tree as if they were less than their equal key.  The tree has a &amp;#039;&amp;#039;depth&amp;#039;&amp;#039; (sometimes called height) of 3 because the deepest node is 3 nodes below the root.  The root node has a depth of 0.  Nodes with no children are called leaf nodes; there are four of them in the tree:  A, C, I and N.  An &amp;#039;&amp;#039;external node&amp;#039;&amp;#039; is the name given to a place where a new node could be attached to the tree.  In the final tree above, there are 9 external nodes; these are not drawn.  The tree has an &amp;#039;&amp;#039;internal path length&amp;#039;&amp;#039; of 15 which is the sum of the depths of all nodes.  It has an &amp;#039;&amp;#039;external path length&amp;#039;&amp;#039; of 31 which is the sum of the depths of all external nodes.  To insert the N (the last key inserted), 3 &amp;#039;&amp;#039;comparisons&amp;#039;&amp;#039; were needed against the root A (&amp;gt;), the M (&amp;gt;), and the R (≤).&lt;br /&gt;
&lt;br /&gt;
To perform an &amp;#039;&amp;#039;inorder&amp;#039;&amp;#039; traversal of the tree, recursively traverse the tree by first visiting the left child, then the root, then the right child.  In the tree above, the nodes are visited in the following order: A, A, C, E, I, M, N, and R.  A &amp;#039;&amp;#039;preorder&amp;#039;&amp;#039; travel (root, left, right) visits in the following order: A, A, M, E, C, I, R, and N.  A &amp;#039;&amp;#039;postorder&amp;#039;&amp;#039; traversal (left, right, root) is: A, C, I, E, N, R, M, A.  Inorder traversals are typically used to list the contents of the tree in sorted order. &lt;br /&gt;
&lt;br /&gt;
Binary search trees can support the operations insert, delete, and search.  Moreover, it handles the operations efficiently; in a tree with 1 million items, one can search for a particular value in about log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; 1000000  ≈ 20 steps.  Items can be inserted or deleted in about as many steps, too.  However, binary search trees can become unbalanced, if the keys being inserted are not pretty random.  For example, consider the binary search tree resulting from inserting the keys A, E, I, O, U, Y.  Sophisticated techniques are available to maintain balanced trees.  Binary search trees are “dynamic” data structures that can support an unlimited number of operations in any order. &lt;br /&gt;
&lt;br /&gt;
To search for a node in a binary tree, the following algorithm (in pseudo-code) is used:&lt;br /&gt;
:: p = root&lt;br /&gt;
::found = FALSE&lt;br /&gt;
:: while (p ≠ NIL) and (not found)&lt;br /&gt;
::: if (x&amp;lt;p’s key)&lt;br /&gt;
:::: p = p’s left child&lt;br /&gt;
::: else if (x&amp;gt;p’s key)&lt;br /&gt;
:::: p = p’s right child&lt;br /&gt;
::: else&lt;br /&gt;
:::: found = TRUE&lt;br /&gt;
::: end if&lt;br /&gt;
:: end while&lt;br /&gt;
&lt;br /&gt;
Deleting from a binary search tree is a bit more complicated.  The algorithm we’ll use is as follows:&lt;br /&gt;
:: p = node to delete&lt;br /&gt;
:: f = father of p&lt;br /&gt;
:: if (p has no children)&lt;br /&gt;
::: delete p&lt;br /&gt;
:: else if (p has one child)&lt;br /&gt;
::: make p’s child become f’s child&lt;br /&gt;
::: delete p&lt;br /&gt;
:: else if (p has two children)&lt;br /&gt;
::: l = p’s left child (it might also have children)&lt;br /&gt;
::: r = p’s right child (it might also have children)&lt;br /&gt;
::: make l become f’s child instead of p&lt;br /&gt;
::: stick r onto the l tree&lt;br /&gt;
::: delete p&lt;br /&gt;
:: end if&lt;br /&gt;
&lt;br /&gt;
These diagrams illustrate the algorithm using the tree above.  At the left, we delete I (0 children); in the middle, we delete the R (1 child); and at the right, we delete the M (2 children).&lt;br /&gt;
&lt;br /&gt;
{| class =&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:trees_2.png|128px]]&lt;br /&gt;
|[[File:trees_3.png|128px]]&lt;br /&gt;
|[[File:trees_4.png|256px]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There are also general trees that use the same terminology, but they have 0 or more &amp;#039;&amp;#039;subnodes&amp;#039;&amp;#039; which can be accessed with an array or linked list of pointers.  &amp;#039;&amp;#039;Pre-order&amp;#039;&amp;#039; and &amp;#039;&amp;#039;post-order&amp;#039;&amp;#039; traversals are possible with these trees, but the other algorithms do not work in the same way.  Applications of general trees include game theory, organizational charts, family trees, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Balanced&amp;#039;&amp;#039; trees minimize searching time when every leaf node has a depth of within 1 of every other leaf node.  &amp;#039;&amp;#039;Complete&amp;#039;&amp;#039; trees are filled in at every level and are always balanced.  &amp;#039;&amp;#039;Strictly binary&amp;#039;&amp;#039; trees ensure that every node has either 0 or 2 subnodes.  You may want to consider how there are exactly 5 strictly binary trees with 7 nodes.&lt;br /&gt;
&lt;br /&gt;
== Priority Queues ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;priority queue&amp;#039;&amp;#039; is quite similar to a binary search tree, but one can only delete the smallest item and “search” for the smallest.  These operations can be done in a guaranteed time proportional to the log of the number of items.  One popular way to implement a priority queue is using a &amp;#039;&amp;#039;heap&amp;#039;&amp;#039; data structure.  A heap uses a binary tree (that is, a tree with two children) and maintains the following two properties:  every node is smaller than its two children (nothing is said about the relative magnitude of the two children), and the resulting tree contains no “holes”.  That is, all levels of the tree are completely filled, except the bottom level, which is filled in from the left to the right.  You may want to stop for a moment to think about how you might make an efficient implementation of a priority queue.  This is called a “min-heap”.  “Max-heaps” are also possible.&lt;br /&gt;
&lt;br /&gt;
The algorithm for insertion is not too difficult:  put the new node at the bottom of the tree and then go up the tree, making exchanges with its parent, until the tree is valid.  Consider inserting C into the following heap that has been built by inserting A, M, E, R, I, C, A, N:&lt;br /&gt;
&lt;br /&gt;
[[File:tree_5.png]]&lt;br /&gt;
&lt;br /&gt;
The smallest value is always the root.  To delete it (and one can only delete the smallest value), one replaces it with the bottom-most and right-most element, and then walks down the tree making exchanges with the child in order to insure that the tree is valid.  The following pseudo-code formalizes this notion:&lt;br /&gt;
&lt;br /&gt;
: b = bottom-most and right-most element&lt;br /&gt;
: p = root of tree&lt;br /&gt;
: p’s key = b’s key&lt;br /&gt;
: delete b&lt;br /&gt;
: while (p is larger than either child)&lt;br /&gt;
:: exchange p with smaller child&lt;br /&gt;
:: p = smaller child&lt;br /&gt;
: end while&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates the building of a heap from the characters A, M, E, R, I, C, A, N:&lt;br /&gt;
 		 	 	 	 &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:heap_1.png]] || [[File:heap_2.png]] || [[File:heap_3.png]]  || [[File:heap_4.png]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:heap_5.png]] || [[File:heap_6.png]] || [[File:heap_7.png]]  || [[File:heap_8.png]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Consider an initially empty stack.  What is the value of Z when these operations are performed:&lt;br /&gt;
PUSH(3); PUSH(6); PUSH(8); POP(Y); POP(X);&lt;br /&gt;
PUSH(X-Y); PUSH(4); PUSH(7); POP(Y); POP(X); PUSH(X-Y); POP(X); POP(Y); PUSH(X*Y);POP(Y); POP(X); PUSH(X/Y); POP(Z)	&lt;br /&gt;
&lt;br /&gt;
Solution:  The stack will look like the following:&lt;br /&gt;
3 6 8  →  3 -2  →  3 -2 4 7  →  3 -2 -3  →  3 6  →  0.5&lt;br /&gt;
Therefore, the answer is 0.5 or ½.&lt;br /&gt;
This sequence illustrates a method for evaluating a postfix expression.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Consider creating a min-heap with the letters in the word PROGRAMMING.  What would the bottom-most nodes from left to right be when the entire tree is a heap.&lt;br /&gt;
&lt;br /&gt;
Solution:  The final result of the heap has a root A, row 1 is G, G, row 2 is M, I, P, M, and the bottom row is R, O, R, N on the left side of the tree.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
If one traversed this general tree in preorder (visit the root, and then each of the subtrees from left to right), in what order would nodes be visited?&lt;br /&gt;
&lt;br /&gt;
[[File:tree_s3.png]]&lt;br /&gt;
&lt;br /&gt;
Solution:  A is the root node.  Then do each of its subtrees using recursion so B has 3 subtrees, F has 2 subtrees, and finally C has 1 subtree.  Therefore, the answer is:&lt;br /&gt;
A B D E F H I C G.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Create a binary search tree from the letters in the word PROGRAMMING.  What is the internal path length?	&lt;br /&gt;
&lt;br /&gt;
Solution:  When drawing the tree, P has a depth of 0, O and R have a depth of 1, G and R have a depth of 2, A and M have a depth of 3, M and N have a depth of 4, I has a depth of 5, and G has a depth of 6.  Therefore, the internal path length is 31.&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=394</id>
		<title>Data Structures</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=394"/>
		<updated>2018-08-21T14:04:38Z</updated>

		<summary type="html">&lt;p&gt;Carlen: /* Priority Queues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;At the heart of virtually every computer program are its algorithms and its data structures.  It is hard to separate these two items, for data structures are meaningless without algorithms to create and manipulate them, and algorithms are usually trivial unless there are data structures on which to operate.  The bigger the data sets, the more important data structures are in various algorithms.&lt;br /&gt;
&lt;br /&gt;
This category concentrates on four of the most basic structures:  &amp;#039;&amp;#039;&amp;#039;stacks&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;queues&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;binary search trees&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;priority queues&amp;#039;&amp;#039;&amp;#039;.  Questions will cover these data structures and implicit algorithms, not specific to implementation language details.&lt;br /&gt;
A &amp;#039;&amp;#039;stack&amp;#039;&amp;#039; is usually used to save information that will need to be processed later.  Items are processed in a “last-in, first-out” (LIFO) order.  A &amp;#039;&amp;#039;queue&amp;#039;&amp;#039; is usually used to process items in the order in which requests are generated; a new item is not processed until all items currently on the queue are processed.  This is also known as “first-in, first-out” (FIFO) order.  A &amp;#039;&amp;#039;binary search tree&amp;#039;&amp;#039; is used when one is storing a set of items and needs to be able to efficiently process the operations of insertion, deletion, and query (i.e. find out if a particular item is part of the set and if not, which item in the set is close to the item in question).  A &amp;#039;&amp;#039;priority queue&amp;#039; is used like a binary search tree, except one cannot delete an arbitrary item, nor can one make an arbitrary query.  One can only find out or delete the smallest element of the set.&lt;br /&gt;
&lt;br /&gt;
== Stacks and Queues ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;stack&amp;#039;&amp;#039; supports two operations:  PUSH and POP.  A command of the form “PUSH(A)” puts the key A at the top of the stack; the command “POP(X)” removes the top item from the stack and stores its value into variable X.  If the stack was empty (because nothing had ever been pushed on it, or if all elements have been popped off of it), then X is given the special value of NIL.  An analogy to this is a stack of books on a desk:  a new book is placed on the top of the stack (pushed) and a book is removed from the top also (popped).  Some textbooks call this data structure a “push-down stack” or a “LIFO stack”.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Queues&amp;#039;&amp;#039; operate just like stacks, except items are removed from the bottom instead of the top.  A good physical analogy of this is the way a train conductor or newspaper boy uses a coin machine to give change:  new coins are added to the tops of the piles, and change is given from the bottom of each.  Some textbooks refer to this data structure as a “FIFO stack”.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence of 14 operations:&lt;br /&gt;
: PUSH(A), PUSH(M), PUSH(E), POP(X), PUSH(R), POP(X), PUSH(I),&lt;br /&gt;
: POP(X), POP(X), POP(X), POP(X), PUSH(C), PUSH(A), PUSH(N)&lt;br /&gt;
&lt;br /&gt;
If these operations are applied to a stack, then the values of the pops are: E, R, I, M, A and NIL.  After all of the operations, there are three items still on the stack:  the N is at the top (it will be the next to be popped, if nothing else is pushed before the pop command), and C is at the bottom.  If, instead of using a stack we used a queue, then the values popped would be: A, M, E, R, I and NIL.  There would be three items still on the queue:  N at the top and C on the bottom.  Since items are removed from the bottom of a queue, C would be the next item to be popped regardless of any additional pushes.  Sometimes the top and bottom of a queue are referred to as the rear and the front respectively.  Therefore, items are pushed/enqueued at the rear of the queue and popped/dequeued at the front of the queue.  There is a similarity to the Britsh “queueing up”. &lt;br /&gt;
&lt;br /&gt;
== Trees ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Trees&amp;#039;&amp;#039;, in general, use the following terminology:  the &amp;#039;&amp;#039;root&amp;#039;&amp;#039; is the top node in the tree; &amp;#039;&amp;#039;children&amp;#039;&amp;#039; are the nodes that are immediately below a &amp;#039;&amp;#039;parent&amp;#039;&amp;#039; node; &amp;#039;&amp;#039;leaves&amp;#039;&amp;#039; are the bottom-most nodes on every branch of the tree; and &amp;#039;&amp;#039;siblings&amp;#039;&amp;#039; are nodes that have the same immediate parent.  &lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;binary search tree&amp;#039;&amp;#039; is composed of nodes having three parts:  information (or a key), a pointer to a left child, and a pointer to a right child.  It has the property that the key at every node is always greater than or equal to the key of its left child, and less than the key of its right child.&lt;br /&gt;
&lt;br /&gt;
The following tree is built from the keys A, M, E, R, I, C, A, N in that order:&lt;br /&gt;
&lt;br /&gt;
[[File:tree_1.png]]&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;root&amp;#039;&amp;#039; of the resulting tree is the node containing the key A; note that duplicate keys are inserted into the tree as if they were less than their equal key.  The tree has a &amp;#039;&amp;#039;depth&amp;#039;&amp;#039; (sometimes called height) of 3 because the deepest node is 3 nodes below the root.  The root node has a depth of 0.  Nodes with no children are called leaf nodes; there are four of them in the tree:  A, C, I and N.  An &amp;#039;&amp;#039;external node&amp;#039;&amp;#039; is the name given to a place where a new node could be attached to the tree.  In the final tree above, there are 9 external nodes; these are not drawn.  The tree has an &amp;#039;&amp;#039;internal path length&amp;#039;&amp;#039; of 15 which is the sum of the depths of all nodes.  It has an &amp;#039;&amp;#039;external path length&amp;#039;&amp;#039; of 31 which is the sum of the depths of all external nodes.  To insert the N (the last key inserted), 3 &amp;#039;&amp;#039;comparisons&amp;#039;&amp;#039; were needed against the root A (&amp;gt;), the M (&amp;gt;), and the R (≤).&lt;br /&gt;
&lt;br /&gt;
To perform an &amp;#039;&amp;#039;inorder&amp;#039;&amp;#039; traversal of the tree, recursively traverse the tree by first visiting the left child, then the root, then the right child.  In the tree above, the nodes are visited in the following order: A, A, C, E, I, M, N, and R.  A &amp;#039;&amp;#039;preorder&amp;#039;&amp;#039; travel (root, left, right) visits in the following order: A, A, M, E, C, I, R, and N.  A &amp;#039;&amp;#039;postorder&amp;#039;&amp;#039; traversal (left, right, root) is: A, C, I, E, N, R, M, A.  Inorder traversals are typically used to list the contents of the tree in sorted order. &lt;br /&gt;
&lt;br /&gt;
Binary search trees can support the operations insert, delete, and search.  Moreover, it handles the operations efficiently; in a tree with 1 million items, one can search for a particular value in about log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; 1000000  ≈ 20 steps.  Items can be inserted or deleted in about as many steps, too.  However, binary search trees can become unbalanced, if the keys being inserted are not pretty random.  For example, consider the binary search tree resulting from inserting the keys A, E, I, O, U, Y.  Sophisticated techniques are available to maintain balanced trees.  Binary search trees are “dynamic” data structures that can support an unlimited number of operations in any order. &lt;br /&gt;
&lt;br /&gt;
To search for a node in a binary tree, the following algorithm (in pseudo-code) is used:&lt;br /&gt;
:: p = root&lt;br /&gt;
::found = FALSE&lt;br /&gt;
:: while (p ≠ NIL) and (not found)&lt;br /&gt;
::: if (x&amp;lt;p’s key)&lt;br /&gt;
:::: p = p’s left child&lt;br /&gt;
::: else if (x&amp;gt;p’s key)&lt;br /&gt;
:::: p = p’s right child&lt;br /&gt;
::: else&lt;br /&gt;
:::: found = TRUE&lt;br /&gt;
::: end if&lt;br /&gt;
:: end while&lt;br /&gt;
&lt;br /&gt;
Deleting from a binary search tree is a bit more complicated.  The algorithm we’ll use is as follows:&lt;br /&gt;
:: p = node to delete&lt;br /&gt;
:: f = father of p&lt;br /&gt;
:: if (p has no children)&lt;br /&gt;
::: delete p&lt;br /&gt;
:: else if (p has one child)&lt;br /&gt;
::: make p’s child become f’s child&lt;br /&gt;
::: delete p&lt;br /&gt;
:: else if (p has two children)&lt;br /&gt;
::: l = p’s left child (it might also have children)&lt;br /&gt;
::: r = p’s right child (it might also have children)&lt;br /&gt;
::: make l become f’s child instead of p&lt;br /&gt;
::: stick r onto the l tree&lt;br /&gt;
::: delete p&lt;br /&gt;
:: end if&lt;br /&gt;
&lt;br /&gt;
These diagrams illustrate the algorithm using the tree above.  At the left, we delete I (0 children); in the middle, we delete the R (1 child); and at the right, we delete the M (2 children).&lt;br /&gt;
&lt;br /&gt;
{| class =&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:trees_2.png|128px]]&lt;br /&gt;
|[[File:trees_3.png|128px]]&lt;br /&gt;
|[[File:trees_4.png|128px]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There are also general trees that use the same terminology, but they have 0 or more &amp;#039;&amp;#039;subnodes&amp;#039;&amp;#039; which can be accessed with an array or linked list of pointers.  &amp;#039;&amp;#039;Pre-order&amp;#039;&amp;#039; and &amp;#039;&amp;#039;post-order&amp;#039;&amp;#039; traversals are possible with these trees, but the other algorithms do not work in the same way.  Applications of general trees include game theory, organizational charts, family trees, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Balanced&amp;#039;&amp;#039; trees minimize searching time when every leaf node has a depth of within 1 of every other leaf node.  &amp;#039;&amp;#039;Complete&amp;#039;&amp;#039; trees are filled in at every level and are always balanced.  &amp;#039;&amp;#039;Strictly binary&amp;#039;&amp;#039; trees ensure that every node has either 0 or 2 subnodes.  You may want to consider how there are exactly 5 strictly binary trees with 7 nodes.&lt;br /&gt;
&lt;br /&gt;
== Priority Queues ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;priority queue&amp;#039;&amp;#039; is quite similar to a binary search tree, but one can only delete the smallest item and “search” for the smallest.  These operations can be done in a guaranteed time proportional to the log of the number of items.  One popular way to implement a priority queue is using a &amp;#039;&amp;#039;heap&amp;#039;&amp;#039; data structure.  A heap uses a binary tree (that is, a tree with two children) and maintains the following two properties:  every node is smaller than its two children (nothing is said about the relative magnitude of the two children), and the resulting tree contains no “holes”.  That is, all levels of the tree are completely filled, except the bottom level, which is filled in from the left to the right.  You may want to stop for a moment to think about how you might make an efficient implementation of a priority queue.  This is called a “min-heap”.  “Max-heaps” are also possible.&lt;br /&gt;
&lt;br /&gt;
The algorithm for insertion is not too difficult:  put the new node at the bottom of the tree and then go up the tree, making exchanges with its parent, until the tree is valid.  Consider inserting C into the following heap that has been built by inserting A, M, E, R, I, C, A, N:&lt;br /&gt;
&lt;br /&gt;
[[File:tree_5.png]]&lt;br /&gt;
&lt;br /&gt;
The smallest value is always the root.  To delete it (and one can only delete the smallest value), one replaces it with the bottom-most and right-most element, and then walks down the tree making exchanges with the child in order to insure that the tree is valid.  The following pseudo-code formalizes this notion:&lt;br /&gt;
&lt;br /&gt;
: b = bottom-most and right-most element&lt;br /&gt;
: p = root of tree&lt;br /&gt;
: p’s key = b’s key&lt;br /&gt;
: delete b&lt;br /&gt;
: while (p is larger than either child)&lt;br /&gt;
:: exchange p with smaller child&lt;br /&gt;
:: p = smaller child&lt;br /&gt;
: end while&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates the building of a heap from the characters A, M, E, R, I, C, A, N:&lt;br /&gt;
 		 	 	 	 &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|[[File:heap_1.png]] || [[File:heap_2.png]] || [[File:heap_3.png]]  || [[File:heap_4.png]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:heap_5.png]] || [[File:heap_6.png]] || [[File:heap_7.png]]  || [[File:heap_8.png]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Consider an initially empty stack.  What is the value of Z when these operations are performed:&lt;br /&gt;
PUSH(3); PUSH(6); PUSH(8); POP(Y); POP(X);&lt;br /&gt;
PUSH(X-Y); PUSH(4); PUSH(7); POP(Y); POP(X); PUSH(X-Y); POP(X); POP(Y); PUSH(X*Y);POP(Y); POP(X); PUSH(X/Y); POP(Z)	&lt;br /&gt;
&lt;br /&gt;
Solution:  The stack will look like the following:&lt;br /&gt;
3 6 8  →  3 -2  →  3 -2 4 7  →  3 -2 -3  →  3 6  →  0.5&lt;br /&gt;
Therefore, the answer is 0.5 or ½.&lt;br /&gt;
This sequence illustrates a method for evaluating a postfix expression.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Consider creating a min-heap with the letters in the word PROGRAMMING.  What would the bottom-most nodes from left to right be when the entire tree is a heap.&lt;br /&gt;
&lt;br /&gt;
Solution:  The final result of the heap has a root A, row 1 is G, G, row 2 is M, I, P, M, and the bottom row is R, O, R, N on the left side of the tree.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
If one traversed this general tree in preorder (visit the root, and then each of the subtrees from left to right), in what order would nodes be visited?&lt;br /&gt;
&lt;br /&gt;
[[File:tree_s3.png]]&lt;br /&gt;
&lt;br /&gt;
Solution:  A is the root node.  Then do each of its subtrees using recursion so B has 3 subtrees, F has 2 subtrees, and finally C has 1 subtree.  Therefore, the answer is:&lt;br /&gt;
A B D E F H I C G.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Create a binary search tree from the letters in the word PROGRAMMING.  What is the internal path length?	&lt;br /&gt;
&lt;br /&gt;
Solution:  When drawing the tree, P has a depth of 0, O and R have a depth of 1, G and R have a depth of 2, A and M have a depth of 3, M and N have a depth of 4, I has a depth of 5, and G has a depth of 6.  Therefore, the internal path length is 31.&lt;br /&gt;
&lt;br /&gt;
= Video Resources =&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Trees_4.png&amp;diff=393</id>
		<title>File:Trees 4.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Trees_4.png&amp;diff=393"/>
		<updated>2018-08-21T14:02:05Z</updated>

		<summary type="html">&lt;p&gt;Carlen: Carlen uploaded a new version of File:Trees 4.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_4.png&amp;diff=392</id>
		<title>File:Graph 4.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_4.png&amp;diff=392"/>
		<updated>2018-08-21T13:26:55Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_2.png&amp;diff=391</id>
		<title>File:Graph 2.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_2.png&amp;diff=391"/>
		<updated>2018-08-21T13:23:06Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph1.png&amp;diff=390</id>
		<title>File:Graph1.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph1.png&amp;diff=390"/>
		<updated>2018-08-21T13:22:32Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_s4.png&amp;diff=389</id>
		<title>File:Graph s4.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_s4.png&amp;diff=389"/>
		<updated>2018-08-21T13:22:14Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Graph_s1.png&amp;diff=388</id>
		<title>File:Graph s1.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Graph_s1.png&amp;diff=388"/>
		<updated>2018-08-21T13:21:57Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=File:Konigsberg.png&amp;diff=387</id>
		<title>File:Konigsberg.png</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=File:Konigsberg.png&amp;diff=387"/>
		<updated>2018-08-21T13:21:35Z</updated>

		<summary type="html">&lt;p&gt;Carlen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Carlen</name></author>
	</entry>
</feed>