<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.categories.acsl.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marc+Brown</id>
	<title>ACSL Category Descriptions - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.categories.acsl.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marc+Brown"/>
	<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Special:Contributions/Marc_Brown"/>
	<updated>2026-05-15T17:23:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Computer_Number_Systems&amp;diff=865</id>
		<title>Computer Number Systems</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Computer_Number_Systems&amp;diff=865"/>
		<updated>2021-11-15T21:43:11Z</updated>

		<summary type="html">&lt;p&gt;Marc Brown: /* Converting from Decimal */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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 &amp;#039;&amp;#039;bit&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;bi&amp;#039;&amp;#039;&amp;#039;nary digi&amp;#039;&amp;#039;&amp;#039;t&amp;#039;&amp;#039;&amp;#039;), has two values: a 1 (or &amp;#039;&amp;#039;true&amp;#039;&amp;#039;) when the signal is on, and a 0 (of &amp;#039;&amp;#039;false&amp;#039;&amp;#039;) when the signal is off. &lt;br /&gt;
&lt;br /&gt;
Larger values can be stored by a group of bits. For example, there are 4 different values stored by 2 bits (00, 01, 10, and 11), 8 values for 3 bits (000, 001, 010, 011, 100, 101, 110, and 111), 16 values for 4 bits (0000, 0001, ..., 1111), and so on. However, large numbers, using 0s and 1s only, are quite unwieldy for humans. For example, a computer would need 19 bits to store the numbers up to 500,000! We use of different number systems to work with large binary strings that represent numbers within computers.&lt;br /&gt;
&lt;br /&gt;
== Different Number Systems ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;number system&amp;#039;&amp;#039; is the way we name and represent numbers. The number system we use in our daily life is known as &amp;#039;&amp;#039;&amp;#039;decimal number system&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;base 10&amp;#039;&amp;#039;&amp;#039; because it is based on 10 different digits: 0, 1, 2, ..., 8, and 9. The base of number is written as subscript to a number. For example, the decimal number &amp;quot;twelve thousand three hundred and forty-five&amp;quot; is written as $12345_{10}$. Without a base or explicit context, it&amp;#039;s assumed that a number is in base 10. &lt;br /&gt;
&lt;br /&gt;
In computer science, apart from the decimal system, three additional number systems are commonly used: &amp;#039;&amp;#039;&amp;#039;binary&amp;#039;&amp;#039;&amp;#039; (base-2), &amp;#039;&amp;#039;&amp;#039;octal&amp;#039;&amp;#039;&amp;#039; (base-8), and &amp;#039;&amp;#039;&amp;#039;hexadecimal&amp;#039;&amp;#039;&amp;#039; or just &amp;#039;&amp;#039;&amp;#039;hex&amp;#039;&amp;#039;&amp;#039; (base-16). Binary numbers are important because that is how numbers are stored in the computer. Octal and hexadecimal are used to represent binary numbers in a user-friendly way. Each octal symbol represents 3 binary bits and each hex digit represents 4 binary bits. For example, the decimal number 53201, stored as in the computer as the binary number 10000001111000101100, is represented by the octal number 2017054, and the hex number 81E2C. The table below compares the number systems: &lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Number System&lt;br /&gt;
!Base&lt;br /&gt;
!Digits Used&lt;br /&gt;
!Examples&lt;br /&gt;
|-&lt;br /&gt;
|Binary&lt;br /&gt;
|2&lt;br /&gt;
|0,1&lt;br /&gt;
|$10110_{2}$, $10110011_{2}$&lt;br /&gt;
|-&lt;br /&gt;
|Octal&lt;br /&gt;
|8&lt;br /&gt;
|0,1,2,3,4,5,6,7&lt;br /&gt;
|$75021_{8}$, $231_{8}$, $60012_{8}$&lt;br /&gt;
|-&lt;br /&gt;
|Decimal&lt;br /&gt;
|10&lt;br /&gt;
|0,1,2,3,4,5,6,7,8,9&lt;br /&gt;
|$97425_{10}$ or simply 97425&lt;br /&gt;
|-&lt;br /&gt;
|Hexadecimal&lt;br /&gt;
|16&lt;br /&gt;
|0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F&lt;br /&gt;
|$54A2DD0F_{16}$&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, $N$ bits have $2^N$ different values. The computers aboard the Apollo spacecraft had 8-bit words of memory. Each word of memory could store 256 different values, and the contents were displayed using 2 hex characters.&lt;br /&gt;
&lt;br /&gt;
The following table shows the first 20 numbers in decimal, binary, octal, and hexadecimal:&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
!Decimal&lt;br /&gt;
!Binary&lt;br /&gt;
!Octal&lt;br /&gt;
!Hexadecimal&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
|0&lt;br /&gt;
|0 &lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|1 &lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|10&lt;br /&gt;
|2&lt;br /&gt;
|2 &lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|11&lt;br /&gt;
|3&lt;br /&gt;
|3 &lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|100&lt;br /&gt;
|4&lt;br /&gt;
|4 &lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|101&lt;br /&gt;
|5&lt;br /&gt;
|5 &lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
|110&lt;br /&gt;
|6&lt;br /&gt;
|6 &lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|111&lt;br /&gt;
|7&lt;br /&gt;
|7 &lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|1000&lt;br /&gt;
|10&lt;br /&gt;
|8&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
|1001&lt;br /&gt;
|11&lt;br /&gt;
|9&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
|1010&lt;br /&gt;
|12&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|11&lt;br /&gt;
|1011&lt;br /&gt;
|13&lt;br /&gt;
|B&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|1100&lt;br /&gt;
|14&lt;br /&gt;
|C &lt;br /&gt;
|-&lt;br /&gt;
|13&lt;br /&gt;
|1101&lt;br /&gt;
|15&lt;br /&gt;
|D &lt;br /&gt;
|-&lt;br /&gt;
|14&lt;br /&gt;
|1110&lt;br /&gt;
|16&lt;br /&gt;
|E &lt;br /&gt;
|-&lt;br /&gt;
|15&lt;br /&gt;
|1111&lt;br /&gt;
|17&lt;br /&gt;
|F &lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|10000&lt;br /&gt;
|20&lt;br /&gt;
|10 &lt;br /&gt;
|-&lt;br /&gt;
|17&lt;br /&gt;
|10001&lt;br /&gt;
|21&lt;br /&gt;
|11&lt;br /&gt;
|-&lt;br /&gt;
|18&lt;br /&gt;
|10010&lt;br /&gt;
|22&lt;br /&gt;
|12&lt;br /&gt;
|-&lt;br /&gt;
|19&lt;br /&gt;
|10011&lt;br /&gt;
|23&lt;br /&gt;
|13&lt;br /&gt;
|-&lt;br /&gt;
|20&lt;br /&gt;
|10100&lt;br /&gt;
|24&lt;br /&gt;
|14&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Converting to Decimal ==&lt;br /&gt;
&lt;br /&gt;
As we learned in the first or second grade, the decimal value of a decimal number is simply sum of each digit multiplied by its place value:&lt;br /&gt;
&lt;br /&gt;
:$12345 = 1×10^{4}+ 2×10^{3}+ 3×10^{2}+ 4×10^{1}+ 5×10^{0} =   10000 + 2000+ 300 +40+5 = 12345$&lt;br /&gt;
&lt;br /&gt;
:$3079 = 3×10^{3}+ 0×10^{2}+ 7×10^{1}+ 9×10^{0} = 3000 + 70 + 9 = 3079$&lt;br /&gt;
&lt;br /&gt;
Analogously, the decimal value of a number in an arbitrary base is the sum of each digit multiplied by its place value.  Here are some examples of converting from one base into base 10:&lt;br /&gt;
&lt;br /&gt;
:$1101_{2}  = 1 × 2^3  + 1 × 2^2  + 0 × 2^1  + 1 × 2^0 = 8 + 4  + 0  + 1  = 13_{10}$ &lt;br /&gt;
&lt;br /&gt;
:$175_{8}   = 1 × 8^2  + 7 × 8^1  + 5 × 8^0 = 1 × 64 + 7 × 8 + 5 × 1 = 64 + 56 + 5 = 125_{10}$&lt;br /&gt;
&lt;br /&gt;
:$A5E_{16}  = 10 × 16^2 + 5 × 16^1 + 14 × 16^0 = 10 × 256 + 5 × 16 + 14 × 1 = 2560 + 80 + 14 = 2654_{10}$&lt;br /&gt;
&lt;br /&gt;
== Converting from Decimal ==&lt;br /&gt;
&lt;br /&gt;
The algorithm to convert a number from an arbitrary base requires finding how many times successive powers of the base go into the number, starting with the largest power of the base less than the starting number. For example, converting 3306 from base 10 to octal proceeds as follows:&lt;br /&gt;
&lt;br /&gt;
1) The largest power of 8 that is less than or equal to 3306 is 512 ($8^3$). Divide 3306 by 512:&lt;br /&gt;
:$3306 = 6*8^3 + 234$  &lt;br /&gt;
&lt;br /&gt;
2) The next power of 8 is 64 ($8^2$). Divide 234 by 64:&lt;br /&gt;
:$234 = 3 *8^2 + 42$&lt;br /&gt;
&lt;br /&gt;
3) The next smaller power of 8 is 8 ($8^1$). Divide 42 by 8:&lt;br /&gt;
:$42 = 5*8^1 + 2$&lt;br /&gt;
&lt;br /&gt;
4) Finally, the next smaller power of 8 is 1 ($8^0$). Divide 2 by 1:&lt;br /&gt;
:$2 = 2 * 8^0$&lt;br /&gt;
&lt;br /&gt;
The answer is $6352_8$.&lt;br /&gt;
&lt;br /&gt;
== Converting between Binary, Octal, and Hexadecimal == &lt;br /&gt;
&lt;br /&gt;
Converting from octal to binary is simple: replace each octal digit by its corresponding 3 binary bits. For example:&lt;br /&gt;
&lt;br /&gt;
:$375_{8} = \ \ 011\ \ \ 111\ \ \ 101_{2} = 11111101_2$&lt;br /&gt;
&lt;br /&gt;
Converting from hex to binary is also simple: replace each hex digit by its corresponding 4 binary bits. For example:&lt;br /&gt;
&lt;br /&gt;
:$FD_{16} = \ \ 1111\ \ \ 1101_{2} = 11111101_2$&lt;br /&gt;
&lt;br /&gt;
Converting from binary to either octal or hex is pretty simple as well: group the bits by 3s or 4s (starting at the right), and convert each group:&lt;br /&gt;
&lt;br /&gt;
:$10000001111000101100 = 10\ 000\ 001\ 111\ 000\ 101 \ 100 = 2017054_8$&lt;br /&gt;
&lt;br /&gt;
:$10000001111000101100 = 1000\ 0001\ 1110\ 0010\ 1100 = 81E2C_{16}$&lt;br /&gt;
&lt;br /&gt;
Converting between base 8 and 16 is easy by expressing the number in base 2 (easy to do!) and then converting that number from base 2 (another easy operation)! This is shown below in Sample Problem #1.&lt;br /&gt;
&lt;br /&gt;
== Using Hexadecimal Numbers to Represent Colors ==&lt;br /&gt;
&lt;br /&gt;
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”. &lt;br /&gt;
 &lt;br /&gt;
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. &lt;br /&gt;
 &lt;br /&gt;
