http://www.categories.acsl.org/wiki/api.php?action=feedcontributions&user=Partha&feedformat=atomACSL Category Descriptions - User contributions [en]2024-03-28T15:52:12ZUser contributionsMediaWiki 1.37.1http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=810Boolean Algebra2020-09-01T01:47:03Z<p>Partha: /* Operators */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=809Boolean Algebra2020-09-01T01:44:41Z<p>Partha: /* Operators */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ x\ \ </math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=808Boolean Algebra2020-09-01T01:43:31Z<p>Partha: /* Operators */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=807Boolean Algebra2020-09-01T01:42:56Z<p>Partha: /* Operators */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''e[X]clusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=806Boolean Algebra2020-09-01T01:41:44Z<p>Partha: /* Operators */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''e[[X]]clusive OR'' (often called '''XOR''') and ''e[[X]]clusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=805Boolean Algebra2020-09-01T01:39:11Z<p>Partha: /* Operators */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are e'''X'''clusive '''OR''' (often called '''XOR''') and e'''X'''clusive '''NOR''' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=804Boolean Algebra2020-09-01T01:33:16Z<p>Partha: </p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are ''and'', ''or'', and ''not''. The secondary operators are ''exclusive or'' (often called ''xor'') and ''exclusive nor'' (sometimes called ''equivalence''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
*The ''and'' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The ''or'' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The ''not'' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The ''xor'' 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 ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The ''xnor'' of two values is true whenever the values are the same. It is the ''not'' of the ''xor'' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*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:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer'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. <br />
<br />
* 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 "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' 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)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
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'll <br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
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.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
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<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Computer_Number_Systems&diff=803Computer Number Systems2020-09-01T01:11:32Z<p>Partha: </p>
<hr />
<div>All digital computers, from supercomputers to your smartphone, are electronic devices and ultimately can do one thing: detect whether an electrical signal is on or off. That basic information, called a ''bit'' ('''bi'''nary digi'''t'''), has two values: a 1 (or ''true'') when the signal is on, and a 0 (of ''false'') when the signal is off. Larger values can be stored by a group of bits. <math></math><br />
<br />
The number system is the system of naming or representing numbers. The number system we use in our daily life is known as '''Decimal''' number system because they are based on 10 different digits: 0, 1, 2, ..., 8, and 9. These numbers are called number with base-10. Base is generally written as subscript suffixed to a number. With base notation, the number "twelve thousand three hundred and forty-five" is written as $12345_{10}$. While we do not use the base-10 notation in our usual writing, we need to use it for other number systems. We will see the use of this base notation throughout this article to differentiate between numbers.<br />
<br />
== Different Number Systems ==<br />
<br />
In computer science, apart from the decimal system, three additional number systems are used. They are '''binary''', '''octal''', and '''hexadecimal'''. Binary systems is for the number system with base 2. Octal stands for the number system with base 8 while hexadecimal stands for the number system with base 16.<br />
<br />
As you might guess, binary deals only with 2 digits — 0 and 1. Octal has 8 digits and hexadecimal has 16 unique digits. The table below displays the Number Systems with Base, Digits Used, and Sample Representation:<br />
:{| class="wikitable"<br />
!Number System<br />
!Base<br />
!Digits Used<br />
!Sample Representation<br />
|-<br />
|Binary<br />
|8<br />
|0,1<br />
|$10110_{2}$<br />
|-<br />
|Octal<br />
|8<br />
|0,1,2,3,4,5,6,7<br />
|$75321_{8}$<br />
|-<br />
|Decimal<br />
|10<br />
|0,1,2,3,4,5,6,7,8,9<br />
|$97425_{10}$ or simply 97425<br />
|-<br />
|Hexadecimal<br />
|10<br />
|0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F<br />
|$54321_{16}$<br />
|}<br />
<br />
The letters A, B, C, D, E, and F represent an unique digit each in hexadecimal system where A stands for 10, B for 11, C for 12, D for 13, E for 14 and F for 15.<br />
<br />
== Number of Bits to Hold All Digits ==<br />
<br />
Since computer uses ''bits'' to store and process information, we need to understand the minimum requirement of bits for each number system.<br />
<br />
As one ''bit'' can store either 0 or 1, it has a capacity of storing 2 values or $2^{1}$ values which is $2^{number\_of\_bits}$.<br />
<br />
For 2 ''bits'', the capacity increases to 4 different numbers which are 00, 01, 10, and 11. We can say 2 bits can store $2^{2}$ values. The capacity grows with the available ''bits'' in multiple of 2.<br />
<br />
So to represent all Octal digits (8 digits), we need to allocate 3 ''bits'' as $2^3$ can accommodate 8 different values. And to assign all Hexadecimal digits (16 digits), we need to allocate 4 ''bits'' as $2^4$ = 16.<br />
<br />
== Need for Octal and Hexadecimal Numbers ==<br />
<br />
While computer can stores the numbers in bits (binary format) only, what is the need for Octal and Hexadecimal number systems?<br />
<br />
Because binary numbers could get very long even for small decimal numbers, they grouped 3 binary digits together to form one base 8 digit and called that octal and grouped 4 binary digits together to form other base 16 digit and called that hexadecimal. The following table shows equivalent values in these bases: <br />
<br />
:{| class="wikitable" style="text-align:center"<br />
!Three digits (0 for left-most)<br />
!Four digits (needed for base 16) <br />
|-<br />
|0000 = 0<br />
|1000 = 8 <br />
|-<br />
|0001 = 1<br />
|1001 = 9 <br />
|-<br />
|0010 = 2<br />
|1010 = A (10) <br />
|-<br />
|0011 = 3<br />
|1011 = B (11) <br />
|-<br />
|0100 = 4<br />
|1100 = C (12) <br />
|-<br />
|0101 = 5<br />
|1101 = D (13) <br />
|-<br />
|0110 = 6<br />
|1110 = E (14) <br />
|-<br />
|0111 = 7<br />
|1111 = F (15) <br />
|}<br />
<br />
As you can see, the largest value that can be represented with 3 binary digits (when the first digit is a 0) is 7 and the largest value with 4 bits is 15. However, because all digits must be single characters, the letters A – F are used to represent the values 10 to 15. Therefore, in base 8, the digits must be 0 to 7 and in base 16 the digits must be 0 – 9, A – F. <br />
<br />
== Formation of Numbers ==<br />
<br />
The formation of any number goes by the digit multiplied by it's place value and adding them together. For example, we read and understand the number 12345 as twelve thousand three hundred and forty-five which has five digits: 1, 2, 3, 4, and 5. The number 12345 is completely different from the number 54321, which is also having the exact same 5 digits. This tells us that the digit with its place value give us the number. So, how to create/form a number in decimal system? Let's see using these 2 example numbers:<br />
:$12345 = 1×10000 + 2×1000 + 3×100 + 4×10 + 5×1 = 1×10^{4}+ 2×10^{3}+ 3×10^{2}+ 4×10^{1}+ 5×10{0}.$<br />
:$54321 = 5×10000 + 4×1000 + 3×100 + 2×10 + 1×1 = 5×10^{4}+ 4×10^{3}+ 3×10^{2}+ 2×10^{1}+ 1×10{0}.$<br />
<br />
The expanded notation in the decimal number system above can represent different numbers by using powers of 10.<br />
<br />
Since formation of a number follows the same rule in all number system, all other bases work the same way as follows:<br />
<br />
:$1101_{2} = 1 × 2^3 + 1 × 2^2 + 0 × 2^1 + 1 × 2^0 = 8 + 4 + 0 + 1 = 13_{10}$ <br />
:$175_{8} = 1 × 8^2 + 7 × 8^1 + 5 × 8^0 = 1 × 64 + 7 × 8 + 5 × 1 = 64 + 56 + 5 = 125_{10}$. <br />
:$A5E_{16} = 10 × 16^2 + 5 × 16^1 + 14 × 16^0 = 10 × 256 + 5 × 16 + 14 × 1 = 2560 + 80 + 14 = 2654_{10}$. <br />
<br />
<br />
'''Grouping Binary Digits for Octal and Hexadecimal Numbers''' <br />
<br />
An easy way to convert between bases 2, 8, and 16 is by grouping bits together and using the table above. <br />
:$1001010110_{2} = \ \ 001\ \ \ 001\ \ \ 010\ \ \ 110_{2} = 1126_{8}$ and <br />
:$1001010110_{2} = 0010\ 0101\ 0110_{2} \ \ \ \ \ \ \ \ \ = 256_{16}$<br />
Notice that grouping is always done starting with the last digit.<br />
<br />
'''Using Hexadecimal Numbers to Represent Colors'''<br />
<br />
Computers use hexadecimal numbers to represent various colors in computer graphics because all computer screens use combinations of red, green, and blue light or RGB to represent thousands of different colors. Two digits are used for each so the hexadecimal number “#FF0000” represents the color red, “#00FF00” represents green, and “#0000FF” represents blue. The color black is “#000000” and white is “#FFFFFF”. <br />
<br />
The hash tag or number sign is used to denote a hexadecimal number. $FF_{16} = F (15) × 16 + F (15) × 1 = 240 + 15 = 255_{10}$ so there are 0 to 255 or 256 different shades of each color or $256^{3} = 16,777,216$ different colors. <br />
<br />
The following web site has nearly every color name, along with its hex code and decimal values: <br />
<br />
:https://www.rapidtables.com/web/color/RGB_Color.html <br />
<br />
For example “salmon” is “#FA8072” which represents the decimal numbers 250 (hex FA), 128 (hex 80), and 114 (hex 72).<br />
<br />
== Resources ==<br />
<br />
[https://ryanstutorials.net/ Ryan's Tutorials] covers this topic beautifully. Rather than trying to duplicate that work, we'll point you to the different sections:<br />
<br />
:[https://ryanstutorials.net/binary-tutorial/ 1. Number Systems] - An introduction to what numbers systems are all about, with emphasis on decimal, binary, octal, and hexadecimal. ACSL will typically identify the base of a number using a subscript. For example, $123_8$ is an octal number, whereas $123_{16}$ is a hexadecimal number. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-conversions.php 2. Binary Conversions] - This section shows how to convert between binary, decimal, hexadecimal and octal numbers. In the [https://ryanstutorials.net/binary-tutorial/binary-conversions.php#activities ''Activities''] section, you can practice converting numbers. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-arithmetic.php 3. Binary Arithmetic] - Describes how to perform various arithmetic operations (addition, subtraction, multiplication, and division) with binary numbers. ACSL problems will also cover basic arithmetic in other bases, such as adding and subtracting together 2 hexadecimal numbers. ACSL problems will not cover division in other bases.<br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-negative-numbers.php 4. Negative Numbers] - ACSL problems will not cover how negative numbers are represented in binary. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-floating-point.php 5. Binary Fractions and Floating Point] - The first part of this section is relevant to ACSL: fractions in other bases. ACSL will not cover floating point numbers in other basis. So, focus on the section [https://ryanstutorials.net/binary-tutorial/binary-floating-point.php#convertfraction Converting to a Binary Fraction], but keep in mind that ACSL problems may also cover octal and hexadecimal fractions.<br />
<br />
The [https://coolconversion.com/math/binary-octal-hexa-decimal/ CoolConversion.com online calculator] is another online app for practicing conversion from/to decimal, hexadecimal, octal and binary; this tool shows the steps that one goes through in the conversion.<br />
<br />
== Format of ACSL Problems ==<br />
<br />
The problems in this category will focus on converting between binary, octal, decimal, and hexadecimal, basic arithmetic of numbers in those bases, and, occasionally, fractions in those bases.<br />
<br />
To be successful in this category, you must know the following facts cold:<br />
<br />
# The decimal value of each hex digit A, B, C, D, E, F <br />
# The binary value of each hex digit A, B, C, D, E, F<br />
# Powers of 2, up to 4096<br />
# Powers of 8, up to 4096<br />
# Powers of 16, up to 65,536<br />
<br />
== Sample Problems ==<br />
<br />
=== Sample Problem 1 ===<br />
<br />
Solve for $x$ where $x_{16}=3676_8$.<br />
<br />
'''Solution:''' One method of solution is to convert $3676_8$ into base 10, and then convert that number into base 16 to yield the value of $x$.<br />
<br />
An easier solution, less prone to arithmetic mistakes, is to convert from octal (base 8) to hexadecimal (base 16) through the binary (base 2) representation of the number:<br />
<br />
$$\begin{align}<br />
3676_8 &= 011 ~ 110 ~ 111 ~ 110_2 & \text{convert each octal digit into base 2}\hfill\cr <br />
&= 0111 ~ 1011 ~ 1110_2 & \text{group by 4 bits, from right-to-left}\hfill\cr<br />
&= 7 ~ \text{B} ~ \text{E}_{16} & \text{convert each group of 4 bits into a hex digit}\cr<br />
\end{align}$$<br />
<br />
=== Sample Problem 2 ===<br />
<br />
Solve for $x$ in the following hexadecimal equation: $ x= \text{F5AD}_{16} - \text{69EB}_{16}$<br />
<br />
'''Solution:''' One could convert the hex numbers into base 10, perform the subtraction, and then convert the answer back to base 16. However, <br />
working directly in base 16 isn't too hard. <br />
As in conventional decimal arithmetic, one works from right-to-left, from the least significant digits to the most. <br />
<br />
:The rightmost digit becomes 2, because D-B=2. <br />
:The next column is A-E. We need to ''borrow'' a one from the 5 column, and 1A-E=C <br />
:In the next column, 4-9=B, again, borrowing a 1 from the next column.<br />
:Finally, the leftmost column, E-6=8<br />
<br />
Combining these results of each column, we get a final answer of $8BC2_{16}$.<br />
<br />
=== Sample Problem 3 ===<br />
<br />
How many numbers from 100 to 200 in base 10 consist of distinct<br />
ascending digits and also have distinct ascending hex digits when<br />
converted to base 16? <br />
<br />
'''Solution:''' There are 13 numbers that have ascending digits in both bases from 100<br />
to 200. They are (in base 10):<br />
123 (7B), 124, 125, 126, 127 (7F), 137 (89), 138, 139 (8B), 156 (9C), 157, 158, 159 (9F), 189 (BD)<br />
<br />
== Video Resources ==<br />
<br />
There are many YouTube videos about computer number systems. Here are a handful that cover the topic nicely, without too many ads:<br />
<br />
{|<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aW3qCcH6Dao</youtube><br />
| [https://youtu.be/aW3qCcH6Dao ''Number Systems - Converting Decimal, Binary and Hexadecimal'' ('''Joe James''')]<br />
<br />
An introduction to number systems, and how to convert between decimal, binary and hexadecimal numbers. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/m1JtWKuTLR0</youtube><br />
| [https://youtu.be/m1JtWKuTLR0 ''Lesson 2.3 : Hexadecimal Tutorial'' ('''Carl Herold''')]<br />
<br />
The video focuses on hexadecimal numbers: their relationship to binary numbers and how to convert to decimal numbers. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/WR67syBDzew</youtube><br />
| [https://youtu.be/WR67syBDzew ''Hexes and the Magic of Base 16 - Vaidehi Joshi - May 2017' ('''DonutJS''')]<br />
<br />
A fun introduction to hexadecimal numbers, focusing a bit <br />
on using hex numbers for specifying RGB colors. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jvx-NrILgpE</youtube><br />
| [https://youtu.be/jvx-NrILgpE ''Collins Lab: Binary & Hex'' ('''Adafruit Industries''')]<br />
<br />
A professionally produced video that explains the number systems, how and why binary numbers are fundamental to computer science, and why hexadecimal is important to computer programmers. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=802Graph Theory2020-09-01T01:02:44Z<p>Partha: /* Problem 2 */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|200px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a $4×4$ matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|600px]]<br />
<br />
By construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|250px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A → B → C and A → D → C. This also says that there is exactly 1 path of length 2 from A to D which is A → B → D, exactly 1 path of length 2 from B to B which is B → C → B and so on.<br />
<br />
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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A → A → C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A → A → A → A → C, A → A → C → A → C, A → C → A → A → C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=801Graph Theory2020-09-01T01:01:09Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|200px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a $4×4$ matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|600px]]<br />
<br />
By construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|250px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A → B → C and A → D → C. This also says that there is exactly 1 path of length 2 from A to D which is A → B → D, exactly 1 path of length 2 from B to B which is B → C → B and so on.<br />
<br />
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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:AdjMatrix2.png&diff=800File:AdjMatrix2.png2020-09-01T00:47:07Z<p>Partha: Partha uploaded a new version of File:AdjMatrix2.png</p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=799Graph Theory2020-09-01T00:22:10Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|200px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|600px]]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|250px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:DirectedGraph.png&diff=798File:DirectedGraph.png2020-09-01T00:21:28Z<p>Partha: Partha uploaded a new version of File:DirectedGraph.png</p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=797Graph Theory2020-08-31T23:48:44Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|300px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|600px]]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|250px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=796Graph Theory2020-08-31T23:46:37Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|250px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|600px]]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|300px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=795Graph Theory2020-08-31T23:46:17Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|250px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|200px]]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|300px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=794Graph Theory2020-08-31T23:45:46Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|250px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png]|200px]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|300px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:AdjMatrix.png&diff=793File:AdjMatrix.png2020-08-31T23:44:26Z<p>Partha: Partha uploaded a new version of File:AdjMatrix.png</p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:AdjMatrix.png&diff=792File:AdjMatrix.png2020-08-31T23:44:04Z<p>Partha: Partha uploaded a new version of File:AdjMatrix.png</p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=791Graph Theory2020-08-31T23:43:25Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|150px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png]]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|300px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=790Graph Theory2020-08-31T23:42:15Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|300px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix (the left empty matrix). We then put 1 for all the edges considering their direction (see the middle one) and finally put 0 for all unfilled cells which gives us the adjacency matrix (the rightmost one, highlighted).<br />
<br />
[[File:AdjMatrix.png|300px]]<br />
<br />
Bu construction, each path of this matrix is of length 1. Now if we raise the power of matrix M to 2, we get:<br />
<br />
[[File:AdjMatrix2.png|300px]]<br />
<br />
And this says that there are 2 paths of length 2 from A to C. By examination we can see they are A->B->C and A->D->C. This also says that there is exactly 1 path of length 2 from A to D which is A->B->D, exactly 1 path of length 2 from B to B which is B->c->B and so on.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:AdjMatrix.png&diff=789File:AdjMatrix.png2020-08-31T23:38:12Z<p>Partha: Partha uploaded a new version of File:AdjMatrix.png</p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=788Graph Theory2020-08-31T23:37:53Z<p>Partha: /* Adjacency Matrices */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
<br />
It is frequently convenient to represent a graph by a matrix known as Adjacency Matrix. Let us understand using the 4 node directed graph below:<br />
<br />
[[File:DirectedGraph.png|500px]]<br />
<br />
To draw adjacency matrix, we put all nodes in rows and also arrange them in columns which gives a 4x4 matrix. We put 1 for all<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:DirectedGraph.png&diff=787File:DirectedGraph.png2020-08-31T23:29:24Z<p>Partha: </p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:AdjMatrix2.png&diff=786File:AdjMatrix2.png2020-08-31T23:28:54Z<p>Partha: </p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:AdjMatrix.png&diff=785File:AdjMatrix.png2020-08-31T23:28:43Z<p>Partha: </p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=784Graph Theory2020-08-31T22:44:30Z<p>Partha: /* Problem 2 */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$). By inspection, the only path of length 2 is A->A->C.<br />
<br />
There are 3 paths of length 4 (cell [1,3] in $M^4$) and they are A->A->A->A->C, A->A->C->A->C, A->C->A->A->C.<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=783Graph Theory2020-08-31T21:36:32Z<p>Partha: /* Trees & Forest */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
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.<br />
<br />
[[File:forest.png|500px]]<br />
<br />
The graph on the left shown above is a tree because it has no cycles and vertices are connected. It has four vertices and three edges, i.e., for ''N'' vertices ''N-1'' edges as mentioned in the definition.<br />
<br />
A ''spanning tree'' 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=782Graph Theory2020-08-31T21:34:06Z<p>Partha: /* Trees */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees & Forest ==<br />
<br />
A graph with no cycles is called a ''tree''. There is only one path between any two nodes in a tree. <br />
<br />
[[File:forest.png|500px]]<br />
<br />
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. 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.<br />
<br />
A group of disconnected trees is called a ''forest''.<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=781Graph Theory2020-08-31T21:33:25Z<p>Partha: /* Trees */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees ==<br />
<br />
A graph with no cycles is called a ''tree''. There is only one path between any two nodes in a tree. <br />
<br />
[[File:forest.png|500px]]<br />
<br />
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. 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 ''forest.''<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=780Graph Theory2020-08-31T21:33:09Z<p>Partha: /* Trees */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees ==<br />
<br />
A graph with no cycles is called a ''tree''. There is only one path between any two nodes in a tree. <br />
<br />
[[File:forest.png|400px]]<br />
<br />
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. 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 ''forest.''<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=779Graph Theory2020-08-31T21:32:46Z<p>Partha: /* Trees */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees ==<br />
<br />
A graph with no cycles is called a ''tree''. There is only one path between any two nodes in a tree. <br />
<br />
[[File:forest.png]]<br />
<br />
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. 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 ''forest.''<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:Forest.png&diff=778File:Forest.png2020-08-31T21:31:29Z<p>Partha: Partha uploaded a new version of File:Forest.png</p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=777Graph Theory2020-08-31T21:29:03Z<p>Partha: /* Trees */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees ==<br />
<br />
A graph with no cycles is called a ''tree''. There is only one path between any two nodes in a tree. <br />
<br />
[[File:forest.png|250px]]<br />
<br />
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. 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 ''forest.''<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:Forest.png&diff=776File:Forest.png2020-08-31T21:28:23Z<p>Partha: </p>
<hr />
<div></div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=775Graph Theory2020-08-31T21:27:47Z<p>Partha: /* Trees */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees ==<br />
<br />
A graph with no cycles is called a ''tree''. There is only one path between any two nodes in a tree. <br />
<br />
[[File:forest.png|150px]]<br />
<br />
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. 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 ''forest.''<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=774Graph Theory2020-08-31T21:07:24Z<p>Partha: </p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Trees ==<br />
<br />
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. 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 ''forest.''<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=773Graph Theory2020-08-31T21:06:23Z<p>Partha: /* Terminology */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one vertex A to another vertex B is the same as from vertex B to vertex A. So the graph above is an ''undirected graph''. Similarly graphs having a direction associated with each edge is known as ''directed graph'' (see section below).<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Trees ==<br />
<br />
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. 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 ''forest.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=772Graph Theory2020-08-31T21:01:36Z<p>Partha: /* Terminology */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
The edges of the above graph has no directions meaning the edge from one node A to another node B is the same as from node B to node A. So the graph above is an ''undirected graph''.<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Trees ==<br />
<br />
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. 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 ''forest.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Graph_Theory&diff=771Graph Theory2020-08-31T21:00:23Z<p>Partha: /* Overview */</p>
<hr />
<div>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.<br />
<br />
== Overview ==<br />
<br />
A ''graph'' is a collection of vertices and edges. An ''edge'' is a connection between two ''vertices'' (sometimes referred to as ''nodes''). 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:<br />
<br />
::[[File:Graph fig1a.svg|150px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph fig1b.svg|150px]]<br />
<br />
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}.<br />
<br />
== Terminology ==<br />
<br />
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, FGHE is path from F to E in the graph above. A ''simple path'' is a path with no vertex repeated. For example, FGHEG is not a simple path. <br />
<br />
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 two connected components: {A, B, D} and {C, E, F, G, H}.<br />
<br />
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 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.<br />
<br />
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<sup>2</sup> (or V(V-1)/2 in an undirected graph). Graphs with 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.''<br />
<br />
== Trees ==<br />
<br />
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. 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 ''forest.''<br />
<br />
== Directed Graphs ==<br />
<br />
''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:<br />
<br />
[[File:Graph fig1a directed.svg|150px]]<br />
<br />
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 ''undirected graph'' 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 ''dag'' (directed acyclic graph).<br />
<br />
== Adjacency Matrices ==<br />
<br />
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 "zero" 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''.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
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}.<br />
<br />
'''Solution:'''<br />
The graph is as follows:<br />
<br />
::[[File:graph sample1.svg|196px]]<br />
<br />
By inspection, the cycles are: ABA, BCDB, and CDC. Thus, there are 3 cycles in the graph.<br />
<!--<br />
=== Sample Problem 2 ===<br />
<br />
Given the directed graph below, how many more paths of length 3 would exist if edges AE and EA were added?<br />
<br />
[[File:graph_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
By using adjacency matrices, the current one is<br />
<br />
[[File:matrix1_s2.png]]<br />
<br />
After adding edges AE and EA, the matrices are:<br />
<br />
[[File:matrix2_s2.png]]<br />
<br />
There are 6 more paths of length 2 since 16 – 10 = 6.<br />
--><br />
<br />
=== Problem 2===<br />
<br />
In the following directed graph, find the total number of different paths from vertex A to vertex C of length 2 or 4.<br />
<br />
::[[File:graph sample3.svg|128px]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
[[File:matrix_s3.png]]<br />
<br />
There is 1 path of length 2 from A to C (cell [1,3] in $M^2$) <br />
and 3 paths of length 4 (cell [1,3] in $M^4$).<br />
<br />
=== Problem 3 ===<br />
<br />
Given the adjacency matrix, draw the directed graph.<br />
<br />
[[File:matrix_s4.png]]<br />
<br />
'''Solution:'''<br />
<br />
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:<br />
<br />
: [[File:Graph sample4soln-a.svg|128px]] <span style="display:inline-block; width: 5em;"></span>[[File:Graph sample4soln-d.svg|128px]]<br />
<br />
== Video Resources ==<br />
<br />
===ACSL Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/pWCuRRqBGvw</youtube><br />
| [https://youtu.be/pWCuRRqBGvw ''ACSL Math: Graph Theory'' ('''Raj Joshi''')]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/H96Lo2q_FSk</youtube><br />
| [https://youtu.be/H96Lo2q_FSk ''ACSL - Graph Theory Worksheet 1'' ('''misterminich''')]<br />
<br />
Shows the solution to the ACSL problem: '''Draw the directed graph with vertices A, B, C, D, E and the directed edges AB, BC, AD, BC, DC, ED, and EA.''<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/y1fdIb_oNG0</youtube><br />
| [https://youtu.be/y1fdIb_oNG0 ''ACSL Graph Theory Worksheet 3'' ('''misterminich''')]<br />
<br />
Shows the solution to an ACSL problem asking to find how many paths of a specific length there are in a specific directed graph.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/vtTCRMGB0K8</youtube><br />
| [https://youtu.be/vtTCRMGB0K8 ''Graph Theory ACSL Example Problem'' ('''Tangerine Code''')]<br />
<br />
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.<br />
|}<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/ivhOH6crQ1w</youtube><br />
| [https://youtu.be/ivhOH6crQ1w ''ACSL Test Prep - Graph Theory'' ('''Mrs. Goopta''')]<br />
<br />
A talked-over presentation discussing graph theory as needed for the American Computer Science League and its tests.<br />
|}<br />
<br />
===Other Videos===<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/44sQJK4BycY</youtube><br />
| [https://youtu.be/44sQJK4BycY ''CS 106B Lecture: Graphs: basic concepts'']<br />
<br />
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. <br />
|-<br />
| <youtube width="300" height="180"> https://youtu.be/gXgEDyodOJU</youtube><br />
| [https://youtu.be/gXgEDyodOJU ''Data structures: Introduction to Graphs'' '''(mycodeschool)''']<br />
<br />
A nice introduction to the fundamental concepts of graphs. <br />
<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&diff=656Digital Electronics2020-08-11T17:32:31Z<p>Partha: /* Sample Problems */</p>
<hr />
<div>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. <br />
Each circuit can be represented as a Boolean Algebra expression; <br />
this topic is an extension of the topic of [[Boolean Algebra]], which includes <br />
a thorough description of truth tables and simplifying expressions. <br />
<br />
= Definitions =<br />
<br />
The following table illustrates all logic gates. For each logic gate, the<br />
table shows the equivalent Boolean algebra expression and truth table.<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''NAME'''<br />
!'''GRAPHICAL SYMBOL'''<br />
!'''ALGEBRAIC EXPRESSION'''<br />
!'''TRUTH TABLE'''<br />
|-<br />
!'''BUFFER'''<br />
| [[File:Buffer-gate-en.svg|128px]]<br />
| X = A<br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
| 0 || 0<br />
|-<br />
| 1 || 1<br />
|}<br />
|-<br />
!'''NOT'''<br />
| [[File:Not-gate-en.svg|128px]]<br />
| X = <math>\overline{A}</math> or <math>\neg A</math><br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || X<br />
|-<br />
| 0 || 1<br />
|-<br />
| 1 || 0<br />
|}<br />
|-<br />
!'''AND'''<br />
| |[[File:And-gate.png|128px]]<br />
| X = <math>AB</math> or <math>A \cdot B</math> <br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="2" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|colspan="1" style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || B || X<br />
|-<br />
| 0 || 0 || 0<br />
|-<br />
| 0 || 1 || 0<br />
|-<br />
| 1 || 0 || 0<br />
|-<br />
| 1 || 1 || 1<br />
|}<br />
|-<br />
!'''NAND'''<br />
| [[File:Nand-gate-en.svg|128px]]<br />
| X = <math>\overline{AB}</math> or <math>\overline{A\cdot B}</math><br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="2" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || B || X<br />
|-<br />
| 0 || 0 || 1<br />
|-<br />
| 0 || 1 || 1<br />
|-<br />
| 1 || 0 || 1<br />
|-<br />
| 1 || 1 || 0<br />
|}<br />
|-<br />
!'''OR'''<br />
| [[File:Or-gate-en.svg|128px]]<br />
| X = <math>A+B</math> <br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="2" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || B || X<br />
|-<br />
| 0 || 0 || 0<br />
|-<br />
| 0 || 1 || 1<br />
|-<br />
| 1 || 0 || 1<br />
|-<br />
| 1 || 1 || 1<br />
|}<br />
|-<br />
!'''NOR'''<br />
| [[File:Nor-gate-en.svg|128px]]<br />
| X = <math>\overline{A+B}</math><br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="2" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || B || X<br />
|-<br />
| 0 || 0 || 1<br />
|-<br />
| 0 || 1 || 0<br />
|-<br />
| 1 || 0 || 0<br />
|-<br />
| 1 || 1 || 0<br />
|}<br />
|-<br />
!'''XOR'''<br />
|[[File:Xor-gate-en.svg|128px]]<br />
| X = <math>A \oplus B</math><br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="2" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || B || X<br />
|-<br />
| 0 || 0 || 0<br />
|-<br />
| 0 || 1 || 1<br />
|-<br />
| 1 || 0 || 1<br />
|-<br />
| 1 || 1 || 0<br />
|}<br />
|-<br />
!'''XNOR'''<br />
| [[File:Xnor-gate-en.svg|128px]]<br />
| X = <math>\overline{A \oplus B} \text{ or } A \odot B</math><br />
|<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="2" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
! A || B || X<br />
|-<br />
| 0 || 0 || 1<br />
|-<br />
| 0 || 1 || 0<br />
|-<br />
| 1 || 0 || 0<br />
|-<br />
| 1 || 1 || 1<br />
|}<br />
|}<br />
<br />
Note that there is some ambiguity in the conversion from a diagram to a circuit. For example, is <math>\overline{A+B}</math> an OR gate followed by a NOT gate, or smply<br />
a NOT gate.<br />
<br />
=Online Tools=<br />
<br />
The [http://www.cburch.com/logisim/index.html Logisim] application is a wonderful tool<br />
for exploring this topic.<br />
Logisim is free to download and use; among its many features is support to automatically draw<br />
a circuit from a Boolean Algebra expression; to simulate the circuit with arbitrary inputs;<br />
and to complete a truth table for the circuit. From the application, you can import the circuit corresponding to the [[#Sample_Problem_1|Sample Problem 1]] <br />
from the file located at [http://www.acsl.org/misc/wiki-digital-electronics-sample1.circ http://www.acsl.org/misc/wiki-digital-electronics-sample1.circ].<br />
There are many YouTube videos that show how to use the Logisim application; including a very nice [https://www.youtube.com/watch?v=cMz7wyY_PxE 4 minute tutorial].<br />
<br />
Logisim contains many <br />
additional advanced features that are beyond<br />
the scope of ACSL problems.<br />
<br />
=Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
Find all ordered triplets (A, B, C) which make the following circuit FALSE:<br />
<br />
::[[File:NotABorC.svg|200px]]<br />
<br />
'''Solution:'''<br />
<br />
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).<br />
<br />
Another approach to solving this problem is to translate the circuit into a Boolean Algebra expression and simplify <br />
the expression using the laws of Boolean Algebra. This circuit translates to the Boolean expression <math>\overline{AB}+C</math>. <br />
To find when this is FALSE we can equivalently find when the <math>\overline{\overline{AB}+C}</math> is TRUE. <br />
The expression becomes <math>\overline{\overline{AB}}\cdot \overline{C}</math> after applying DeMorgan’s Law. The double NOT over the AB expression<br />
cancels out, to become <math>AB\overline{C}</math>. The AND of 3 terms is TRUE when each term is TRUE, or A=1, B=1 and C=0.<br />
<br />
== Sample Problem 2 ==<br />
<br />
How many ordered 4-tuples (A, B, C, D) make the following circuit TRUE?<br />
<br />
::[[File:circuit-sample2.svg |400px]]<br />
<br />
'''Solution:'''<br />
<br />
We'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's useful to keep the column straight when working the truth table.<br />
<br />
::[[File:circuit-sample2-labels.svg |300px]]<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|-<br />
|colspan="4" style="background-color: #cceeff; font-size: x-small" "|INPUT<br />
|colspan="5" style="background-color: #cceeff; font-size: x-small" "|OUTPUT<br />
|-<br />
!rowspan="2" | A<br />
!rowspan="2" | B<br />
!rowspan="2" | C<br />
!rowspan="2" | D<br />
! p<br />
! q<br />
! r<br />
! s<br />
! t<br />
|-<br />
!<math>\overline{C+D}</math><br />
!<math>p+\overline{B}</math><br />
!<math>\overline{A}B</math><br />
!<math>r \oplus q</math><br />
!<math>s \oplus p</math><br />
|-<br />
|0 || 0 || 0 || 0 || 1 || 1 || 0 || 1 || 0<br />
|-<br />
|0 || 0 || 0 || 1 || 0 || 1 || 0 || 1 || 1<br />
|-<br />
|0 || 0 || 1 || 0 || 0 || 1 || 0 || 1 || 1<br />
|-<br />
|0 || 0 || 1 || 1 || 0 || 1 || 0 || 1 || 1<br />
|-<br />
|0 || 1 || 0 || 0 || 1 || 1 || 1 || 0 || 1<br />
|-<br />
|0 || 1 || 0 || 1 || 0 || 0 || 1 || 1 || 1<br />
|-<br />
|0 || 1 || 1 || 0 || 0 || 1 || 1 || 1 || 1<br />
|-<br />
|0 || 1 || 1 || 1 || 0 || 0 || 1 || 1 || 1<br />
|-<br />
|1 || 0 || 0 || 0 || 1 || 1 || 0 || 1 || 0<br />
|-<br />
|1 || 0 || 0 || 1 || 0 || 1 || 0 || 1 || 1<br />
|-<br />
|1 || 0 || 1 || 0 || 0 || 1 || 0 || 1 || 1<br />
|-<br />
|1 || 0 || 1 || 1 || 0 || 1 || 0 || 1 || 1<br />
|-<br />
|1 || 1 || 0 || 0 || 1 || 1 || 0 || 1 || 0<br />
|-<br />
|1 || 1 || 0 || 1 || 0 || 0 || 0 || 0 || 0<br />
|-<br />
|1 || 1 || 1 || 0 || 0 || 0 || 0 || 0 || 0<br />
|-<br />
|1 || 1 || 1 || 1 || 0 || 0 || 0 || 0 || 0<br />
|}<br />
<br />
From the truth table, there are 10 rows where the final output is TRUE.<br />
<br />
== Sample Problem 3 ==<br />
<br />
Simplify the Boolean expression that this circuit represents.<br />
<br />
::[[File:Circuit-PB.png|200px]]<br />
<br />
'''Solution:'''<br />
<br />
The circuit translates as follows:<br />
<br />
<math>(\overline{A}(A+B))\overline{B+C}</math><br />
<math>=(\overline{A}A+\overline{A}B)\overline{B}\overline{C}</math><br />
<math>=(0+\overline{A}B)\overline{B}\overline{C}</math><br />
<math>=\overline{A}B\overline{B}\overline{C}</math><br />
<math>=0</math><br />
<br />
= Video Resources =<br />
<br />
==ACSL Advisors==<br />
<br />
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. <br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--><br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/gxil9VyGTtE</youtube><br />
| [https://youtu.be/gxil9VyGTtE ''Digital Electronics -1'' ('''Ravi Yeluru (hemsra)''')]<br />
<br />
Introduces the AND, OR, and NOT gates, and works through a couple of simple circuits.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/m7-wa5ca_G8</youtube><br />
| [https://youtu.be/m7-wa5ca_G8 Digital Electronics -2'' ('''Ravi Yeluru (hemsra)''')]<br />
<br />
Solves a 3-gate circuit (the AND of an OR and a NOR) given by the Boolean expression <math>(\overline{A}+B)(\overline{B+C})</math>.<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/Eckd5UlJmB4</youtube><br />
| [https://youtu.be/Eckd5UlJmB4 ''Digital Electronics Boolean Algebra'' ('''Tangerine Code''')]<br />
<br />
Solves a 3-gate circuit (the AND of an OR and a NOR) given by the Boolean expression<br />
<math>\overline{(A+B)}(B+C)</math>. <br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/JJL6DsVCpHo</youtube><br />
| [https://youtu.be/JJL6DsVCpHo ''ACSL Digital Electronics Worksheet Sample'' ('''misterminich''')]<br />
<br />
Solves a handful of ACSL problems.<br />
|}<br />
<br />
<br />
==Other Videos==<br />
<br />
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<br />
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. <br />
<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/s2MI_NgKD98</youtube><br />
| [https://youtu.be/s2MI_NgKD98 ''Digital Electronics Basics'' ('''Beginning Electronics''')]<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/z9s8A8oBe7g</youtube><br />
| [https://youtu.be/z9s8A8oBe7g ''Logic Gate Expressions'' ('''Kevin Drumm''')]<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/TLl4E3IV6Z0</youtube><br />
| [https://youtu.be/TLl4E3IV6Z0 ''Logic Gate Combinations'' ('''Kevin Drumm''')]<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/eroqZpbKrhc</youtube><br />
| [https://youtu.be/eroqZpbKrhc ''Determining the truth table and logic statement'' ('''Anna does some physics''')]<br />
Uses a truth table to find the inputs that make the circuit <math>\not(A+B)+(AB)</math> true using a truth table.<br />
|}</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=File:Circuit-PB.png&diff=655File:Circuit-PB.png2020-08-11T16:53:14Z<p>Partha: 07-08 C3 Digital Electronics</p>
<hr />
<div>07-08 C3 Digital Electronics</div>Parthahttp://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=652Bit-String Flicking2020-08-04T19:56:28Z<p>Partha: </p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''NOT''', '''AND''', '''OR''', and '''XOR'''. Bits strings are manipulated as a unit using '''SHIFT''' and '''CIRCULATE''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''.<br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit strings to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and represent each option with a single bit. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. Shifting of bits is also used to multiply or divide by powers of 2.<br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''NOT''' (~ or $\neg$), '''AND''' (&), '''OR''' (|), and '''XOR''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''NOT''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''AND''' is a binary operator that performs the logical '''AND''' of each bit in each of its operands. The '''AND''' of two values is 1 only if both values are 1. For example, '''1011011 and 011001''' has a value of '''001001'''. The '''AND''' function is often used to isolate the value of a bit in a bit-string or to clear the value of a bit in a bit-string.<br />
<br />
* '''OR''' is a binary operator that performs the logical '''OR''' of each bit in each of its operands. The '''OR''' of two values is 1 only if one or both values are 1. For example, '''1011011 or 011001''' has a value of '''111011'''. The '''OR''' function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''XOR''' is a binary operator that performs the logical '''XOR''' of each bit in each of its operands. The '''XOR''' of two values is 1 if the values are different and 0 if they are the same. For example, '''1011011 xor 011001 = 110010'''. The '''XOR''' function is often used to change the value of a particular bit.<br />
<br />
All binary operators (AND, OR, or XOR) must operate on bit-strings that are of the same length. If the operands are not the same length, the shorter one is padded with 0's on the left as needed. For example, '''11010 and 1110''' would have value of '''11010 and 01110 = 01010'''.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 0<br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the indicated direction. As each bit is shifted out one end, it is shifted in at the other end. The effect of this is that the bits remain in the same order on the other side of the string.<br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all unary operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(0101110 AND NOT 110110 OR (LSHIFT-3 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(0101110 AND '''001001''' OR (LSHIFT-3 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde.<br />
:(RCIRC-3 abcde) => cdeab<br />
:(cdeab AND 11011) => cd0ab<br />
:(10110 XOR cd0ab) => Cd1Ab (the capital letter is the NOT of its lower case)<br />
:(LSHIFT-1 Cd1Ab) => d1Ab0<br />
<br />
So, d1Ab0 = 01100.<br />
<br />
Meaning, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. <br />
<br />
The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: (LCIRC-23 01101) is the same as (LCIRC-3 01101) which has a value of 01011, and (RCIRC-14 01011) is the same as (RCIRC-4 01011) which has a value of 10110. Another strategy is to offset the left and right circulates. So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101) which is also 11010.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
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. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/0U6ogoQ5Hkk</youtube><br />
| [https://youtu.be/0U6ogoQ5Hkk "ACSL Math: Bit String Flicking" (Quick Coding Bytes)]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/8J9AdxU5CW8</youtube><br />
| [https://youtu.be/8J9AdxU5CW8 ''Bit String Flicking by Ravi Yeluru'' ('''hemsra''')]<br />
<br />
Walks through two problems from the Junior Division.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Partha