The following web site has nearly every color name, along with its hex code and decimal values:  &lt;br /&gt;
 &lt;br /&gt;
:https://www.rapidtables.com/web/color/RGB_Color.html &lt;br /&gt;
 &lt;br /&gt;
For example “salmon” is “#FA8072” which represents the decimal numbers 250 (hex FA), 128 (hex 80), and 114 (hex 72).&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
[https://ryanstutorials.net/ Ryan&amp;#039;s Tutorials] covers this topic beautifully. Rather than trying to duplicate that work, we&amp;#039;ll point you to the different sections:&lt;br /&gt;
&lt;br /&gt;
:[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. &lt;br /&gt;
&lt;br /&gt;
:[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 &amp;#039;&amp;#039;Activities&amp;#039;&amp;#039;] section, you can practice converting numbers. &lt;br /&gt;
&lt;br /&gt;
:[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.&lt;br /&gt;
&lt;br /&gt;
:[https://ryanstutorials.net/binary-tutorial/binary-negative-numbers.php 4. Negative Numbers] - ACSL problems will not cover how negative numbers are represented in binary. &lt;br /&gt;
&lt;br /&gt;
:[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.&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
The AskNumbers.com site has a nice description of the conversions between [https://www.asknumbers.com/hex-to-octal.aspx binary, octal, decimal and hexadecimal] numbers. &lt;br /&gt;
&lt;br /&gt;
== Format of ACSL Problems ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To be successful in this category, you must know the following facts cold:&lt;br /&gt;
&lt;br /&gt;
# The binary value of each octal digit 0, 1, ..., 7&lt;br /&gt;
# The binary value of each hex digit 0, 1, ..., 9, A, B, C, D, E, F&lt;br /&gt;
# The decimal value of each hex digit 0, 1, ..., F  &lt;br /&gt;
# Powers  of  2,  up  to 4096&lt;br /&gt;
# Powers  of  8,  up  to 4096&lt;br /&gt;
# Powers  of  16,  up  to  65,536&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Solve for $x$ where $x_{16}=3676_8$.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; 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$.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
 &lt;br /&gt;
$$\begin{align}&lt;br /&gt;
3676_8 &amp;amp;= 011 ~  110 ~ 111 ~ 110_2  &amp;amp; \text{convert each octal digit into base 2}\hfill\cr &lt;br /&gt;
&amp;amp;= 0111 ~ 1011 ~ 1110_2  &amp;amp; \text{group by 4 bits, from right-to-left}\hfill\cr&lt;br /&gt;
&amp;amp;= 7 ~ \text{B} ~ \text{E}_{16}  &amp;amp; \text{convert each group of 4 bits into a hex digit}\cr&lt;br /&gt;
\end{align}$$&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Solve for $x$ in the following hexadecimal equation: $ x= \text{F5AD}_{16} - \text{69EB}_{16}$&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; One could convert the hex numbers into base 10, perform the subtraction, and then convert the answer back to base 16. However, &lt;br /&gt;
working directly in base 16 isn&amp;#039;t too hard. &lt;br /&gt;
As in conventional decimal arithmetic, one works from right-to-left, from the least significant digits to the most.  &lt;br /&gt;
&lt;br /&gt;
:The rightmost digit becomes 2, because D-B=2.  &lt;br /&gt;
:The next column is A-E. We need to &amp;#039;&amp;#039;borrow&amp;#039;&amp;#039; a one from the 5 column, and 1A-E=C &lt;br /&gt;
:In the next column, 4-9=B, again, borrowing a 1 from the next column.&lt;br /&gt;
:Finally, the leftmost column,  E-6=8&lt;br /&gt;
&lt;br /&gt;
Combining these results of each column, we get a final answer of $8BC2_{16}$.&lt;br /&gt;
&lt;br /&gt;
=== Sample Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
How many numbers from 100 to 200 in base 10 consist of distinct&lt;br /&gt;
ascending digits and also have distinct ascending hex digits when&lt;br /&gt;
converted to base 16? &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; There are 13 numbers that have ascending digits in both bases from 100&lt;br /&gt;
to 200.  They are (in base 10):&lt;br /&gt;
123 (7B), 124, 125, 126, 127 (7F), 137 (89), 138, 139 (8B), 156 (9C), 157, 158, 159 (9F), 189 (BD)&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
There are many YouTube videos about computer number systems. Here are a handful that cover the topic nicely, without too many ads:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aW3qCcH6Dao&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aW3qCcH6Dao &amp;#039;&amp;#039;Number Systems - Converting Decimal, Binary and Hexadecimal&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Joe James&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
An introduction to number systems, and how to convert between decimal, binary and hexadecimal numbers. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/m1JtWKuTLR0&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/m1JtWKuTLR0 &amp;#039;&amp;#039;Lesson 2.3 : Hexadecimal Tutorial&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Carl Herold&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
The video focuses on hexadecimal numbers: their relationship to binary numbers and how to convert to decimal numbers. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/WR67syBDzew&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/WR67syBDzew &amp;#039;&amp;#039;Hexes and the Magic of Base 16 - Vaidehi Joshi - May 2017&amp;#039; (&amp;#039;&amp;#039;&amp;#039;DonutJS&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A fun introduction to hexadecimal numbers, focusing a bit &lt;br /&gt;
on using hex numbers for specifying RGB colors. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jvx-NrILgpE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jvx-NrILgpE &amp;#039;&amp;#039;Collins Lab: Binary &amp;amp; Hex&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Adafruit Industries&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=624</id>
		<title>Bit-String Flicking</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=624"/>
		<updated>2019-01-10T01:35:33Z</updated>

		<summary type="html">&lt;p&gt;Marc Brown: /* Problem 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039;. Bits strings are manipulated as a unit using &amp;#039;&amp;#039;&amp;#039;shift&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;circulate&amp;#039;&amp;#039;&amp;#039; operators. The bits on the left are called the &amp;#039;&amp;#039;most significant bits&amp;#039;&amp;#039; and those on the right are the &amp;#039;&amp;#039;least significant bits&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.&lt;br /&gt;
&lt;br /&gt;
== Operators==&lt;br /&gt;
&lt;br /&gt;
=== Bitwise Operators ===&lt;br /&gt;
&lt;br /&gt;
The logical operators are  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; (~ or $\neg$), &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; (&amp;amp;), &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; (|), and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands.  The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 and 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if one or both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 or 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;111011&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; function is often use to force the value of a bit in a bit-string to be 1, if it isn&amp;#039;t already.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of two values is 1 if the values are different and 0 if they are the same. For example, 1011011 xor 011001 = 110010. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; function is often used to change the value of a particular bit.&lt;br /&gt;
&lt;br /&gt;
All binary operators (and, or, or xor) must operate on bit-strings that are of&lt;br /&gt;
the same length. If the operands are not the same&lt;br /&gt;
length, the shorter one is padded with 0&amp;#039;s on the left as needed. For &lt;br /&gt;
example, &amp;#039;&amp;#039;&amp;#039;11010 and 1110&amp;#039;&amp;#039;&amp;#039; would have value of &amp;#039;&amp;#039;&amp;#039;11010 and 01110 = 01010&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The following table summarizes the operators:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
! &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Shift Operators ===&lt;br /&gt;
&lt;br /&gt;
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.   &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
The following table gives some examples of these operations:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: right&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!x&lt;br /&gt;
!(LSHIFT-2 x)&lt;br /&gt;
!(RSHIFT-3 x)&lt;br /&gt;
!(LCIRC-3 x)&lt;br /&gt;
!(RCIRC-1 x)&lt;br /&gt;
|-&lt;br /&gt;
!01101&lt;br /&gt;
| 10100&lt;br /&gt;
| 00001&lt;br /&gt;
| 01011&lt;br /&gt;
| 10110&lt;br /&gt;
|-&lt;br /&gt;
!10&lt;br /&gt;
| 00&lt;br /&gt;
| 00&lt;br /&gt;
| 01&lt;br /&gt;
| 01&lt;br /&gt;
|-&lt;br /&gt;
!1110&lt;br /&gt;
| 1000&lt;br /&gt;
| 0001&lt;br /&gt;
| 0111&lt;br /&gt;
| 0111&lt;br /&gt;
|-&lt;br /&gt;
!1011011&lt;br /&gt;
| 1101100&lt;br /&gt;
| 0001011&lt;br /&gt;
| 1011101&lt;br /&gt;
| 1101101&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Order of Precedence ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(0101110 AND NOT 110110 OR (LSHIFT-3 101010))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows:&lt;br /&gt;
:(0101110 AND &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-3 101010))&lt;br /&gt;
:(&amp;#039;&amp;#039;&amp;#039;001000&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-3 101010))&lt;br /&gt;
:(001000 OR &amp;#039;&amp;#039;&amp;#039;010000&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;011000&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows, starting at the innermost parentheses:&lt;br /&gt;
:(RCIRC-2 01101) =&amp;gt; 01011&lt;br /&gt;
:(LCIRC-4 01011) =&amp;gt; 10101&lt;br /&gt;
:(RSHIFT-1 10101) = 01010&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
List all possible values of x (5 bits long) that solve the following equation.&lt;br /&gt;
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Since x is a string 5 bits long, represent it by abcde.  (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab.  This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).&lt;br /&gt;
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, 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”.  The four possible values of x are: 00000, 00001, 00100 and 00101.&lt;br /&gt;
&lt;br /&gt;
=== Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression:&lt;br /&gt;
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) &amp;amp; (RSHIFT-2 10111))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The problem can be rewritten as &lt;br /&gt;
: A | B &amp;amp; C&lt;br /&gt;
The AND has higher precedence than the OR.  &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Expressions B and C are pretty easy to evaluate:&lt;br /&gt;
:B = (LSHIFT-1 10011) = 00110&lt;br /&gt;
:C = (RSHIFT-2 10111) = 00101&lt;br /&gt;
&lt;br /&gt;
The expression becomes&lt;br /&gt;
: A | B &amp;amp; C = 10110 | 00110 &amp;amp; 00101 = 10110 | 00100 = 10110&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/IeMsD3harrE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/IeMsD3harrE &amp;#039;&amp;#039;Bit String Flicking (Intro)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jbKw8oYJPs4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jbKw8oYJPs4 &amp;#039;&amp;#039;Bit String Flicking Shifts and Circs&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Part 2 covers logical shifts and circulate operations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/XNBcO25mgCw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/XNBcO25mgCw &amp;#039;&amp;#039;Bit String Flicking&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/8J9AdxU5CW8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/8J9AdxU5CW8 &amp;#039;&amp;#039;Bit String Flicking by Ravi Yeluru&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;hemsra&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through two problems from the Junior Division.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aa_lQ8gft60&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aa_lQ8gft60 &amp;#039;&amp;#039;ACSL BitString Flicking Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of problems given in previous years at the Intermediate Division level.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=619</id>
		<title>Bit-String Flicking</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=619"/>
		<updated>2019-01-09T14:54:09Z</updated>

		<summary type="html">&lt;p&gt;Marc Brown: /* Problem 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039;. Bits strings are manipulated as a unit using &amp;#039;&amp;#039;&amp;#039;shift&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;circulate&amp;#039;&amp;#039;&amp;#039; operators. The bits on the left are called the &amp;#039;&amp;#039;most significant bits&amp;#039;&amp;#039; and those on the right are the &amp;#039;&amp;#039;least significant bits&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.&lt;br /&gt;
&lt;br /&gt;
== Operators==&lt;br /&gt;
&lt;br /&gt;
=== Bitwise Operators ===&lt;br /&gt;
&lt;br /&gt;
The logical operators are  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; (~ or $\neg$), &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; (&amp;amp;), &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; (|), and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands.  The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 and 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if one or both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 or 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;111011&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; function is often use to force the value of a bit in a bit-string to be 1, if it isn&amp;#039;t already.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of two values is 1 if the values are different and 0 if they are the same. For example, 1011011 xor 011001 = 110010. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; function is often used to change the value of a particular bit.&lt;br /&gt;
&lt;br /&gt;
All binary operators (and, or, or xor) must operate on bit-strings that are of&lt;br /&gt;
the same length. If the operands are not the same&lt;br /&gt;
length, the shorter one is padded with 0&amp;#039;s on the left as needed. For &lt;br /&gt;
example, &amp;#039;&amp;#039;&amp;#039;11010 and 1110&amp;#039;&amp;#039;&amp;#039; would have value of &amp;#039;&amp;#039;&amp;#039;11010 and 01110 = 01010&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The following table summarizes the operators:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
! &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
| o&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Shift Operators ===&lt;br /&gt;
&lt;br /&gt;
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.   &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
The following table gives some examples of these operations:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: right&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!x&lt;br /&gt;
!(LSHIFT-2 x)&lt;br /&gt;
!(RSHIFT-3 x)&lt;br /&gt;
!(LCIRC-3 x)&lt;br /&gt;
!(RCIRC-1 x)&lt;br /&gt;
|-&lt;br /&gt;
!01101&lt;br /&gt;
| 10100&lt;br /&gt;
| 00001&lt;br /&gt;
| 01011&lt;br /&gt;
| 10110&lt;br /&gt;
|-&lt;br /&gt;
!10&lt;br /&gt;
| 00&lt;br /&gt;
| 00&lt;br /&gt;
| 01&lt;br /&gt;
| 01&lt;br /&gt;
|-&lt;br /&gt;
!1110&lt;br /&gt;
| 1000&lt;br /&gt;
| 0001&lt;br /&gt;
| 0111&lt;br /&gt;
| 0111&lt;br /&gt;
|-&lt;br /&gt;
!1011011&lt;br /&gt;
| 1101100&lt;br /&gt;
| 0001011&lt;br /&gt;
| 1011101&lt;br /&gt;
| 1101101&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Order of Precedence ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(0101110 AND NOT 110110 OR (LSHIFT-2 101010))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows:&lt;br /&gt;
:(0101110 AND &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-2 101010))&lt;br /&gt;
:(&amp;#039;&amp;#039;&amp;#039;001000&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-2 101010))&lt;br /&gt;
:(001000 OR &amp;#039;&amp;#039;&amp;#039;010000&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;011000&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows, starting at the innermost parentheses:&lt;br /&gt;
:(RCIRC-2 01101) =&amp;gt; 01011&lt;br /&gt;
:(LCIRC-4 01011) =&amp;gt; 10101&lt;br /&gt;
:(RSHIFT-1 10101) = 01010&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
List all possible values of x (5 bits long) that solve the following equation.&lt;br /&gt;
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Since x is a string 5 bits long, represent it by abcde.  (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab.  This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).&lt;br /&gt;
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, 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”.  The four possible values of x are: 00000, 00001, 00100 and 00101.&lt;br /&gt;
&lt;br /&gt;
=== Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression:&lt;br /&gt;
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) &amp;amp; (RSHIFT-2 10111))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The problem can be rewritten as &lt;br /&gt;
: A | B &amp;amp; C&lt;br /&gt;
The AND has higher precedence than the OR.  &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Expressions B and C are pretty easy to evaluate:&lt;br /&gt;
:B = (LSHIFT-1 10011) = 00110&lt;br /&gt;
:C = (RSHIFT-2 10111) = 00101&lt;br /&gt;
&lt;br /&gt;
The expression becomes&lt;br /&gt;
: A | B &amp;amp; C = 10110 | 00110 &amp;amp; 00101 = 10110 | 00100 = 10110&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/IeMsD3harrE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/IeMsD3harrE &amp;#039;&amp;#039;Bit String Flicking (Intro)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jbKw8oYJPs4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jbKw8oYJPs4 &amp;#039;&amp;#039;Bit String Flicking Shifts and Circs&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Part 2 covers logical shifts and circulate operations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/XNBcO25mgCw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/XNBcO25mgCw &amp;#039;&amp;#039;Bit String Flicking&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/8J9AdxU5CW8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/8J9AdxU5CW8 &amp;#039;&amp;#039;Bit String Flicking by Ravi Yeluru&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;hemsra&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through two problems from the Junior Division.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aa_lQ8gft60&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aa_lQ8gft60 &amp;#039;&amp;#039;ACSL BitString Flicking Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of problems given in previous years at the Intermediate Division level.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=618</id>
		<title>Bit-String Flicking</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=618"/>
		<updated>2019-01-09T14:54:06Z</updated>

		<summary type="html">&lt;p&gt;Marc Brown: /* Problem 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039;. Bits strings are manipulated as a unit using &amp;#039;&amp;#039;&amp;#039;shift&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;circulate&amp;#039;&amp;#039;&amp;#039; operators. The bits on the left are called the &amp;#039;&amp;#039;most significant bits&amp;#039;&amp;#039; and those on the right are the &amp;#039;&amp;#039;least significant bits&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.&lt;br /&gt;
&lt;br /&gt;
== Operators==&lt;br /&gt;
&lt;br /&gt;
=== Bitwise Operators ===&lt;br /&gt;
&lt;br /&gt;
The logical operators are  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; (~ or $\neg$), &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; (&amp;amp;), &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; (|), and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands.  The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 and 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if one or both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 or 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;111011&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; function is often use to force the value of a bit in a bit-string to be 1, if it isn&amp;#039;t already.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of two values is 1 if the values are different and 0 if they are the same. For example, 1011011 xor 011001 = 110010. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; function is often used to change the value of a particular bit.&lt;br /&gt;
&lt;br /&gt;
All binary operators (and, or, or xor) must operate on bit-strings that are of&lt;br /&gt;
the same length. If the operands are not the same&lt;br /&gt;
length, the shorter one is padded with 0&amp;#039;s on the left as needed. For &lt;br /&gt;
example, &amp;#039;&amp;#039;&amp;#039;11010 and 1110&amp;#039;&amp;#039;&amp;#039; would have value of &amp;#039;&amp;#039;&amp;#039;11010 and 01110 = 01010&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The following table summarizes the operators:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
! &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
| o&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Shift Operators ===&lt;br /&gt;
&lt;br /&gt;
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.   &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
The following table gives some examples of these operations:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: right&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!x&lt;br /&gt;
!(LSHIFT-2 x)&lt;br /&gt;
!(RSHIFT-3 x)&lt;br /&gt;
!(LCIRC-3 x)&lt;br /&gt;
!(RCIRC-1 x)&lt;br /&gt;
|-&lt;br /&gt;
!01101&lt;br /&gt;
| 10100&lt;br /&gt;
| 00001&lt;br /&gt;
| 01011&lt;br /&gt;
| 10110&lt;br /&gt;
|-&lt;br /&gt;
!10&lt;br /&gt;
| 00&lt;br /&gt;
| 00&lt;br /&gt;
| 01&lt;br /&gt;
| 01&lt;br /&gt;
|-&lt;br /&gt;
!1110&lt;br /&gt;
| 1000&lt;br /&gt;
| 0001&lt;br /&gt;
| 0111&lt;br /&gt;
| 0111&lt;br /&gt;
|-&lt;br /&gt;
!1011011&lt;br /&gt;
| 1101100&lt;br /&gt;
| 0001011&lt;br /&gt;
| 1011101&lt;br /&gt;
| 1101101&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Order of Precedence ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(0101110 AND NOT 110110 OR (LSHIFT-2 101010))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows:&lt;br /&gt;
:(0101110 AND &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-2 101010))&lt;br /&gt;
:(&amp;#039;&amp;#039;&amp;#039;001000&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-2 101010))&lt;br /&gt;
:(001000 OR &amp;#039;&amp;#039;&amp;#039;010000&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;011000&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows, starting at the innermost parentheses:&lt;br /&gt;
:(RCIRC-2 01101) =&amp;gt; 01011&lt;br /&gt;
:(LCIRC-4 01011) =&amp;gt; 10101&lt;br /&gt;
:(RSHIFT-1 10101) = 01010&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
List all possible values of x (5 bits long) that solve the following equation.&lt;br /&gt;
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Since x is a string 5 bits long, represent it by abcde.  (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab.  This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).&lt;br /&gt;
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, 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”.  The four possible values of x are: 00000, 00001, 00100 and 00101.&lt;br /&gt;
&lt;br /&gt;
=== Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression:&lt;br /&gt;
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) &amp;amp; (RSHIFT-2 10111))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The problem can be rewritten as &lt;br /&gt;
: A | B &amp;amp; C&lt;br /&gt;
The AND has higher precedence than the OR.  &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Expressions B and C are pretty easy to evaluate:&lt;br /&gt;
:B = (LSHIFT-1 10011) = 00110&lt;br /&gt;
:C = (RSHIFT-2 10111) = 00101&lt;br /&gt;
&lt;br /&gt;
The expression becomes&lt;br /&gt;
: A | B &amp;amp; C = 10110 | 00110 &amp;amp; 00101 = 10110 | 00100 = 10110&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/IeMsD3harrE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/IeMsD3harrE &amp;#039;&amp;#039;Bit String Flicking (Intro)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jbKw8oYJPs4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jbKw8oYJPs4 &amp;#039;&amp;#039;Bit String Flicking Shifts and Circs&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Part 2 covers logical shifts and circulate operations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/XNBcO25mgCw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/XNBcO25mgCw &amp;#039;&amp;#039;Bit String Flicking&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/8J9AdxU5CW8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/8J9AdxU5CW8 &amp;#039;&amp;#039;Bit String Flicking by Ravi Yeluru&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;hemsra&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through two problems from the Junior Division.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aa_lQ8gft60&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aa_lQ8gft60 &amp;#039;&amp;#039;ACSL BitString Flicking Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of problems given in previous years at the Intermediate Division level.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=617</id>
		<title>Bit-String Flicking</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&amp;diff=617"/>
		<updated>2019-01-09T08:30:44Z</updated>

		<summary type="html">&lt;p&gt;Marc Brown: /* Bitwise Operators */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039;. Bits strings are manipulated as a unit using &amp;#039;&amp;#039;&amp;#039;shift&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;circulate&amp;#039;&amp;#039;&amp;#039; operators. The bits on the left are called the &amp;#039;&amp;#039;most significant bits&amp;#039;&amp;#039; and those on the right are the &amp;#039;&amp;#039;least significant bits&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.&lt;br /&gt;
&lt;br /&gt;
== Operators==&lt;br /&gt;
&lt;br /&gt;
=== Bitwise Operators ===&lt;br /&gt;
&lt;br /&gt;
The logical operators are  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; (~ or $\neg$), &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; (&amp;amp;), &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; (|), and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands.  The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 and 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if one or both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 or 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;111011&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; function is often use to force the value of a bit in a bit-string to be 1, if it isn&amp;#039;t already.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of two values is 1 if the values are different and 0 if they are the same. For example, 1011011 xor 011001 = 110010. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; function is often used to change the value of a particular bit.&lt;br /&gt;
&lt;br /&gt;
All binary operators (and, or, or xor) must operate on bit-strings that are of&lt;br /&gt;
the same length. If the operands are not the same&lt;br /&gt;
length, the shorter one is padded with 0&amp;#039;s on the left as needed. For &lt;br /&gt;
example, &amp;#039;&amp;#039;&amp;#039;11010 and 1110&amp;#039;&amp;#039;&amp;#039; would have value of &amp;#039;&amp;#039;&amp;#039;11010 and 01110 = 01010&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The following table summarizes the operators:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
! &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
| o&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Shift Operators ===&lt;br /&gt;
&lt;br /&gt;
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.   &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
The following table gives some examples of these operations:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: right&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!x&lt;br /&gt;
!(LSHIFT-2 x)&lt;br /&gt;
!(RSHIFT-3 x)&lt;br /&gt;
!(LCIRC-3 x)&lt;br /&gt;
!(RCIRC-1 x)&lt;br /&gt;
|-&lt;br /&gt;
!01101&lt;br /&gt;
| 10100&lt;br /&gt;
| 00001&lt;br /&gt;
| 01011&lt;br /&gt;
| 10110&lt;br /&gt;
|-&lt;br /&gt;
!10&lt;br /&gt;
| 00&lt;br /&gt;
| 00&lt;br /&gt;
| 01&lt;br /&gt;
| 01&lt;br /&gt;
|-&lt;br /&gt;
!1110&lt;br /&gt;
| 1000&lt;br /&gt;
| 0001&lt;br /&gt;
| 0111&lt;br /&gt;
| 0111&lt;br /&gt;
|-&lt;br /&gt;
!1011011&lt;br /&gt;
| 1101100&lt;br /&gt;
| 0001011&lt;br /&gt;
| 1011101&lt;br /&gt;
| 1101101&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Order of Precedence ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(0101110 AND NOT 110110 OR (LSHIFT-2 101010))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows:&lt;br /&gt;
:(0101110 AND &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-2 101010))&lt;br /&gt;
:(&amp;#039;&amp;#039;&amp;#039;001000&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-3 101010))&lt;br /&gt;
:(001000 OR &amp;#039;&amp;#039;&amp;#039;010000&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;011000&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows, starting at the innermost parentheses:&lt;br /&gt;
:(RCIRC-2 01101) =&amp;gt; 01011&lt;br /&gt;
:(LCIRC-4 01011) =&amp;gt; 10101&lt;br /&gt;
:(RSHIFT-1 10101) = 01010&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
List all possible values of x (5 bits long) that solve the following equation.&lt;br /&gt;
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Since x is a string 5 bits long, represent it by abcde.  (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab.  This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).&lt;br /&gt;
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, 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”.  The four possible values of x are: 00000, 00001, 00100 and 00101.&lt;br /&gt;
&lt;br /&gt;
=== Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression:&lt;br /&gt;
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) &amp;amp; (RSHIFT-2 10111))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The problem can be rewritten as &lt;br /&gt;
: A | B &amp;amp; C&lt;br /&gt;
The AND has higher precedence than the OR.  &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Expressions B and C are pretty easy to evaluate:&lt;br /&gt;
:B = (LSHIFT-1 10011) = 00110&lt;br /&gt;
:C = (RSHIFT-2 10111) = 00101&lt;br /&gt;
&lt;br /&gt;
The expression becomes&lt;br /&gt;
: A | B &amp;amp; C = 10110 | 00110 &amp;amp; 00101 = 10110 | 00100 = 10110&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/IeMsD3harrE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/IeMsD3harrE &amp;#039;&amp;#039;Bit String Flicking (Intro)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jbKw8oYJPs4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jbKw8oYJPs4 &amp;#039;&amp;#039;Bit String Flicking Shifts and Circs&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Part 2 covers logical shifts and circulate operations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/XNBcO25mgCw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/XNBcO25mgCw &amp;#039;&amp;#039;Bit String Flicking&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/8J9AdxU5CW8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/8J9AdxU5CW8 &amp;#039;&amp;#039;Bit String Flicking by Ravi Yeluru&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;hemsra&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through two problems from the Junior Division.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aa_lQ8gft60&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aa_lQ8gft60 &amp;#039;&amp;#039;ACSL BitString Flicking Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of problems given in previous years at the Intermediate Division level.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=LISP&amp;diff=616</id>
		<title>LISP</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=LISP&amp;diff=616"/>
		<updated>2019-01-09T08:29:07Z</updated>

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

		<summary type="html">&lt;p&gt;Marc Brown: Marc Brown uploaded a new version of File:Graph sample3.svg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&amp;diff=614</id>
		<title>Digital Electronics</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Digital_Electronics&amp;diff=614"/>
		<updated>2018-10-27T13:08:13Z</updated>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		<summary type="html">&lt;p&gt;Marc Brown: /* Reference Manual */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Programs written in high-level languages are traditionally converted by compilers into assembly language, which is turned into machine language programs – sequences of 1’s and 0’s – by an assembler. Even today, with very good quality compilers available, there is the need for programmers to understand assembly language.  First, it provides programmers with a better understanding of the compiler and its constraints.  Second, on occasion, programmers find themselves needing to program directly in assembly language in order to meet constraints in execution speed or space. &lt;br /&gt;
&lt;br /&gt;
ACSL chose to define its own assembly language rather than use a “real” one in order to eliminate the many sticky details associated with real languages.  The basic concepts of our ACSL topic description are common to all assembly languages.  &lt;br /&gt;
&lt;br /&gt;
== Reference Manual ==&lt;br /&gt;
&lt;br /&gt;
Execution starts at the first line of the program and continues sequentially, except for branch instructions (BG, BE, BL, BU), until the end instruction (END) is encountered.  The result of each operation is stored in a special word of memory, called the “accumulator” (ACC).  Each line of an assembly language program has the following fields (lower-case indicates optional components):&lt;br /&gt;
&lt;br /&gt;
 label OPCODE LOC comments&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;label&amp;#039;&amp;#039; is a character string beginning in the first column.  Valid OPCODE’s are listed in the chart below.  The LOC field is either a reference to a label or &amp;#039;&amp;#039;immediate data&amp;#039;&amp;#039;.  For example, “LOAD A” would put the contents referenced by the label “A” into the ACC; “LOAD =123” would store the value 123 in the ACC.  Only those instructions that do not modify the LOC field can use the “immediate data” format.  In the following chart, they are indicated by an asterisk in the first column.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!OP CODE&lt;br /&gt;
!DESCRIPTION&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*LOAD&lt;br /&gt;
|The contents of LOC are placed in the ACC. LOC is unchanged.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!STORE&lt;br /&gt;
|The contents of the ACC are placed in the LOC. ACC is unchanged.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*ADD&lt;br /&gt;
|The contents of LOC are added to the contents of the ACC.  The sum is stored in the ACC. LOC is unchanged. Addition is modulo 1,000,000.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*SUB&lt;br /&gt;
|The contents of LOC are subtracted from the contents of the ACC.  The difference is stored in the ACC.  LOC is unchanged.  Subtraction is modulo 1,000,000.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*MULT&lt;br /&gt;
|The contents of LOC are multiplied by the contents of the ACC.  The product is stored in the ACC.  LOC is unchanged.  Multiplication is modulo 1,000,000.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*DIV&lt;br /&gt;
|The contents of LOC are divided into the contents of the ACC.  The signed integer part of the quotient is stored in the ACC.  LOC is unchanged.&lt;br /&gt;
.&lt;br /&gt;
|-&lt;br /&gt;
!BG&lt;br /&gt;
|&lt;br /&gt;
Branch to the instruction labeled with LOC if ACC&amp;gt;0.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!BE&lt;br /&gt;
|&lt;br /&gt;
Branch to the instruction labeled with LOC if ACC=0.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!BL&lt;br /&gt;
|&lt;br /&gt;
Branch to the instruction labeled with LOC if ACC&amp;lt;0.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!BU&lt;br /&gt;
|Branch to the instruction labeled with LOC.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!READ&lt;br /&gt;
|&lt;br /&gt;
Read a signed integer (modulo 1,000,000) into LOC.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!PRINT&lt;br /&gt;
|&lt;br /&gt;
Print the contents of LOC.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!DC&lt;br /&gt;
|&lt;br /&gt;
The value of the memory word defined by the LABEL field is defined to contain the specified constant.  The LABEL field is mandatory for this opcode.  The ACC is not modified.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!END&lt;br /&gt;
| &lt;br /&gt;
Program terminates.  LOC field is ignored.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
After the following program is executed, &lt;br /&gt;
what value is in location TEMP?&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|TEMP || DC || 0&lt;br /&gt;
|-&lt;br /&gt;
|A||DC||8&lt;br /&gt;
|-&lt;br /&gt;
|B||DC||-2&lt;br /&gt;
|-&lt;br /&gt;
|C||DC||3&lt;br /&gt;
|-&lt;br /&gt;
| ||LOAD||B&lt;br /&gt;
|-&lt;br /&gt;
| ||MULT||C&lt;br /&gt;
|-&lt;br /&gt;
| ||ADD||A&lt;br /&gt;
|-&lt;br /&gt;
| ||DIV||B&lt;br /&gt;
|-&lt;br /&gt;
| ||SUB||A&lt;br /&gt;
|-&lt;br /&gt;
| ||STORE||TEMP&lt;br /&gt;
|-&lt;br /&gt;
| ||END||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; The ACC takes on values -2, -6, 2, -1, and -9 in that order. The last value, -9, is stored in location TEMP.&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
If the following program has an input value&lt;br /&gt;
of N, what is the final value of X which is&lt;br /&gt;
computed?  Express X as an algebraic&lt;br /&gt;
expression in terms of N.	&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|  || READ || X&lt;br /&gt;
|-&lt;br /&gt;
|  || LOAD || X&lt;br /&gt;
|-&lt;br /&gt;
|TOP || SUB || =1&lt;br /&gt;
|-&lt;br /&gt;
|  || BE || DONE&lt;br /&gt;
|-&lt;br /&gt;
|  || STORE || A&lt;br /&gt;
|-&lt;br /&gt;
|  || MULT || X&lt;br /&gt;
|-&lt;br /&gt;
|  || STORE || X&lt;br /&gt;
|-&lt;br /&gt;
|  || LOAD || A&lt;br /&gt;
|-&lt;br /&gt;
|  || BU || TOP&lt;br /&gt;
|-&lt;br /&gt;
|DONE || END || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; This program loops between labels TOP and&lt;br /&gt;
DONE for A times.  A has an initial value of X and subsequent terms of N,&lt;br /&gt;
then values of A-1, A-2, …, 1.  Each time through the loop,&lt;br /&gt;
X is multiplied by the the current value of A.&lt;br /&gt;
Thus, X = A * (A-1) * (A-2) * … * 1 or X=A! or A factorial.&lt;br /&gt;
For example, 5! = 5 * 4 * 3 * 2 * 1 = 120.  Since the&lt;br /&gt;
initial value of A is the number input (i.e. N),&lt;br /&gt;
the algebraic expression is X = N!.&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/RUm3iHsbO3I&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/RUm3iHsbO3I &amp;#039;&amp;#039;Intro to Assembly Language&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A general introduction into assembly language. In particular, it covers how it fits into the source code to an executable image pipeline.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/i_JYT398O64&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/i_JYT398O64 &amp;#039;&amp;#039;Syntax of ACSL Assembly Language&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A very nice introduction to this ACSL category.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/NEQASUsZ0g4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/NEQASUsZ0g4 &amp;#039;&amp;#039;Examples&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through a couple of ACSL Assembly language programs that have been used in previous contests.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=590</id>
		<title>FSAs and Regular Expressions</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&amp;diff=590"/>
		<updated>2018-09-13T00:08:56Z</updated>

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

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

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

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

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

		<summary type="html">&lt;p&gt;Marc Brown: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=580</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=580"/>
		<updated>2018-09-12T05:59:23Z</updated>

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

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

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

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

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

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

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

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

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

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

		<summary type="html">&lt;p&gt;Marc Brown: /* Context */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The expression $5+\large{8\over{3-1}}$ clearly has a value of 9. It is written in &amp;#039;&amp;#039;infix&amp;#039;&amp;#039; notation as $5+8/(3-1)$. The value of an &amp;#039;&amp;#039;infix&amp;#039;&amp;#039; version is well-defined because there is a well-established order of precedence in mathematics: We first evaluate the parentheses (3-1=2); then, because division has higher precedence that subtraction, we next do 8/2=4. And finally, 5+4=9.  The order of precedence is often given the mnemonic of &amp;#039;&amp;#039;&amp;#039;Please excuse my dear Aunt Sue&amp;#039;&amp;#039;&amp;#039;, or &amp;#039;&amp;#039;&amp;#039;PEMDAS&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039;arentheses, &amp;#039;&amp;#039;&amp;#039;e&amp;#039;&amp;#039;&amp;#039;xponentiation, &amp;#039;&amp;#039;&amp;#039;m&amp;#039;&amp;#039;&amp;#039;ultiplication/&amp;#039;&amp;#039;&amp;#039;d&amp;#039;&amp;#039;&amp;#039;ivision, and &amp;#039;&amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;#039;ddition/&amp;#039;&amp;#039;&amp;#039;&amp;#039;s&amp;#039;&amp;#039;&amp;#039;ubtraction. Multiplication and division have the same level of precedence; addition and subtraction also have the same level of precedence. Terms with equals precedence are evaluated from left-to-right [https://en.wikipedia.org/wiki/Order_of_operations wikipedia].&lt;br /&gt;
&lt;br /&gt;
The algorithm to evaluate an &amp;#039;&amp;#039;infix&amp;#039;&amp;#039; expression is complex, as it must address the order of precedence. Two alternative notations have been developed which lend themselves to simple computer algorithms for evaluating expressions. In &amp;#039;&amp;#039;prefix&amp;#039;&amp;#039; notation, each operator is placed before its operands . The expression above would be &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;+ 5 / 8 - 3 1&amp;lt;/syntaxhighlight&amp;gt;. In &amp;#039;&amp;#039;postfix&amp;#039;&amp;#039; notation, each operator is placed after its operand. The expression above is &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;5 8 3 1 - / +&amp;lt;/syntaxhighlight&amp;gt;.  In &amp;#039;&amp;#039;prefix&amp;#039;&amp;#039; and &amp;#039;&amp;#039;postfix&amp;#039;&amp;#039; notations, there is no notion of order of precedence, nor are there any parentheses. The evaluation is the same regardless of the operators. &lt;br /&gt;
&lt;br /&gt;
Problems in this category ask to convert between prefix, infix, and postfix, or to evaluate an expression in prefix or postfix.&lt;br /&gt;
&lt;br /&gt;
== Converting Expressions ==&lt;br /&gt;
&lt;br /&gt;
An algorithm for converting from infix to prefix (postfix) is as follows:&lt;br /&gt;
* Fully parenthesize the infix expression.  It should now consist solely of “terms”:  a binary operator sandwiched between two operands.&lt;br /&gt;
* Write down the operands in the same order that they appear in the infix expression.&lt;br /&gt;
* Look at each term in the infix expression in the order that one would evaluate them, i.e., inner-most parenthesis to outer-most and left to right among terms of the same depth.&lt;br /&gt;
* For each term, write down the operand before (after) the operators.  &lt;br /&gt;
&lt;br /&gt;
One way to convert from prefix (postfix) to infix is to make repeated scans through the expression. &lt;br /&gt;
Each scan, find an operator with two adjacent operators and replace it with a parenthesized infix expression. &lt;br /&gt;
This is not the most efficient algorithm, but works well for a human.&lt;br /&gt;
&lt;br /&gt;
A quick check for determining whether a conversion is correct is to convert the result back into the original format.  &lt;br /&gt;
&lt;br /&gt;
== Context ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Prefix&amp;#039;&amp;#039; and &amp;#039;&amp;#039;postfix&amp;#039;&amp;#039; notation is also known as [https://en.wikipedia.org/wiki/Polish_notation &amp;#039;&amp;#039;Polish&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Reverse Polish&amp;#039;&amp;#039; notation], respectively.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Infix to Prefix ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting $X=\left(AB-{C\over{D}}\right)^E$ from infix to prefix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!(X = (((A * B) - (C / D)) ↑ E)) &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot;  |X A B C D E	&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;* A B&amp;lt;/syntaxhighlight&amp;gt; C D E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;* A B&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;/ C D&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;- * A B / C D&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; |  X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;↑-  * A B / C D E&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;= X ↑ - * A B / C D E&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Infix to Postfix ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting $X=\left(AB-{C\over{D}}\right)^E$ from infix to postfix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!(X = (((A * B) - (C / D)) ↑ E))&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot;  |X A B C D E	&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B *&amp;lt;/syntaxhighlight&amp;gt; C D E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B *&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;C D /&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B * C D / -&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; |  X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B * C D / - E ↑&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt; X A B * C D / - E ↑ =&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Prefix to Infix ===&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting  $(3*4+{8\over{2}})^{(7-5)}$  from its prefix representation to infix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ↑ + * 3 4 / 8 2 – 7 5 &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | ↑ + &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; / 8 2 – 7 5&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |↑ + &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(8/2)&amp;lt;/syntaxhighlight&amp;gt; – 7 5&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |↑ &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)+(8/2)&amp;lt;/syntaxhighlight&amp;gt; - 7 5&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |↑ &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;((3*4)+(8/2))&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(7-5)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(((3*4)+(8/2))↑(7-5))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Postfix to Infix ===&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting  $(3*4+{8\over{2}})^{(7-5)}$  from its postfix representation to infix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!3 4 * 8 2 / + 7 5 -↑&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; 8 2 / + 7 5 - ↑&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(8/2)&amp;lt;/syntaxhighlight&amp;gt; + 7 5 - ↑&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;((3*4)+(8/2))&amp;lt;/syntaxhighlight&amp;gt; 7 5 -↑ &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;((3*4)+(8/2))&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(7-5)&amp;lt;/syntaxhighlight&amp;gt; ↑ &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(((3*4)+(8/2))↑(7-5))&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some previous problems.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/Lj91oRv3EIY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/Lj91oRv3EIY &amp;#039;&amp;#039;ACSL Prep - Mrs. Gupta - Prefix Infix Postfix&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;MegaChristian5555&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video starts with a nice introduction to the category, and then solves a handful of practice problems.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/lDm08rP_lms&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/lDm08rP_lms &amp;#039;&amp;#039;ACSL Prefix Postfix Infix Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Mr. Minich is an ACSL advisor. This video was created to help prepare his students for the ACSL Prefix/Infix/Postfix category. It shows solutions to 5 different problems that have&lt;br /&gt;
appeared in recent years. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/4YZdsw2UOpo&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/4YZdsw2UOpo &amp;#039;&amp;#039;Prefix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
To quote the video description: &amp;#039;&amp;#039;A general tutorial on prefix notation that can be used for American Computer Science League.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/R-t9-rbJDw8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/R-t9-rbJDw8 &amp;#039;&amp;#039;Postfix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
To quote the video description: &amp;#039;&amp;#039;A general tutorial on postfix notation that can be used for American Computer Science League.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/dcc-nXY2L6c&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/dcc-nXY2L6c &amp;#039;&amp;#039;2015 16 Contest 2 Prefix Infix Postfix Problem#1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Ravi Yeluru walks through the solution to an ACSL Prefix/Infix/Postfix program that appeared in the 2015-16 year, Contest #2.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/lEIPvUqstEY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/lEIPvUqstEY &amp;#039;&amp;#039;2015 16 Contest 2 Prefix Infix Postfix Problem#2&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Ravi Yeluru walks through the solution to an ACSL Prefix/Infix/Postfix program that appeared in the 2015-16 year, Contest #2.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Other Videos ===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos cover various aspects of this topic; they were created by authors who are not involved (or aware) of ACSL, to the best of our knowledge. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/t7YWDiz8LMY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/t7YWDiz8LMY &amp;#039;&amp;#039;Infix Postfix and Prefix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Carleton Moore&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A very gentle overview of infix, prefix, and postfix.&lt;br /&gt;
 &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/z3VsmufB_QI&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/z3VsmufB_Q I&amp;#039;&amp;#039;Infix Prefix and Postfix&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;University Academy&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Another very gentle overview of infix, prefix, and postfix.&lt;br /&gt;
 &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jos1Flt21is&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jos1Flt21is &amp;#039;&amp;#039;Infix Postfix and Prefix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;mycodeschool&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Another overview of infix, prefix, and postfix notations.&lt;br /&gt;
 &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/MeRb_1bddWg&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/MeRb_1bddWg &amp;#039;&amp;#039;Evaluation of Prefix and Postfix expressions using stack&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;mycodeschool&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Describes the standard algorithm to evaluate prefix and postfix expressions.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vq-nUF0G4fI&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vq-nUF0G4fI &amp;#039;&amp;#039;Infix to Postfix using stack&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;mycodeschool&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Describes the standard algorithm to convert from infix to postfix. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Prefix/Infix/Postfix_Notation&amp;diff=568</id>
		<title>Prefix/Infix/Postfix Notation</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Prefix/Infix/Postfix_Notation&amp;diff=568"/>
		<updated>2018-09-09T09:39:31Z</updated>

		<summary type="html">&lt;p&gt;Marc Brown: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The expression $5+\large{8\over{3-1}}$ clearly has a value of 9. It is written in &amp;#039;&amp;#039;infix&amp;#039;&amp;#039; notation as $5+8/(3-1)$. The value of an &amp;#039;&amp;#039;infix&amp;#039;&amp;#039; version is well-defined because there is a well-established order of precedence in mathematics: We first evaluate the parentheses (3-1=2); then, because division has higher precedence that subtraction, we next do 8/2=4. And finally, 5+4=9.  The order of precedence is often given the mnemonic of &amp;#039;&amp;#039;&amp;#039;Please excuse my dear Aunt Sue&amp;#039;&amp;#039;&amp;#039;, or &amp;#039;&amp;#039;&amp;#039;PEMDAS&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039;arentheses, &amp;#039;&amp;#039;&amp;#039;e&amp;#039;&amp;#039;&amp;#039;xponentiation, &amp;#039;&amp;#039;&amp;#039;m&amp;#039;&amp;#039;&amp;#039;ultiplication/&amp;#039;&amp;#039;&amp;#039;d&amp;#039;&amp;#039;&amp;#039;ivision, and &amp;#039;&amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;#039;ddition/&amp;#039;&amp;#039;&amp;#039;&amp;#039;s&amp;#039;&amp;#039;&amp;#039;ubtraction. Multiplication and division have the same level of precedence; addition and subtraction also have the same level of precedence. Terms with equals precedence are evaluated from left-to-right [https://en.wikipedia.org/wiki/Order_of_operations wikipedia].&lt;br /&gt;
&lt;br /&gt;
The algorithm to evaluate an &amp;#039;&amp;#039;infix&amp;#039;&amp;#039; expression is complex, as it must address the order of precedence. Two alternative notations have been developed which lend themselves to simple computer algorithms for evaluating expressions. In &amp;#039;&amp;#039;prefix&amp;#039;&amp;#039; notation, each operator is placed before its operands . The expression above would be &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;+ 5 / 8 - 3 1&amp;lt;/syntaxhighlight&amp;gt;. In &amp;#039;&amp;#039;postfix&amp;#039;&amp;#039; notation, each operator is placed after its operand. The expression above is &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;5 8 3 1 - / +&amp;lt;/syntaxhighlight&amp;gt;.  In &amp;#039;&amp;#039;prefix&amp;#039;&amp;#039; and &amp;#039;&amp;#039;postfix&amp;#039;&amp;#039; notations, there is no notion of order of precedence, nor are there any parentheses. The evaluation is the same regardless of the operators. &lt;br /&gt;
&lt;br /&gt;
Problems in this category ask to convert between prefix, infix, and postfix, or to evaluate an expression in prefix or postfix.&lt;br /&gt;
&lt;br /&gt;
== Converting Expressions ==&lt;br /&gt;
&lt;br /&gt;
An algorithm for converting from infix to prefix (postfix) is as follows:&lt;br /&gt;
* Fully parenthesize the infix expression.  It should now consist solely of “terms”:  a binary operator sandwiched between two operands.&lt;br /&gt;
* Write down the operands in the same order that they appear in the infix expression.&lt;br /&gt;
* Look at each term in the infix expression in the order that one would evaluate them, i.e., inner-most parenthesis to outer-most and left to right among terms of the same depth.&lt;br /&gt;
* For each term, write down the operand before (after) the operators.  &lt;br /&gt;
&lt;br /&gt;
One way to convert from prefix (postfix) to infix is to make repeated scans through the expression. &lt;br /&gt;
Each scan, find an operator with two adjacent operators and replace it with a parenthesized infix expression. &lt;br /&gt;
This is not the most efficient algorithm, but works well for a human.&lt;br /&gt;
&lt;br /&gt;
A quick check for determining whether a conversion is correct is to convert the result back into the original format.  &lt;br /&gt;
&lt;br /&gt;
== Context ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Prefix&amp;#039;&amp;#039; and &amp;#039;&amp;#039;postfix&amp;#039;&amp;#039; notation is also known as &amp;#039;&amp;#039;Polish&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Reverse Polish&amp;#039;&amp;#039; notation, respectively, for the Polish logician Jan Lukasiewicz. &lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Infix to Prefix ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting $X=\left(AB-{C\over{D}}\right)^E$ from infix to prefix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!(X = (((A * B) - (C / D)) ↑ E)) &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot;  |X A B C D E	&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;* A B&amp;lt;/syntaxhighlight&amp;gt; C D E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;* A B&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;/ C D&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;- * A B / C D&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; |  X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;↑-  * A B / C D E&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;= X ↑ - * A B / C D E&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Infix to Postfix ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting $X=\left(AB-{C\over{D}}\right)^E$ from infix to postfix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!(X = (((A * B) - (C / D)) ↑ E))&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot;  |X A B C D E	&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B *&amp;lt;/syntaxhighlight&amp;gt; C D E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B *&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;C D /&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B * C D / -&amp;lt;/syntaxhighlight&amp;gt; E&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; |  X &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;A B * C D / - E ↑&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff; text-align: left; padding-left: 2em&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt; X A B * C D / - E ↑ =&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Prefix to Infix ===&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting  $(3*4+{8\over{2}})^{(7-5)}$  from its prefix representation to infix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ↑ + * 3 4 / 8 2 – 7 5 &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | ↑ + &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; / 8 2 – 7 5&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |↑ + &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(8/2)&amp;lt;/syntaxhighlight&amp;gt; – 7 5&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |↑ &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)+(8/2)&amp;lt;/syntaxhighlight&amp;gt; - 7 5&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |↑ &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;((3*4)+(8/2))&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(7-5)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(((3*4)+(8/2))↑(7-5))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Postfix to Infix ===&lt;br /&gt;
&lt;br /&gt;
The following sequence of steps illustrates converting  $(3*4+{8\over{2}})^{(7-5)}$  from its postfix representation to infix:&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!3 4 * 8 2 / + 7 5 -↑&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; 8 2 / + 7 5 - ↑&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(3*4)&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(8/2)&amp;lt;/syntaxhighlight&amp;gt; + 7 5 - ↑&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;((3*4)+(8/2))&amp;lt;/syntaxhighlight&amp;gt; 7 5 -↑ &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; | &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;((3*4)+(8/2))&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(7-5)&amp;lt;/syntaxhighlight&amp;gt; ↑ &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background-color: #ffffff&amp;quot; |&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; inline&amp;gt;(((3*4)+(8/2))↑(7-5))&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some previous problems.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/Lj91oRv3EIY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/Lj91oRv3EIY &amp;#039;&amp;#039;ACSL Prep - Mrs. Gupta - Prefix Infix Postfix&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;MegaChristian5555&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
This video starts with a nice introduction to the category, and then solves a handful of practice problems.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/lDm08rP_lms&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/lDm08rP_lms &amp;#039;&amp;#039;ACSL Prefix Postfix Infix Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Mr. Minich is an ACSL advisor. This video was created to help prepare his students for the ACSL Prefix/Infix/Postfix category. It shows solutions to 5 different problems that have&lt;br /&gt;
appeared in recent years. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/4YZdsw2UOpo&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/4YZdsw2UOpo &amp;#039;&amp;#039;Prefix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
To quote the video description: &amp;#039;&amp;#039;A general tutorial on prefix notation that can be used for American Computer Science League.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/R-t9-rbJDw8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/R-t9-rbJDw8 &amp;#039;&amp;#039;Postfix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
To quote the video description: &amp;#039;&amp;#039;A general tutorial on postfix notation that can be used for American Computer Science League.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/dcc-nXY2L6c&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/dcc-nXY2L6c &amp;#039;&amp;#039;2015 16 Contest 2 Prefix Infix Postfix Problem#1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Ravi Yeluru walks through the solution to an ACSL Prefix/Infix/Postfix program that appeared in the 2015-16 year, Contest #2.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/lEIPvUqstEY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/lEIPvUqstEY &amp;#039;&amp;#039;2015 16 Contest 2 Prefix Infix Postfix Problem#2&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Ravi Yeluru&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Ravi Yeluru walks through the solution to an ACSL Prefix/Infix/Postfix program that appeared in the 2015-16 year, Contest #2.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Other Videos ===&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos cover various aspects of this topic; they were created by authors who are not involved (or aware) of ACSL, to the best of our knowledge. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/t7YWDiz8LMY&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/t7YWDiz8LMY &amp;#039;&amp;#039;Infix Postfix and Prefix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Carleton Moore&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A very gentle overview of infix, prefix, and postfix.&lt;br /&gt;
 &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/z3VsmufB_QI&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/z3VsmufB_Q I&amp;#039;&amp;#039;Infix Prefix and Postfix&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;University Academy&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Another very gentle overview of infix, prefix, and postfix.&lt;br /&gt;
 &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jos1Flt21is&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jos1Flt21is &amp;#039;&amp;#039;Infix Postfix and Prefix Notation&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;mycodeschool&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Another overview of infix, prefix, and postfix notations.&lt;br /&gt;
 &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/MeRb_1bddWg&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/MeRb_1bddWg &amp;#039;&amp;#039;Evaluation of Prefix and Postfix expressions using stack&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;mycodeschool&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Describes the standard algorithm to evaluate prefix and postfix expressions.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/vq-nUF0G4fI&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/vq-nUF0G4fI &amp;#039;&amp;#039;Infix to Postfix using stack&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;mycodeschool&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Describes the standard algorithm to convert from infix to postfix. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=LISP&amp;diff=567</id>
		<title>LISP</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=LISP&amp;diff=567"/>
		<updated>2018-09-09T09:36:41Z</updated>

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

		<summary type="html">&lt;p&gt;Marc Brown: /* Sample Problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039;. Bits strings are manipulated as a unit using &amp;#039;&amp;#039;&amp;#039;shift&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;circulate&amp;#039;&amp;#039;&amp;#039; operators. The bits on the left are called the &amp;#039;&amp;#039;most significant bits&amp;#039;&amp;#039; and those on the right are the &amp;#039;&amp;#039;least significant bits&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.&lt;br /&gt;
&lt;br /&gt;
== Operators==&lt;br /&gt;
&lt;br /&gt;
=== Bitwise Operators ===&lt;br /&gt;
&lt;br /&gt;
The logical operators are  &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; (~ or $\neg$), &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; (&amp;amp;), &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; (|), and &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands.  The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 and 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; of two values is 1 only if one or both values are 1. For example, &amp;#039;&amp;#039;&amp;#039;1011011 or 011001&amp;#039;&amp;#039;&amp;#039; has a value of &amp;#039;&amp;#039;&amp;#039;111011&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; function is often use to force the value of a bit in a bit-string to be 1, if it isn&amp;#039;t already.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; is a binary operator that performs the logical &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of each bit in each of its operands. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; of two values is 1 if the values are different and 0 if they are the same. For example, 1011011 xor 011001 = 110010. The &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; function is often used to change the value of a particular bit.&lt;br /&gt;
&lt;br /&gt;
All binary operators (and, or, or xor) must operate on bit-strings that are of&lt;br /&gt;
the same length. If the operands are not the same&lt;br /&gt;
length, the shorter one is padded with 0&amp;#039;s on the left as needed. For &lt;br /&gt;
example, &amp;#039;&amp;#039;&amp;#039;11010 and 1110&amp;#039;&amp;#039;&amp;#039; would have value of &amp;#039;&amp;#039;&amp;#039;11010 and 01110 = 01010&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The following table summarizes the operators:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
! &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
!&amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;xor&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!0&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
|-&lt;br /&gt;
!0&lt;br /&gt;
!1&lt;br /&gt;
| 1 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!0&lt;br /&gt;
| 0 &lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 0  &lt;br /&gt;
|-&lt;br /&gt;
!1&lt;br /&gt;
!1&lt;br /&gt;
| 0 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
| 1 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Shift Operators ===&lt;br /&gt;
&lt;br /&gt;
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.   &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
The following table gives some examples of these operations:&lt;br /&gt;
&lt;br /&gt;
::{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: right&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!x&lt;br /&gt;
!(LSHIFT-2 x)&lt;br /&gt;
!(RSHIFT-3 x)&lt;br /&gt;
!(LCIRC-3 x)&lt;br /&gt;
!(RCIRC-1 x)&lt;br /&gt;
|-&lt;br /&gt;
!01101&lt;br /&gt;
| 10100&lt;br /&gt;
| 00001&lt;br /&gt;
| 01011&lt;br /&gt;
| 10110&lt;br /&gt;
|-&lt;br /&gt;
!10&lt;br /&gt;
| 00&lt;br /&gt;
| 00&lt;br /&gt;
| 01&lt;br /&gt;
| 01&lt;br /&gt;
|-&lt;br /&gt;
!1110&lt;br /&gt;
| 1000&lt;br /&gt;
| 0001&lt;br /&gt;
| 0111&lt;br /&gt;
| 0111&lt;br /&gt;
|-&lt;br /&gt;
!1011011&lt;br /&gt;
| 1101100&lt;br /&gt;
| 0001011&lt;br /&gt;
| 1011101&lt;br /&gt;
| 1101101&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Order of Precedence ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(0101110 AND NOT 110110 OR (LSHIFT-2 101010))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows:&lt;br /&gt;
:(0101110 AND &amp;#039;&amp;#039;&amp;#039;001001&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-2 101010))&lt;br /&gt;
:(&amp;#039;&amp;#039;&amp;#039;001000&amp;#039;&amp;#039;&amp;#039; OR (LSHIFT-3 101010))&lt;br /&gt;
:(001000 OR &amp;#039;&amp;#039;&amp;#039;010000&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;011000&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression: &lt;br /&gt;
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The expression evaluates as follows, starting at the innermost parentheses:&lt;br /&gt;
:(RCIRC-2 01101) =&amp;gt; 01011&lt;br /&gt;
:(LCIRC-4 01011) =&amp;gt; 10101&lt;br /&gt;
:(RSHIFT-1 10101) = 01010&lt;br /&gt;
&lt;br /&gt;
=== Problem 3 ===&lt;br /&gt;
&lt;br /&gt;
List all possible values of x (5 bits long) that solve the following equation.&lt;br /&gt;
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Since x is a string 5 bits long, represent it by abcde.  (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab.  This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).&lt;br /&gt;
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, 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”.  The four possible values of x are: 00000, 00001, 00100 and 00101.&lt;br /&gt;
&lt;br /&gt;
=== Problem 4 ===&lt;br /&gt;
&lt;br /&gt;
Evaluate the following expression:&lt;br /&gt;
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) &amp;amp; (RSHIFT-2 10111))&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The problem can be rewritten as &lt;br /&gt;
: A | B &amp;amp; C&lt;br /&gt;
The AND has higher precedence than the OR.  &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Expressions B and C are pretty easy to evaluate:&lt;br /&gt;
:B = (LSHIFT-1 10011) = 00110&lt;br /&gt;
:C = (RSHIFT-2 10111) = 00101&lt;br /&gt;
&lt;br /&gt;
The expression becomes&lt;br /&gt;
: A | B &amp;amp; C = 10110 | 00110 &amp;amp; 00101 = 10110 | 00100 = 10110&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/IeMsD3harrE&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/IeMsD3harrE &amp;#039;&amp;#039;Bit String Flicking (Intro)&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/jbKw8oYJPs4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/jbKw8oYJPs4 &amp;#039;&amp;#039;Bit String Flicking Shifts and Circs&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Part 2 covers logical shifts and circulate operations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/XNBcO25mgCw&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/XNBcO25mgCw &amp;#039;&amp;#039;Bit String Flicking&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;Tangerine Code&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/8J9AdxU5CW8&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/8J9AdxU5CW8 &amp;#039;&amp;#039;Bit String Flicking by Ravi Yeluru&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;hemsra&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through two problems from the Junior Division.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/aa_lQ8gft60&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/aa_lQ8gft60 &amp;#039;&amp;#039;ACSL BitString Flicking Contest 2 Worksheet 1&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;misterminich&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Solves a handful of problems given in previous years at the Intermediate Division level.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&amp;diff=565</id>
		<title>Boolean Algebra</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&amp;diff=565"/>
		<updated>2018-09-09T09:35:18Z</updated>

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

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

		<summary type="html">&lt;p&gt;Marc Brown: /* Sample Problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Programs written in high-level languages are traditionally converted by compilers into assembly language, which is turned into machine language programs – sequences of 1’s and 0’s – by an assembler. Even today, with very good quality compilers available, there is the need for programmers to understand assembly language.  First, it provides programmers with a better understanding of the compiler and its constraints.  Second, on occasion, programmers find themselves needing to program directly in assembly language in order to meet constraints in execution speed or space. &lt;br /&gt;
&lt;br /&gt;
ACSL chose to define its own assembly language rather than use a “real” one in order to eliminate the many sticky details associated with real languages.  The basic concepts of our ACSL topic description are common to all assembly languages.  &lt;br /&gt;
&lt;br /&gt;
== Reference Manual ==&lt;br /&gt;
&lt;br /&gt;
Execution starts at the first line of the program and continues sequentially, except for branch instructions (BG, BE, BL, BU), until the end instruction (END) is encountered.  The result of each operation is stored in a special word of memory, called the “accumulator” (ACC).  Each line of an assembly language program has the following fields (lower-case indicates optional components):&lt;br /&gt;
&lt;br /&gt;
 label OPCODE LOC comments&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;label&amp;#039;&amp;#039; is a character string beginning in the first column.  Valid OPCODE’s are listed in the chart below.  The LOC field is either a reference to a label or &amp;#039;&amp;#039;immediate data&amp;#039;&amp;#039;.  For example, “LOAD A” would put the contents referenced by the label “A” into the ACC; “LOAD =123” would store the value 123 in the ACC.  Only those instructions that do not modify the LOC field can use the “immediate data” format.  In the following chart, they are indicated by an asterisk in the first column.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
!OP CODE&lt;br /&gt;
!DESCRIPTION&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*LOAD&lt;br /&gt;
|The contents of LOC are placed in the ACC. LOC is unchanged.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!STORE&lt;br /&gt;
|The contents of LOC are placed in the LOC. ACC is unchanged.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*ADD&lt;br /&gt;
|The contents of LOC are added to the contents of the ACC.  The sum is stored in the ACC. LOC is unchanged. Addition is modulo 1,000,000.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*SUB&lt;br /&gt;
|The contents of LOC are subtracted from the contents of the ACC.  The difference is stored in the ACC.  LOC is unchanged.  Subtraction is modulo 1,000,000.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*MULT&lt;br /&gt;
|The contents of LOC are multiplied by the contents of the ACC.  The product is stored in the ACC.  LOC is unchanged.  Multiplication is modulo 1,000,000.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!*DIV&lt;br /&gt;
|The contents of LOC are divided into the contents of the ACC.  The signed integer part of the quotient is stored in the ACC.  LOC is unchanged.&lt;br /&gt;
.&lt;br /&gt;
|-&lt;br /&gt;
!BG&lt;br /&gt;
|&lt;br /&gt;
Branch to the instruction labeled with LOC if ACC&amp;gt;0.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!BE&lt;br /&gt;
|&lt;br /&gt;
Branch to the instruction labeled with LOC if ACC=0.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!BL&lt;br /&gt;
|&lt;br /&gt;
Branch to the instruction labeled with LOC if ACC&amp;lt;0.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!BU&lt;br /&gt;
|Branch to the instruction labeled with LOC.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!READ&lt;br /&gt;
|&lt;br /&gt;
Read a signed integer (modulo 1,000,000) into LOC.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!PRINT&lt;br /&gt;
|&lt;br /&gt;
Print the contents of LOC.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!DC&lt;br /&gt;
|&lt;br /&gt;
The value of the memory word defined by the LABEL field is defined to contain the specified constant.  The LABEL field is mandatory for this opcode.  The ACC is not modified.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
!END&lt;br /&gt;
| &lt;br /&gt;
Program terminates.  LOC field is ignored.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sample Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Problem 1 ===&lt;br /&gt;
&lt;br /&gt;
After the following program is executed, &lt;br /&gt;
what value is in location TEMP?&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|TEMP || DC || 0&lt;br /&gt;
|-&lt;br /&gt;
|A||DC||8&lt;br /&gt;
|-&lt;br /&gt;
|B||DC||-2&lt;br /&gt;
|-&lt;br /&gt;
|C||DC||3&lt;br /&gt;
|-&lt;br /&gt;
| ||LOAD||B&lt;br /&gt;
|-&lt;br /&gt;
| ||MULT||C&lt;br /&gt;
|-&lt;br /&gt;
| ||ADD||A&lt;br /&gt;
|-&lt;br /&gt;
| ||DIV||B&lt;br /&gt;
|-&lt;br /&gt;
| ||SUB||A&lt;br /&gt;
|-&lt;br /&gt;
| ||STORE||TEMP&lt;br /&gt;
|-&lt;br /&gt;
| ||END||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; The ACC takes on values -2, -6, 2, -1, and -9 in that order. The last value, -9, is stored in location TEMP.&lt;br /&gt;
&lt;br /&gt;
=== Problem 2 ===&lt;br /&gt;
&lt;br /&gt;
If the following program has an input value&lt;br /&gt;
of N, what is the final value of X which is&lt;br /&gt;
computed?  Express X as an algebraic&lt;br /&gt;
expression in terms of N.	&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left&amp;quot;&lt;br /&gt;
|  || READ || X&lt;br /&gt;
|-&lt;br /&gt;
|  || LOAD || X&lt;br /&gt;
|-&lt;br /&gt;
|TOP || SUB || =1&lt;br /&gt;
|-&lt;br /&gt;
|  || BE || DONE&lt;br /&gt;
|-&lt;br /&gt;
|  || STORE || A&lt;br /&gt;
|-&lt;br /&gt;
|  || MULT || X&lt;br /&gt;
|-&lt;br /&gt;
|  || STORE || X&lt;br /&gt;
|-&lt;br /&gt;
|  || LOAD || A&lt;br /&gt;
|-&lt;br /&gt;
|  || BU || TOP&lt;br /&gt;
|-&lt;br /&gt;
|DONE || END || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution:&amp;#039;&amp;#039;&amp;#039; This program loops between labels TOP and&lt;br /&gt;
DONE for A times.  A has an initial value of X and subsequent terms of N,&lt;br /&gt;
then values of A-1, A-2, …, 1.  Each time through the loop,&lt;br /&gt;
X is multiplied by the the current value of A.&lt;br /&gt;
Thus, X = A * (A-1) * (A-2) * … * 1 or X=A! or A factorial.&lt;br /&gt;
For example, 5! = 5 * 4 * 3 * 2 * 1 = 120.  Since the&lt;br /&gt;
initial value of A is the number input (i.e. N),&lt;br /&gt;
the algebraic expression is X = N!.&lt;br /&gt;
&lt;br /&gt;
== Video Resources ==&lt;br /&gt;
&lt;br /&gt;
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/RUm3iHsbO3I&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/RUm3iHsbO3I &amp;#039;&amp;#039;Intro to Assembly Language&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A general introduction into assembly language. In particular, it covers how it fits into the source code to an executable image pipeline.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/i_JYT398O64&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/i_JYT398O64 &amp;#039;&amp;#039;Syntax of ACSL Assembly Language&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
A very nice introduction to this ACSL category.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;https://youtu.be/NEQASUsZ0g4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [https://youtu.be/NEQASUsZ0g4 &amp;#039;&amp;#039;Examples&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;CalculusNguyenify&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
Walks through a couple of ACSL Assembly language programs that have been used in previous contests.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;youtube width=&amp;quot;300&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;URL&amp;lt;/youtube&amp;gt;&lt;br /&gt;
| [URL &amp;#039;&amp;#039;TITLE&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;AUTHOR&amp;#039;&amp;#039;&amp;#039;)]&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
|}&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=562</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Main_Page&amp;diff=562"/>
		<updated>2018-09-09T09:24:59Z</updated>

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

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

		<summary type="html">&lt;p&gt;Marc Brown: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Marc Brown</name></author>
	</entry>
	<entry>
		<id>http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=559</id>
		<title>Data Structures</title>
		<link rel="alternate" type="text/html" href="http://www.categories.acsl.org/wiki/index.php?title=Data_Structures&amp;diff=559"/>
		<updated>2018-09-09T09:13:16Z</updated>

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