<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
      <title>Labs on The Art of Computing </title>
    <link>https://artofcomputing.cecs.anu.edu.au/tags/labs/index.xml</link>
    <language>en-US</language>
    <author>Enthusiastic Hugo User</author>
    <rights>Copyright (c) 2014, Enthusiastic Hugo User; all rights reserved.</rights>
    <updated>Mon, 01 Jan 0001 00:00:00 UTC</updated>
    
    <item>
      <title>Lab 9: Combinatorial Circuits</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/lab9/</link>
      <pubDate>Sun, 14 May 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/lab9/</guid>
      <description>&lt;p&gt;In this lab, you will use the
&lt;a href=&#34;http://www.cburch.com/logisim/&#34;&gt;Logisim&lt;/a&gt;
tool, along with pen and paper, to analyse and create simple
combinatorial circuits.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2 id=&#34;installing-and-starting-logisim&#34;&gt;Installing and Starting Logisim&lt;/h2&gt;

&lt;p&gt;Unlike Snap!, Logisim does not run in a web browser but needs
to be installed. It is not installed on the CSIT lab computers,
so to use it, you will have to install it on your own computer
or on your student account.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download &lt;a href=&#34;http://sourceforge.net/projects/circuit/files/latest/download&#34;&gt;the Logisim v. 2.7.1 JAR file&lt;/a&gt; and save it in a convenient location
(e.g., your home directory).&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;You will probably be able to start the program by simply
(double-)clicking on the JAR file.
If that doesn&amp;rsquo;t work, on a GNU/Linux system you can start a
commandline (&amp;ldquo;terminal&amp;rdquo;) and type in&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;java -jar logisim-generic-2.7.1.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(assuming you are in the directory where the file is).&lt;/p&gt;

&lt;p&gt;Note that Logisim requires Java version 5 or later.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&#34;exercise-9-1-no-marks&#34;&gt;Exercise 9.1 (no marks)&lt;/h3&gt;

&lt;p&gt;First, do the following simple exercise to familiarise yourself a
bit with the Logisim environment.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download the file &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/code/lab9ex1.circ&#34;&gt;lab9ex1.circ&lt;/a&gt;
(using &amp;ldquo;save link as&amp;rdquo;), then open the file in Logisim
(select &amp;ldquo;Open&amp;hellip;&amp;rdquo; under the &amp;ldquo;File&amp;rdquo; menu).
If everything worked, you should now see a simple combinatorial
circuit.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;What does this circuit do? It computes some function&lt;/p&gt;

&lt;p&gt;Output = F(A, B, C)&lt;/p&gt;

&lt;p&gt;where all three inputs and the output are binary (0 or 1).
But what is the function F? To find out, you can:&lt;/p&gt;

&lt;p&gt;a. Figure it out by looking at the circuit.&lt;/p&gt;

&lt;p&gt;b. Select the &amp;ldquo;poke&amp;rdquo; tool
(&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/logisim-poke-tool.png&#34; alt=&#34;poke tool icon&#34; /&gt;),
click on the inputs A, B and C to change their value, and observe
how the output changes.&lt;/p&gt;

&lt;p&gt;c. From the &amp;ldquo;Project&amp;rdquo; menu, select &amp;ldquo;Analyze Circuit&amp;rdquo;.
This opens a window with information about the circuit.
Under &amp;ldquo;Table&amp;rdquo; you can find the complete truth table for the
circuit, and under &amp;ldquo;Expression&amp;rdquo; you can see the equivalent
Boolean expression.
(Note that Logisim does not have a symbol for logical AND in
expressions: &amp;ldquo;x AND y&amp;rdquo; is written just &amp;ldquo;x y&amp;rdquo;. The symbol for
logical OR is &amp;ldquo;+&amp;rdquo; and for NOT is &amp;ldquo;~&amp;ldquo;.)&lt;/p&gt;

&lt;p&gt;Make sure you try the first two methods before the last.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Is there a simpler/smaller circuit that computes the same function?
Using the truth table for the circuit, attempt to find a smaller
expression that generates the same table. Build the corresponding circuit
next to the one given (using the same inputs, but a new output) and test
it to see that it gives the same result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(Again, Logisim offers you a way to cheat: The &amp;ldquo;Minimized&amp;rdquo; tab of the
circuit analysis window will give you a minimal expression, and can
even rebuild the circuit automatically for you. Use this to check what
you came up with by hand.)&lt;/p&gt;

&lt;h3 id=&#34;exercise-9-2-sorting-numbers-with-circuits&#34;&gt;Exercise 9.2 Sorting Numbers with Circuits&lt;/h3&gt;

&lt;p&gt;In this exercise, you will construct a circuit that sorts four
4-bit binary numbers. This means the circuit has has 16 inputs
and 16 outputs! If you tried build it directly, the result would
probably be pretty gigantic.
So, instead, we will introduce some intermediate abstractions,
which will help keep the size of the result manageable.&lt;/p&gt;

&lt;p&gt;Download the file &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/code/lab9ex2.circ&#34;&gt;lab9ex2.circ&lt;/a&gt; and open it in
Logisim.
The project contains several defined components: a &amp;ldquo;1-bit swap&amp;rdquo;,
a &amp;ldquo;4-bit swap&amp;rdquo; and a &amp;ldquo;4-bit compare &amp;amp; swap&amp;rdquo;.&lt;/p&gt;

&lt;h3 id=&#34;task-1-1-bit-swap-50&#34;&gt;Task 1 1-bit swap (50%)&lt;/h3&gt;

&lt;p&gt;The 1-bit swap element is not implemented. Your first task is to build it.&lt;/p&gt;

&lt;p&gt;The 1-bit swap has three inputs, called &lt;em&gt;Input 1&lt;/em&gt;, &lt;em&gt;Input 2&lt;/em&gt; and
&lt;em&gt;swap?&lt;/em&gt;, and two outputs, called &lt;em&gt;Output 1&lt;/em&gt; and &lt;em&gt;Output 2&lt;/em&gt;.
The element is meant to implement a controllable swap of the two
inputs into the two outputs.
In other words, behaviour of the circuit should be as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When &lt;em&gt;swap?&lt;/em&gt; is 0, the inputs are just copied to the outputs, that is
&lt;em&gt;Output 1&lt;/em&gt; equals &lt;em&gt;Input 1&lt;/em&gt; and &lt;em&gt;Output 2&lt;/em&gt; equals &lt;em&gt;Input 2&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;When &lt;em&gt;swap?&lt;/em&gt; is 1, the outputs are the inputs swapped, that is
&lt;em&gt;Output 1&lt;/em&gt; equals &lt;em&gt;Input 2&lt;/em&gt; and &lt;em&gt;Output 2&lt;/em&gt; equals &lt;em&gt;Input 1&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hints&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To help you understand how to make this work, you can draw up the
truth table (it has only 2&lt;sup&gt;3&lt;/sup&gt; = 8 lines) and fill in the
correct outputs for each case.&lt;/p&gt;

&lt;p&gt;If you are using more than 10 gates to build the circuit, you&amp;rsquo;re on the
wrong track; there is an easier solution. Look at the truth table.&lt;/p&gt;

&lt;p&gt;All the inputs and output that your circuit should have are already
in place, so you should not have to place any new &amp;ldquo;pins&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to build circuits in Logisim&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To view and edit the circuit that implements one of the defined elements
(1-bit swap, etc), double-click on it in the left-hand-side menu. You
can also double-click &amp;ldquo;main&amp;rdquo; to get back to the main circuit.&lt;/li&gt;
&lt;li&gt;To add a gate to the circuit, select the gate you want from the
menu on the left. Then just click on the circuit board to add the gate.&lt;/li&gt;
&lt;li&gt;When you have selected the edit tool
(&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/logisim-edit-tool.png&#34; alt=&#34;edit tool icon&#34; /&gt;) you can move
components and add wires. Right-click and select &amp;ldquo;Delete&amp;rdquo; to remove
a component or wire.&lt;/li&gt;
&lt;li&gt;To connect components, add or extend wires. Components have a small
marker where they can connect (you will see a small green circle when
the pointer is on the mark). You can also add a branch off an existing
wire, at any point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/video/logisim-edit-ex2.mp4&#34;&gt;a short video&lt;/a&gt; showing how it is
done. (Note: The circuit built in the video is &lt;em&gt;not&lt;/em&gt; the solution to
this exercise!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test your circuit!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After you have built a circuit, you can check that it does the right
thing by either using the poke tool to vary the inputs, or using
Logisim&amp;rsquo;s built-in circuit analyzer, which will show you the truth
table for both outputs.&lt;/p&gt;

&lt;p&gt;The 4-bit swap element is implemented using several 1-bit swaps. Thus,
after you have built the 1-bit swap (correctly), the 4-bit swap will
also work. In the main circuit, off to the right, there is a small test
circuit for the 4-bit swap: it has two 4-bit inputs and a (1-bit) swap
input, and two displayed outputs. Using the poke tool, you can change
the inputs; when you toggle the swap bit, you should see the outputs
change place. (Note that when you use the poke tool to change multi-bit
inputs, you must toggle each bit separately by clicking on it.)&lt;/p&gt;

&lt;h3 id=&#34;task-2-the-4-number-sorting-circuit-50&#34;&gt;Task 2 The 4-number sorting circuit (50%)&lt;/h3&gt;

&lt;p&gt;The 4-bit compare &amp;amp; swap element has two inputs and two outputs, which
are all 4-bit binary numbers. It sorts the two input numbers: that is,
the first (upper) output is the smaller of the two numbers, and the
second (lower) output is the bigger one. Note that it does an &lt;em&gt;unsigned&lt;/em&gt;
comparison. This means the numbers are interpreted as positive (ranging
from 0 to 15), not in 2&amp;rsquo;s complement.&lt;/p&gt;

&lt;p&gt;The 4-bit compare &amp;amp; swap element is implemented using the 4-bit swap
and a &amp;ldquo;comparator&amp;rdquo; (a component from Logisim&amp;rsquo;s standard library).
A test circuit is provided (also to the right in &amp;ldquo;main&amp;rdquo;): use the poke
tool to change the inputs and observe what happens with the output.
(This is also a chance to practice reading binary numbers: how do you
set the inputs to, for example, 12 and 9?)&lt;/p&gt;

&lt;p&gt;Now, you should build the 4-number sorting circuit using only 4-bit
compare and swap elements (and wires). The inputs (labelled A-D) are
on the left and the outputs (labelled #1-#4) are on the right. The
outputs should be the inputs sorted in increasing order, that is,
#1 should be the smallest of A,B,C,D, #2 the second smallest, and so
on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have trouble working out how to sort the four numbers, think
recursively. This circuit gives you part of one possible solution for
sorting three numbers:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/how-to-sort-hint.png&#34; alt=&#34;part of sort 3&#34; /&gt;&lt;/p&gt;

&lt;p&gt;After the two compare &amp;amp; swaps, the top wire has the smallest number, and
the other two hold the two larger numbers (but not in sorted order). How
would you complete this circuit to sort all three numbers?
If you have a circuit that can sort three numbers, how could you use it
to sort four numbers?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test and save your circuit!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After you have built the circuit, check that works by varying the inputs.
(The circuit analyzer tool does not work with multi-bit inputs and outputs.)&lt;/p&gt;

&lt;p&gt;Save your circuit in a new file (using &amp;ldquo;Save As&amp;hellip;&amp;rdquo; from the File menu).
This is the file that you will need to submit for this assignment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submission:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You must submit one Logisim circuit file, containing your solutions
to Tasks 1 and 2. Submit the files through
&lt;a href=&#34;http://wattlecourses.anu.edu.au/course/view.php?id=12823&#34;&gt;wattle&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Lab 8: Learning to diagnose - Machine learning with decision trees </title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/decisiontree/</link>
      <pubDate>Wed, 26 Apr 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/decisiontree/</guid>
      <description>

&lt;p&gt;This lab practice the ideas of recursive computation with tree structure and core concepts of machine learning, by learning a decision tree for diagnosing breast cancer.&lt;/p&gt;

&lt;!--more --&gt;

&lt;!--
# Learning to diagnose - Machine learning with decision trees

**Joy of Computing Tutorial 6: Machine Learning**

Andrew Wrigley, &lt;andrew.wrigley@anu.edu.au&gt;&lt;br /&gt;
May 2014

## Preface

This tutorial is designed to support the _Topic 6: Machine Learning_ component of the upcoming Joy of Computing (JoC) course at ANU.

It details a set of practical tasks that JoC students will undertake as part of the course in an
interactive format. The tasks are related to decision tree learning and include background material and discussion
questions. The target audience of this work is future students undertaking the JoC course. 
For further background on the design and
implementation of these exercises, see [design and implementation](topic6-ml-design.html).
--&gt; 

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#intro&#34;&gt;Data, data everywhere&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#task1&#34;&gt;Task 1: Decision trees and classification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#task2&#34;&gt;Reading: Choosing a decision rule&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#task3&#34;&gt;Task 2: Building a decision tree&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#extn1&#34;&gt;Task 3: Analysing performance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#references&#34;&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Submission instructions&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;For this lab, you will need to submit two files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;An xml file containing Snap blocks for Task 1-3. This block should contain &amp;ldquo;Choice node &amp;hellip;&amp;rdquo; from task 1, &amp;ldquo;Build a decision tree &amp;hellip;&amp;rdquo; block from task 2, and &amp;ldquo;Test performance &amp;hellip;&amp;rdquo; from task 3, as well as blocks they depend on.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A written report for Task3 (written electronically in an editor of your choice, and exported to pdf)as described below.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Breaking down by tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task 1 (40%) - implement &amp;ldquo;Choice node &amp;hellip;&amp;rdquo; block, you need to import this block to task 2 project.&lt;/li&gt;
&lt;li&gt;Task 2 (40%) - implement &amp;ldquo;Build a decision tree &amp;hellip;&amp;rdquo; block.&lt;/li&gt;
&lt;li&gt;Task 3 (20%)- implement &amp;ldquo;Test performance &amp;hellip;&amp;rdquo; block and answer the questions in 3.2 and 3.3 in a short report format, there are 10 questions in total.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a name=&#34;intro&#34; id=&#34;intro&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;data-data-everywhere&#34;&gt;Data, data everywhere&lt;/h2&gt;

&lt;p&gt;In the 21st century, data is everywhere. Being able to make sense of large data sets and use them to make predictions is
becoming increasingly relevant in many domains including scientific and medical research, government, and commerce.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Machine learning&lt;/em&gt; is the study of computer algorithms that learn from data. Commonly, we are given some &lt;em&gt;training data&lt;/em&gt;
containing a set of sample input and output pairs and want to use this to make &lt;em&gt;predictions&lt;/em&gt; for future inputs whose
true output value is unknown. Using a set of labelled training data to learn in this manner is known as &lt;em&gt;supervised
learning&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Supervised learning algorithms use training data to create a &lt;em&gt;model&lt;/em&gt; which describes a probabilistic
relationship between input and output data, and are then able to use this model to make predictions. The fundamental
goal in supervised learning is to create models that &lt;em&gt;generalise&lt;/em&gt; well. This means that they must make accurate
predictions when given future, unknown inputs rather than simply modelling the training data perfectly
[&lt;a href=&#34;#references&#34;&gt;1&lt;/a&gt;].&lt;/p&gt;

&lt;p&gt;In this tutorial you will investigate a popular model called the &lt;em&gt;decision tree&lt;/em&gt;, and see how it can be applied as a
diagnostic tool in medicine.&lt;/p&gt;

&lt;h3 id=&#34;a-data-set-for-medical-diagnosis&#34;&gt;A data set for medical diagnosis&lt;/h3&gt;

&lt;p&gt;The training data set we will use in this tutorial is a subset of the &lt;em&gt;Breast Cancer Wisconsin (Original) Data Set&lt;/em&gt;,
courtesy of the UCI Machine Learning Repository [&lt;a href=&#34;#references&#34;&gt;4&lt;/a&gt;]. Each training example contains a set of
measurements, called &lt;em&gt;features&lt;/em&gt;, and a corresponding classification as either malignant (true) or benign (false). The 9
features were obtained from &lt;a href=&#34;http://en.wikipedia.org/wiki/Fine-needle_aspiration&#34;&gt;Fine-Needle Aspiration Cytology&lt;/a&gt; (FNAC) measurements of human tissue. Each feature has been
&lt;em&gt;normalised&lt;/em&gt; to lie in the range 1-10, with high valued features thought to represent more malignant (cancerous) cell
characteristics. All feature values are integers.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  #  Feature                       Domain
  -- -----------------------------------------
  1. Clump Thickness               1 - 10
  2. Uniformity of Cell Size       1 - 10
  3. Uniformity of Cell Shape      1 - 10
  4. Marginal Adhesion             1 - 10
  5. Single Epithelial Cell Size   1 - 10
  6. Bare Nuclei                   1 - 10
  7. Bland Chromatin               1 - 10
  8. Normal Nucleoli               1 - 10
  9. Mitoses                       1 - 10
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this tutorial we will represent a single training example as a list containing 10 elements - the 9 input features and
the corresponding class. For example &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/training-example.png&#34; alt=&#34;training-example&#34; /&gt; represents a training example
whose class is benign. The training data set is then a list of training examples - a list of lists.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;test&lt;/em&gt; example, e.g. from a new patient, however contains only the 9 input features. For example,&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/input-vector.png&#34; alt=&#34;input-vector&#34; /&gt; represents a test example
whose class is unknown. The test &lt;em&gt;data set&lt;/em&gt; is then a list of test examples - also a list of lists in Snap. Your overall goal is to &lt;em&gt;learn&lt;/em&gt; good decision rules from a &lt;em&gt;training dataset&lt;/em&gt;, so as to classify the &lt;em&gt;test examples&lt;/em&gt; correctly.&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;task1&#34; id=&#34;task1&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;task-1-decision-trees-and-classification-40&#34;&gt;Task 1: Decision trees and classification (40%)&lt;/h2&gt;

&lt;p&gt;Trees are one of the most widely used data structures in computer science. They are used for searching, sorting,
representing hierarchical relationships and even finding routes for data over the Internet. Recall that a tree consists of a single &lt;em&gt;root node&lt;/em&gt;, a number of &lt;em&gt;internal nodes&lt;/em&gt; and &lt;em&gt;leaf nodes&lt;/em&gt;, and that these nodes are connected with &lt;em&gt;edges&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A decision tree is a special type of tree used to classify input data into one of a number of classes. Each internal
node (or &lt;em&gt;decision node&lt;/em&gt;) of a decision tree contains a &lt;em&gt;decision rule&lt;/em&gt;, and each leaf node contains a class label.
Here is a simple decision tree for our FNAC domain with 4 decision nodes and 5 leaf nodes:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/dt-sample.png&#34; alt=&#34;Example of a decision tree&#34; /&gt;&lt;/p&gt;

&lt;p&gt;This decision tree takes a set of features as input and produces a classification of either &lt;code&gt;Benign&lt;/code&gt; or &lt;code&gt;Cancer&lt;/code&gt; as
output. To decide the class of a new input vector we start at the root node and continue down the tree, repeatedly
applying decision rules. Each decision rule compares a particular input feature with a fixed threshold, and depending on
the feature value we continue down either the left or right subtree. When we reach a leaf node we stop and this becomes
the classification for our input vector.&lt;/p&gt;

&lt;p&gt;The decision function at each decision node in our tree can therefore be described by two parameters: a &lt;em&gt;feature number&lt;/em&gt;
and a &lt;em&gt;split point&lt;/em&gt;. The number in brackets next to the feature description at each decision node is the feature number.
The number next to the edges leaving a decision node is the split point.&lt;/p&gt;

&lt;h4 id=&#34;discussion-question&#34;&gt;Discussion question&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Under this decision tree, would the input vector &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/input-vector.png&#34; alt=&#34;input-vector&#34; /&gt; be classified as &lt;code&gt;Benign&lt;/code&gt; or &lt;code&gt;Cancer&lt;/code&gt;?&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;recursion-with-trees&#34;&gt;Recursion with trees&lt;/h4&gt;

&lt;p&gt;A tree is an example of a &lt;em&gt;recursive data type&lt;/em&gt;. The children of a node in a tree are themselves trees - large trees are
created simply by joining smaller trees together. In the example above, the subtree rooted at the node labelled &lt;code&gt;Clump
thickness&lt;/code&gt; and the subtree rooted at the node labelled &lt;code&gt;Bare nuclei&lt;/code&gt; are both perfectly valid decision trees in their
own right. We were able to construct a larger decision tree by joining these two trees with a new choice node labelled
&lt;code&gt;Marginal adhesion&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Defining trees in this recursive manner allows us to write beautifully simple algorithms that achieve non-trivial
results. For example to classify a new input vector, all a choice node needs to do is pass the input vector to its
left or right child and ask it to perform the classification. In this task, you will add a &lt;code&gt;classify&lt;/code&gt; method to both
the choice nodes and leaf nodes and see how this works.&lt;/p&gt;

&lt;p&gt;In this task the tree structure is fixed (- later, you will see how the tree structure can be learned from training data).&lt;/p&gt;

&lt;h3 id=&#34;instructions&#34;&gt;Instructions&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The Snap! project link for this task is &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/decisiontree-task1.xml&#34;&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;&lt;p&gt;The code around the top of the scripting area will create a fixed decision tree and show it on the stage.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/init_tree_task1.png&#34; alt=&#34;init-tree&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Opening the block will show you its definition in Snap! that correspond to its shape drawn on stage. If this looks very busy, don&amp;rsquo;t worry, the rest of this task will break down and explain each component in turn.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/fixed_tree_task1.png&#34; alt=&#34;fixed_tree_task1&#34; /&gt;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;We start by implementing simplest decision tree ever - the leaf node. We also use this part to look at the concept of implementing a function as part of a list (i.e. a gray ring).&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/decision-node.png&#34; alt=&#34;decision-node&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The inpupt to a leaf node is a test example, the output is a decision (true or false).
There are two types of leaf nodes: One that always returns &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/true.png&#34; alt=&#34;true&#34; /&gt; (cancer) or one that always returns &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/false.png&#34; alt=&#34;false&#34; /&gt;  (benign). Therefore the expected behaviour of a &lt;em&gt;true&lt;/em&gt; leaf node, invoked with given input data, is shown below&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/leaf_true.png&#34; alt=&#34;ask_leaf_true&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Therefore, the leaf node should always report a class label. This class label should also be the same as the type of leaf node (i.e. TRUE or FALSE in angle slot).&lt;/p&gt;

&lt;p&gt;Look at the snap workspace to see how this is implemented.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;You next task is to complete the choice node:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/choice-node.png&#34; alt=&#34;choice-node&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Currently, it will also report &lt;code&gt;Not implemented&lt;/code&gt; when asked to classify
an input vector. Your goal is to edit the node type blocks so the decision tree reports either
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/true.png&#34; alt=&#34;true&#34; /&gt; or &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/false.png&#34; alt=&#34;false&#34; /&gt; for an input vector according to the structure of the decision tree. Similar to the leaf node, replace &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/report-not-implemented.png&#34; alt=&#34;report-not-implemented&#34; /&gt; with your code.&lt;/p&gt;

&lt;p&gt;Two utility blocks to help you visualize the process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-draw-tree.png&#34; alt=&#34;tell-artist-draw-tree&#34; /&gt; draws a decision tree to the stage.&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-draw-classification-blank.png&#34; alt=&#34;tell-artist-draw-classification-blank&#34; /&gt; can be used to visualise how a given decision tree should classify a new input vector. For example, the visualization of a small decision tree &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-draw-classification2.png&#34; alt=&#34;tell-artist-draw-classification&#34; /&gt; shows:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/dt-small-classify.png&#34; alt=&#34;Example of `draw_classification` command&#34; /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some more hints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remember, you are implementing a recursive algorithm. Rather than report &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/true.png&#34; alt=&#34;true&#34; /&gt; or
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/false.png&#34; alt=&#34;false&#34; /&gt; directly, a decision node should delegate this decision to one of its children.&lt;/li&gt;
&lt;li&gt;For leaf nodes, the implementation forms the base for your recursion and should return either
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/true.png&#34; alt=&#34;true&#34; /&gt; or &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/false.png&#34; alt=&#34;false&#34; /&gt;.&lt;/li&gt;
&lt;li&gt;Because you are changing the code that &lt;em&gt;creates&lt;/em&gt; tree nodes, your changes will not impact trees that have already
been built unless you tell Snap! to build them again. Make sure Snap! is calling
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/choice-node.png&#34; alt=&#34;choice-node&#34; /&gt; and &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/decision-node.png&#34; alt=&#34;decision-node&#34; /&gt; every time you test your code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following three tests should help you trouble shoot and test your program as you write it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/small_ask_classify.png&#34; alt=&#34;smalltree-classify&#34; /&gt; should reproduce the two-level tree drawn above, and report &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/false.png&#34; alt=&#34;false&#34; /&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-print.png&#34; alt=&#34;tell-artist-print&#34; /&gt;  prints a message to the bottom of the stage. For example: &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/artist_print_result.png&#34; alt=&#34;tell-artist-print-false&#34; /&gt; this prints the classification result of the original tree above, it should say &amp;ldquo;Classification: false&amp;rdquo;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;On the other hand, a slightly different test example &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/artist_print_result2.png&#34; alt=&#34;tell-artist-true&#34; /&gt; should say &amp;ldquo;Classification: true&amp;rdquo;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;When you think your implementation is working run the following test:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test-classification.png&#34; alt=&#34;test-classification&#34; /&gt;. This will
test your implementation with a range of different inputs and report &lt;code&gt;Pass&lt;/code&gt; or &lt;code&gt;Fail&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&#34;discussion&#34;&gt;Discussion&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Execute these blocks at the end of the Snap workspace &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/converse_tree.png&#34; alt=&#34;converse tree&#34; /&gt;.
Notice that this tree here is the exact converse of the 3-level decision tree earlier &amp;ndash; whenever the other tree says &amp;lsquo;cancer&amp;rsquo; this tree will diagnose &amp;lsquo;benign&amp;rsquo; &amp;hellip; So which tree is correct?
The next few tasks will explore this question.&lt;/li&gt;
&lt;/ul&gt;

&lt;!--
#### Hints
*   Some Snap! functions are available to help you visualise decision trees.

    *  ![tell-artist-draw-tree](/images/lab8/tell-artist-draw-tree.png) draws a decision tree to the stage.
    *   ![tell-artist-draw-classification-blank](/images/lab8/tell-artist-draw-classification-blank.png) can be used to visualise how a given decision tree should classify a new input vector. For example, using the decision tree above ![tell-artist-draw-classification](/images/lab8/tell-artist-draw-classification.png) shows:

        ![Example of `draw_classification` command](/images/lab8/dt-sample-classify.png)

        The input vector is displayed at the top of the stage with the features used to classify the input vector
        coloured in orange.
    -   ![tell-artist-print](/images/lab8/tell-artist-print.png) prints a message to the bottom of the stage. This is useful
        for debugging your code.
--&gt;

&lt;p&gt;&lt;a name=&#34;task2&#34; id=&#34;task2&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;reading-choosing-a-decision-rule&#34;&gt;Reading - Choosing a decision rule&lt;/h2&gt;

&lt;p&gt;Remember that our goal in decision tree learning is to build a decision tree automatically based on our training data. How can we do that?&lt;/p&gt;

&lt;h4 id=&#34;greed-is-good&#34;&gt;Greed is good&lt;/h4&gt;

&lt;p&gt;In computer science, a &lt;em&gt;greedy algorithm&lt;/em&gt; is an algorithm that finds a solution to a problem by making &lt;em&gt;locally optimal&lt;/em&gt; decisions. Greedy algorithms make a series of choices that seem best at the time but depending on the problem may not
produce a globally optimal solution. These algorithms are often useful when finding a globally optimal solution is not
computationally feasible. In the next two tasks, we will use a greedy algorithm to build our decision tree, choosing
decision functions at each node that appear to best split the data we have at the time.&lt;/p&gt;

&lt;p&gt;We are going to start with all our training data, and build our tree by splitting our data set over and over until we
reach some stopping criteria. The algorithm we will use to choose a feature and split point given a set of training
examples is as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Input: dataset with N features
Output: (feature, split point) pair

for each feature 1 to N:
    sort dataset by feature
    for each split point in sorted dataset:
        evaluate the gain of split
        if gain is the highest seen so far:
            remember gain, feature and split point
return highest gain, and the corresponding feature and split point
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The gain of splitting on a given feature at a given split point is a measure of the quality of the split. At each
stage, we want to choose the split with the lowest cost. To define this cost concretely, we need to understand the
concept of &lt;em&gt;entropy&lt;/em&gt;.&lt;/p&gt;

&lt;h5 id=&#34;discussion-questions&#34;&gt;Discussion questions&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Why do we sort the data set before looping over possible split points?&lt;/li&gt;
&lt;li&gt;Is finding the &lt;em&gt;globally&lt;/em&gt; optimal split possible, and computationally feasible?&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;information-entropy&#34;&gt;Information entropy&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Entropy&lt;/em&gt; gives us a measure of the uncertainty associated with a probability distribution. Suppose we roll a die and
wish to predict which outcome in the set $C={1,2,3,4,5,6}$ will occur next. If the die is fair, each outcome in $C$
has an equal probability of occuring ($p(x) = \frac{1}{6}$). Because of this, it is difficult to predict which number
will come up next - the outcome is uncertain. We say that the distribution of outcomes has high &lt;em&gt;entropy&lt;/em&gt;. Conversely,
the distribution of an unfair die (that is more likely to roll some numbers than others) has lower entropy since there
is less uncertainty associated with rolling it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/die-high-entropy.png&#34; alt=&#34;High entropy: a fair die&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/die-low-entropy.png&#34; alt=&#34;Low entropy: an unfair die&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Given a random variable $X$ with probability mass function $p(x)$, the entropy $\mathbb{H}(X)$ is defined as:&lt;/p&gt;

&lt;p&gt;$$
\mathbb{H}(X) = -\sum_x p(x)\log_2 p(x)
$$&lt;/p&gt;

&lt;p&gt;taking $p(x)\log_2 p(x)=0$ whenever $p(x)=0$ [&lt;a href=&#34;#references&#34;&gt;3&lt;/a&gt;]. The more uniform the distribution $p(x)$, the higher
$\mathbb{H}$ will be. $\mathbb{H}$ is at its highest when all outcomes are equally likely.&lt;/p&gt;

&lt;h4 id=&#34;cost-function-revisited&#34;&gt;Cost function revisited&lt;/h4&gt;

&lt;p&gt;In this exercise, we define the cost of a split in terms of the entropy of the sublists that the split creates. If we
consider the proportion of training examples from each of the two classes as an approximation of a probability
distribution over the classes, then a set of training examples from mostly the same class has low entropy and a set with
an equal number from each class has high entropy. We therefore define our cost function as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cost of split = (proportion of examples in left sublist) * (entropy of left sublist) + 
                (proportion of examples in right sublist) * (entropy of right sublist)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Minimising this sum will result in both sublists having low entropy and
therefore gives us a split with the best possible class separation [&lt;a href=&#34;#references&#34;&gt;2&lt;/a&gt;].&lt;/p&gt;

&lt;h5 id=&#34;discussion-questions-1&#34;&gt;Discussion questions&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Why do we weight each term by the relative size of the sublist?&lt;/li&gt;
&lt;li&gt;What other metrics could we use to quantify the quality of a split?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/choose-feature-split.png&#34; alt=&#34;choose-feature-split&#34; /&gt; implements the feature selection function. The block takes a list of training data as input and should report the index of the optimum feature as well as the optimum split point for that feature. To report a pair of values in Snap!, report a list with two elements:
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/report-pair-feature-split.png&#34; alt=&#34;report-feature-split&#34; /&gt;.&lt;/p&gt;

&lt;h4 id=&#34;notes&#34;&gt;Notes&lt;/h4&gt;

&lt;p&gt;We encourage you to look at the implementation of the feature split block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/choose-feature-split.png&#34; alt=&#34;choose-feature-split&#34; /&gt; and note the following technical aspects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sorting is used so we can efficiently check all the possible split points for a given feature. The variable
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/split.png&#34; alt=&#34;split&#34; /&gt; is used to keep track of the possible split points when iterating over the sorted data.&lt;/li&gt;
&lt;li&gt;The block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/sort-dataset-by-feature.png&#34; alt=&#34;sort-dataset-by-feature&#34; /&gt; has been created to implement counting
sort, since comparison sorting algorithms are incredibly slow in Snap!. Note that this block relies on the features
being integers from 1 to 10 and will not work otherwise.&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Even using counting sort this procedure can be quite slow to run, so it is useful to add status messages such as:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-print-checking-feature.png&#34; alt=&#34;The `print_status` command can be used for debugging&#34; /&gt;&lt;/p&gt;

&lt;p&gt;to view progress of the algorithm.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;discussion-question-1&#34;&gt;Discussion question&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Why does this block report the cost rather than the information gain as described in class? Do they lead to the same results?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a name=&#34;task3&#34; id=&#34;task3&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;task-2-building-a-decision-tree-40&#34;&gt;Task 2: Building a decision tree (40%)&lt;/h2&gt;

&lt;p&gt;Now that we have a block to tell us the best feature and split point given a set of data, all that is left to do is to
greedily build our decision tree. In this task, we will use a recursive algorithm to do this.&lt;/p&gt;

&lt;p&gt;The tree building algorithm we will use is as follows [&lt;a href=&#34;#references&#34;&gt;3&lt;/a&gt;]:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Input: training dataset, maximum tree depth
Output: root node of a decision tree constructed greedily using minimum entropy

if depth = 1 or entropy of list = 0:
    # Stopping criteria reached
    decision = most common class in dataset
    report a leaf node with this decision
else:
    j, t = choose a feature and split point for this dataset
    left sublist, right sublist = split dataset according to (j, t)
    left child = call this procedure recursively on the left sublist with depth - 1
    right child = call this procedure recursively on the right sublist with depth - 1
    return a decision node with the above split and children
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Notice that this algorithm is recursive - it contains calls to itself.&lt;/p&gt;

&lt;h3 id=&#34;instructions-1&#34;&gt;Instructions&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Load Snap! project &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/decisiontree-learning.xml&#34;&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You will also need to import the two blocks from Task 1 for this task to work. Namely, &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/decision-node.png&#34; alt=&#34;decision-node&#34; /&gt; and &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/choice-node.png&#34; alt=&#34;choice-node&#34; /&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Implement the algorithm above when depth = 1.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This block should report a &lt;em&gt;decision tree&lt;/em&gt; of depth 1 (what kind of node is this?)
&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Test your code by learning on the following simple dataset with one feature, and making the tree classify two new examples, as shown below.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/learn-tree-level1.png&#34; alt=&#34;level1-tree&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints/discussions&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What should the &amp;lsquo;tree&amp;rsquo; here look like? Can you express it using the leaf node block?&lt;/li&gt;
&lt;li&gt;What does it do on the input with featuer &amp;ldquo;2&amp;rdquo;? (true)&lt;/li&gt;
&lt;li&gt;What does it do on the input with featuer &amp;ldquo;6&amp;rdquo;? (true) What should it do? (false) &amp;ndash; the next step would fix this.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Now let&amp;rsquo;s implement the tree with depth=2.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/learn-tree-level2.png&#34; alt=&#34;level2-tree&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints/discussions&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What should the &amp;lsquo;tree&amp;rsquo; here look like? Can you express it using the leaf node and choice node blocks?&lt;/li&gt;
&lt;li&gt;Does it now classify the input with feature &amp;ldquo;2&amp;rdquo; and &amp;ldquo;6&amp;rdquo; correctly?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Refining your implementation: If you tell the tree to learn from the same 3-example dataset, but with depth=3, what should happen? Do you actually get a tree with depth 3, why or why not?&lt;/p&gt;

&lt;p&gt;Test your implementation with the blocks below, with the 3-example dataset, and a 4-example dataset of 2 features.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/learn-tree-level3a.png&#34; alt=&#34;level3a-tree&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/learn-tree-level3b.png&#34; alt=&#34;level3b-tree&#34; /&gt;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Complete the implementation of block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/build-decision-tree.png&#34; alt=&#34;build-decision-tree&#34; /&gt;. This block takes a list of training data and a maximum tree depth as input and should report the root node of a tree constructed according to the greedy algorithm above. Test it by executing this block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/build-decision-tree2.png&#34; alt=&#34;build-decision-tree&#34; /&gt;, speed it up using &amp;ldquo;warp&amp;rdquo; after the code is correct.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;When you have constructed the tree, use &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-draw-tree.png&#34; alt=&#34;tell-artist-d&#34; /&gt; to visualise your tree. Does this tree look reasonable? Does it conform to the meanings of FNAC features, i.e., higher feature values represent more malignant cell characteristics?&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Use &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test-decision-tree.png&#34; alt=&#34;test-decision-tree&#34; /&gt; to check your results. This block takes a decision tree as input and checks the classification of some input vectors against a reference implementation.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&#34;extension-questions&#34;&gt;Extension questions&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this task we used two stopping criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maximum depth&lt;/li&gt;
&lt;li&gt;Entropy equal to zero.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What other stopping criteria could be used? What impact do the stopping criteria have on the performance of our
model on future, unknown input data?&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;In computer science, an &lt;em&gt;optimal solution&lt;/em&gt; is a solution to a problem that is at least as good as any other
solution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How would you define an optimal solution to the decision tree problem given a set of training data?&lt;/li&gt;
&lt;li&gt;The problem of finding an optimal partitioning of the data is &lt;em&gt;NP-complete&lt;/em&gt; [&lt;a href=&#34;#references&#34;&gt;3&lt;/a&gt;]. Loosely
speaking, this means we do not currently know of an efficient algorithm to solve the problem for large data sets
and it is quite likely that there isn&amp;rsquo;t one. Can you describe a &amp;lsquo;brute force&amp;rsquo; algorithm that reports the optimal
solution given a set of training data? How do you think the running time of this algorithm would compare to that
of the greedy algorithm you have implemented in this task?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;task-3-analysing-performance-20&#34;&gt;Task 3: Analysing performance (20%)&lt;/h2&gt;

&lt;p&gt;The decision tree you have constructed in this tutorial classifies the training data perfectly. Is this a good
thing? If our training set instead consisted of 1,000,000 samples, are we better off with a deep, complex decision tree that fits our training data perfectly or a simpler tree that makes some errors on the training set?&lt;/p&gt;

&lt;p&gt;Creating incredibly complex models that match our training data perfectly is known as &lt;em&gt;overfitting&lt;/em&gt;, and is something
that we must actively avoid in machine learning. Remember that our goal in machine learning is to achieve good
&lt;em&gt;generalisation&lt;/em&gt; behaviour - we want our to model to predict future, unknown inputs well, not just perform well on the training set (in other words, &lt;em&gt;remembering&lt;/em&gt; what it was taught on).&lt;/p&gt;

&lt;p&gt;We cannot judge generalisation performance using the same data set we used to train our model. For this we must use a separate set of labelled examples which we call a &lt;em&gt;test set&lt;/em&gt; [&lt;a href=&#34;#references&#34;&gt;1&lt;/a&gt;].&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;extn1&#34; id=&#34;extn1&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;exercises&#34;&gt;Exercises&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Complete the implementation of block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test-performance.png&#34; alt=&#34;test-performance&#34; /&gt; that takes a decision tree and a labelled data set and reports the &lt;em&gt;fraction&lt;/em&gt; of misclassifications that the decision tree makes on the data.&lt;/p&gt;

&lt;p&gt;For example, &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test_toy.png&#34; alt=&#34;test-toy-example&#34; /&gt; should return 0.5, as the first example is correctly classified, while the second is wrongly classified.
Use a few more example trees and datasets to test this block.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Training-testing protocol.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build a decision tree&lt;/strong&gt; using the existing data and your block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/build-decision-tree2.png&#34; alt=&#34;build-decision-tree&#34; /&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Draw the tree on stage&lt;/strong&gt; using &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/tell-artist-draw-tree.png&#34; alt=&#34;tell-artist-d&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Measure training error&lt;/strong&gt; use your block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test-performance.png&#34; alt=&#34;test-performance&#34; /&gt; to measure how many mistakes this tree has made on &lt;em&gt;training data&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download test data&lt;/strong&gt; Use the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/get-dataset-from-url.png&#34; alt=&#34;get-dataset-from-url&#34; /&gt; block to download the &lt;code&gt;breast-cancer-50.data&lt;/code&gt; data set. This data set contains 50 new labelled examples. All datasets in this lab reside in the same web directory, you can download them and assign to a new variable like this:
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test-data.png&#34; alt=&#34;test data 50&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Measure test error&lt;/strong&gt; Use your block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab8/test-performance.png&#34; alt=&#34;test-performance&#34; /&gt; to measure how many mistakes this tree has made on &lt;em&gt;test data&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In your report:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Include a picture (snap! stage) of the learned decision trees, at depth 4, 3, and 2, respectively.&lt;/li&gt;
&lt;li&gt;Include a table containing the training and test errors these trees made on training and test data, respectively.&lt;/li&gt;
&lt;li&gt;What are the training accuracies? Should it be 1.0?&lt;/li&gt;
&lt;li&gt;Why are the testing accuracy not 1.0? Should it be?&lt;/li&gt;
&lt;li&gt;What seem to be the right &lt;em&gt;depth&lt;/em&gt; of this decision tree, why?&lt;/li&gt;
&lt;li&gt;Given these results, if you were to train a tree of &lt;code&gt;max-depth=5&lt;/code&gt; using the original training data, what will the tree look like? &amp;ndash; Draw it in your report or describe in words.&lt;/li&gt;
&lt;li&gt;Discuss (and not implement) the following scenario: If you were to write a modified decision tree learning routine, in which each choice node can split one feature to up to three branches (e.g. feature 1 &amp;lt;=2, 2 &amp;lt; feature 1 &amp;lt;= 4, feature 1 &amp;gt;4), what needs to change in our program? Will you get a different decision tree? Will this generate a fundamentally better tree than a binary tree?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;The effect of training data&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Build&lt;/em&gt; two decision trees up to depth=4. One using the original training data, the other use &lt;code&gt;breast-cancer-train2.data&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Test&lt;/em&gt; them on two datasets: &lt;code&gt;breast-cancer-50.data&lt;/code&gt; as above, and &lt;code&gt;data-50-2.data&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In your report:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Include pictures of the two decision trees being compared here.&lt;/li&gt;
&lt;li&gt;Include a small table of the testing accuracy of the two trees on the two datasets.&lt;/li&gt;
&lt;li&gt;Which decision tree performs better on the two datasets? Can you offer some explanations as to why?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;!--
3. Overfitting?
    
    _Build_ two decision trees using `breast-cancer-train3.data`, one with max-depth=4, the other with max-depth=3. 

    _Test_ them on `data-50-2.data`. 

    **In your report:**

    * Include pictures of the two decision trees. 
    * Report the testing accuracy. 
    * What do you think happened in these two trees? 
--&gt;    

&lt;h4 id=&#34;discussion-1&#34;&gt;Discussion:&lt;/h4&gt;

&lt;p&gt;So how do we generally ensure that the learned model is of good quality? One commonly used technique is cross-validation. Read about this technique in Section 1.3 of Bishop&amp;rsquo;s book [&lt;a href=&#34;#references&#34;&gt;1&lt;/a&gt;] &amp;ndash; this section is included in the preview &lt;a href=&#34;http://www.amazon.com/Pattern-Recognition-Learning-Information-Statistics/dp/0387310738&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;references&#34; id=&#34;references&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Bishop, Christopher M. &lt;em&gt;Pattern recognition and machine learning.&lt;/em&gt; Vol. 1. New York: springer, 2006.&lt;/li&gt;
&lt;li&gt;Mohri, Mehryar, Afshin Rostamizadeh, and Ameet Talwalkar. &lt;em&gt;Foundations of machine learning.&lt;/em&gt; MIT Press, 2012.&lt;/li&gt;
&lt;li&gt;Murphy, Kevin P. &lt;em&gt;Machine learning: a probabilistic perspective.&lt;/em&gt; MIT Press, 2012.&lt;/li&gt;
&lt;li&gt;Wolberg, W., Mangasarian, O.: Breast Cancer Wisconsin (Original) Data Set (1992),
&lt;a href=&#34;https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Original%29&#34;&gt;https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Original%29&lt;/a&gt; (accessed May 2014).&lt;/li&gt;
&lt;/ol&gt;
</description>
    </item>
    
    <item>
      <title>Lab 7: The Sentiment of a Superstorm</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/sentiment/</link>
      <pubDate>Tue, 18 Apr 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/sentiment/</guid>
      <description>&lt;!--
# The Sentiment of a Superstorm

**Joy of Computing Tutorial 4: Computational Social Science**

Josh Chia, [u5024740@anu.edu.au][author email]
--&gt;

&lt;p&gt;For this tutorial, we&amp;rsquo;ll explore how we can use social data (tweets from Twitter) to enrich our understanding of one of the most destructive hurricanes in US history: &amp;ldquo;&lt;a href=&#34;http://en.wikipedia.org/wiki/Hurricane_Sandy&#34;&gt;Superstorm Sandy&lt;/a&gt;&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;The first part of this lab sheet contains reading material for both sentiment analysis and hashing, the second part contains the exercise questions. Skip directly to the practical part of you are impatient.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Also note that there are five scoring parts in total, Exercise 6.1 - 6.4, and visualization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Part I - Preliminaries&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#making&#34;&gt;Making Sense of Social Media&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Concept 1: Sentiment Analysis

&lt;ul&gt;
&lt;li&gt;A Simplified Approach to Determining Sentiment&lt;/li&gt;
&lt;li&gt;Sentiment Lexicon&lt;/li&gt;
&lt;li&gt;Steps for Determining Tweet Sentiment&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Interlude: The Dictionary Problem&lt;/li&gt;
&lt;li&gt;Concept 2: Hash Tables (not #HashTags)

&lt;ul&gt;
&lt;li&gt;Hash Functions&lt;/li&gt;
&lt;li&gt;Buckets and Hash Collisions&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Part II - Programming tasks&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&#34;#practical&#34;&gt;Practical: Sentiment Analysis of Superstorm Sandy&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implementing a Hash Function

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#ex61&#34;&gt;Exercise 6.1: Implement a hashing scheme&lt;/a&gt; (3 points)&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Implementing a Hash Set

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#ex62&#34;&gt;Exercise 6.2: Implement the insert operation&lt;/a&gt; (3 points)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#ex63&#34;&gt;Exercise 6.3: Implement the contains operation&lt;/a&gt; (2 points)&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Testing&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#ex64&#34;&gt;Exercise 6.4: Computing the sentiment score of a Tweet&lt;/a&gt; (1 point)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#sandy&#34;&gt;Sentiment Analysis and Visualisation of Superstorm Sandy Tweets&lt;/a&gt; (1 point)&lt;/li&gt;
&lt;li&gt;Extension Tasks

&lt;ul&gt;
&lt;li&gt;Extension Task 1: Implement the remove operation&lt;/li&gt;
&lt;li&gt;Extension Task 2: Implement dynamic resizing (rehashing)&lt;/li&gt;
&lt;li&gt;Extension Task 3: Implement the dictionary data structure (hash table)&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;References&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a name=&#34;making&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;making-sense-of-social-media&#34;&gt;Making Sense of Social Media&lt;/h2&gt;

&lt;p&gt;The prevalence of social media is changing not only the way society communicates and interacts, but also how we think about social data. For instance, can real-time social data be used to better detect the occurrence of an earthquake?[&lt;a href=&#34;http://dl.acm.org/citation.cfm?id=1772777&#34;&gt;1&lt;/a&gt;] Can social media aid disaster response to wildfires?[&lt;a href=&#34;http://dl.acm.org/citation.cfm?id=1629907&#34;&gt;2&lt;/a&gt;] What other kinds of activities could be enriched by the analysis of social data?&lt;/p&gt;

&lt;p&gt;The abundance of data presents us with the unique opportunity to better understand and utilise social behaviour and phenomena. This has lead to the rise of Computational Social Science; an interdisciplinary field which explores how computational techniques from computer science can be applied to various fields of social science.&lt;/p&gt;

&lt;p&gt;To do this we&amp;rsquo;ll first review two concepts: sentiment analysis and hash tables.&lt;/p&gt;

&lt;h2 id=&#34;concept-1-sentiment-analysis&#34;&gt;Concept 1: Sentiment Analysis&lt;/h2&gt;

&lt;p&gt;There are many ways we could make sense of textual data from tweets. One way is to consider whether the emotional state or attitude it expresses is either positive, negative or neutral. This is called sentiment polarity.&lt;/p&gt;

&lt;p&gt;For example this tweet would be considered positive in sentiment:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;So happy exams are over. Finally done with second year! Now can look forward to my holiday :D #summmerrr
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Conversely this tweet would express negative sentiment:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;I hope i do good on my finals tommorow #worried
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But what about this one? Is the person actually happy? Can we be sure?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;i totally failed math finals so that&#39;s good
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Try determining whether the following tweets about Superstorm Sandy are positive, neutral or negative:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;So happy to wake up to #sandy gone!

Everyone Panic!!!1 RT @NBCNews Full moon could make #Sandy&#39;s impact worse http://t.co/hHs5l8EY

#sandy i love you. even if your last names not cheeks*

RT @NewYorkPost: Rainbow touches down in lower Manhattan #hurricane #sandy http://t.co/M6MGqGN7 via @kurtdietrich*

RT @NickpcWx: #Hurricane #Sandy cloud cover is covering nearly 1 million square miles of water/land. @reedtimmerTVN http://t.co/STGZxi2X

RT @GovChristie: I don&#39;t give a damn about Election Day after what has happened here. I am worried about the people of New Jersey. #Sandy*
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How did you determine their sentiment polarity?&lt;/li&gt;
&lt;li&gt;Could you write out a list of steps used to determine this?&lt;/li&gt;
&lt;li&gt;Would others following your steps produce the same results?&lt;/li&gt;
&lt;li&gt;What makes determining sentiment difficult? Why is it relatively easy for humans to classify sentiment but not computers?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;a-simplified-approach-to-determining-sentiment&#34;&gt;A Simplified Approach to Determining Sentiment&lt;/h3&gt;

&lt;p&gt;A simple way to determine sentiment polarity for a tweet would be to determine how many words in the tweet are positive, negative or neutral in sentiment polarity. If there are more positive words than negative words, then the tweet is considered positive. Conversely if we have more negative words than positive words, then the tweet is negative. Otherwise if they are equal, then the tweet is neutral. But how do we determine the sentiment polarity of a word?&lt;/p&gt;

&lt;h3 id=&#34;sentiment-lexicon&#34;&gt;Sentiment Lexicon&lt;/h3&gt;

&lt;p&gt;Determining the sentiment of a word can be accomplished by using a sentiment lexicon. This is a collection of words (or phrases) along with their associated sentiment polarity. For instance a lexicon of positive words could contain the words &amp;ldquo;happy&amp;rdquo; and &amp;ldquo;good&amp;rdquo; whilst a negative word lexicon could contain the words &amp;ldquo;sad&amp;rdquo; and &amp;ldquo;bad&amp;rdquo;. Thus the sentiment of word can be determined by checking if it is in either lexicon.&lt;/p&gt;

&lt;p&gt;Such a sentiment lexicon can be described as an example of &lt;em&gt;labeled data&lt;/em&gt;. This is because the words have been assigned a &amp;ldquo;correct&amp;rdquo; label (sentiment polarity). This is accomplished either by experts manually assigning a &amp;ldquo;correct&amp;rdquo; value or by using machine learning techniques to determine this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are some of the limitations of this approach?&lt;/li&gt;
&lt;li&gt;Is the labelled data &amp;ldquo;correct&amp;rdquo; across different social domains?&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;Compare how are the words &amp;ldquo;bull&amp;rdquo; and &amp;ldquo;bear&amp;rdquo; are used general and in the context of financial markets&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Is the labelled data &amp;ldquo;correct&amp;rdquo; in different contexts?

&lt;ul&gt;
&lt;li&gt;Compare the word &amp;lsquo;low&amp;rsquo; in the context of &amp;ldquo;low cost&amp;rdquo; and &amp;ldquo;low salary&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Has social media made it easier to create or access labeled data?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;steps-for-determining-tweet-sentiment&#34;&gt;Steps for Determining Tweet Sentiment&lt;/h3&gt;

&lt;p&gt;Since we are interested in whether a tweet contains more (or less) positive words than negative words, we can assign positive words a value of 1 and negative words a value of -1. Thus if we sum these values for all words in a tweet, we get a score that tell us whether a tweet is positive, negative or neutral in sentiment. We can describe these steps informally as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;input is tweetText
set sentimentScore to 0
for each word in tweetText
    if positiveWordLexicon contains word then
        add 1 to sentimentScore
    end                  
    if negativeWordLexicon contains word then
        subtract 1 from sentimentScore
    end
end
output is sentimentScore
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Thus a &lt;code&gt;sentimentScore&lt;/code&gt; greater than zero indicates that the tweet is positive. If it is below zero, then the tweet is negative. Otherwise if the score is zero then it has a neutral in sentiment polarity. Note that we ignore neutral words since they won&amp;rsquo;t change the score.&lt;/p&gt;

&lt;p&gt;This description of steps used to determine &lt;code&gt;sentimentScore&lt;/code&gt; from &lt;code&gt;tweetText&lt;/code&gt; is an example of an &lt;em&gt;algorithm&lt;/em&gt;. The informal description is known as &lt;em&gt;pseudo-code&lt;/em&gt;, as it cannot be read by a computer, however to be useful it should loosely relate to a language you&amp;rsquo;re familiar with. We use pseudo-code to focus on how the algorithm works rather than language (Snap!) syntax and rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can you tie back all the pseudo-code to the Snap! blocks you have seen/used?&lt;/li&gt;
&lt;li&gt;How would you determine the words of a tweet?

&lt;ul&gt;
&lt;li&gt;Look back at the example tweets, what would you need to exclude or consider?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;What concerns would you have if the sentiment lexicon contained a very large number of words?&lt;/li&gt;
&lt;li&gt;Suppose that you have a physical copy of all 20 volumes of the Oxford English Dictionary (2nd Edition), which comprises of over 400,000 entries and 22,000 pages.[&lt;a href=&#34;http://www.amazon.com/Oxford-English-Dictionary-Vols-1-20/dp/0198611862/&#34;&gt;4&lt;/a&gt;] How would you quickly look up a definition for a particular word?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;interlude-the-mailbox-problem&#34;&gt;Interlude: The Mailbox Problem&lt;/h2&gt;

&lt;p&gt;Imagine that you are post-office clerk looking for a letter in a pile that has been sorted alphabetically. You&amp;rsquo;d flick to where you&amp;rsquo;d estimate the letter to be, then flick left or right through the letters to get closer to the desired letter (or determine that it is not present). This type of searching is fast, but is there a faster way?&lt;/p&gt;

&lt;p&gt;Instead imagine that you live in a residential hall or college and you are trying to find your mail. There are a number of letter-box, one for &amp;lsquo;A&amp;rsquo;, another for &amp;lsquo;B, another for &amp;lsquo;XYZ&amp;rsquo;, etc. To find mail for a person, you simply take the first letter of the person&amp;rsquo;s last name, go to the respective letter-box and search through the letters to find the person&amp;rsquo;s mail. This scenario roughly describes the idea of a hash table.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/mailbox2.png&#34; alt=&#34;&#39;mailbox image&#39;&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some college kids are pranksters. One has randomly redistributed the mail into the letter-boxs. You face the same problem of finding your letter.

&lt;ul&gt;
&lt;li&gt;What is the maximum number of letters you would have to look through to find your letter?&lt;/li&gt;
&lt;li&gt;What is the least number of letters?&lt;/li&gt;
&lt;li&gt;On average, how many pages would you have to look through to find your letter?&lt;/li&gt;
&lt;li&gt;How many letters would you have to look through to organise all the mail?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;concept-2-hash-tables-not-hashtags&#34;&gt;Concept 2: Hash Tables (not #HashTags)&lt;/h2&gt;

&lt;p&gt;Similar to how a residential college stores a letter associated with a person, a hash table stores a value associated with a key. Hash tables store entries using a &lt;em&gt;hash fuction&lt;/em&gt; for faster look up.&lt;/p&gt;

&lt;h3 id=&#34;hash-functions&#34;&gt;Hash Functions&lt;/h3&gt;

&lt;p&gt;A hash function is simply a function that takes an input value of arbitrary size and outputs a value of fixed sized. For example consider the following hash function which takes an integer k as input (for positive numbers mod is that same as remainder):&lt;/p&gt;

&lt;p&gt;$$hash(k) = k \mod 3$$&lt;br /&gt;
$$hash(1) = 1$$&lt;br /&gt;
$$hash(2) = 2$$&lt;br /&gt;
$$hash(3) = 0$$&lt;br /&gt;
$$hash(23412517) = 1$$&lt;/p&gt;

&lt;p&gt;No matter how large the input integer is, the function will always return a value between 0 and 2 inclusively. This is called a hash value and it is useful because just as a physical residential college has a finite number of mailboxes to put letters in; computers have a finite amount of memory that can be used to store data. Where we store our entries in memory is called a &lt;em&gt;bucket&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Thus if we have &lt;em&gt;n&lt;/em&gt; buckets to store our entries in, our hash function should output a value corresponding to a bucket:&lt;/p&gt;

&lt;p&gt;$$hash(k) = k \mod n$$&lt;/p&gt;

&lt;p&gt;Since we want to associate a key with a value, we hash the key to determine the bucket. We then store the key along with the value in the bucket. This is just like having letters with people&amp;rsquo;s names on them. Otherwise, when we flick through the letters in a mailbox, we wouldn&amp;rsquo;t be able to tell which ones were ours.&lt;/p&gt;

&lt;p&gt;In the mailbox example, we already defined an intuitive hash function. The key/input is a arbitrary person. To find the hash value, you take the first letter of a person&amp;rsquo;s surname. This outputs a fixed character between &amp;lsquo;A&amp;rsquo; and &amp;lsquo;Z&amp;rsquo;. Thus, we have a hash function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why would it be undesirable for a hash function to give a different output value each time it is applied to the same given input?&lt;/li&gt;
&lt;li&gt;What would happen if we have 100 words to store but only 99 buckets to put them in?&lt;/li&gt;
&lt;li&gt;What would happen if we have two different input values that have the same hash value? How would we store them?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;buckets-and-hash-collisions&#34;&gt;Buckets and Hash Collisions&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;hash collision&lt;/em&gt; is when two different input values have the same hash value. Collisions are problematic because we need to somehow store and look up multiple values in the same bucket. One way to handle this is to use an addressing method called &lt;em&gt;separate chaining&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The idea of separate chaining is to treat buckets as a list of entries, where one entry is linked to another in a chain. Thus if we want to look up an entry in a bucket, we would need to go through the chain until we find it or reach the end of the chain. If we want to insert an entry we would need to go through the chain to check if it is already there and if so, we update its value. Otherwise we add the entry to the end of the chain.&lt;/p&gt;

&lt;p&gt;To illustrate this, simply observe the mailbox example. When there is a hash collision, like in the case of &amp;lsquo;Bruce Wagne&amp;rsquo; and &amp;lsquo;Andrew Wrigley&amp;rsquo;, both letters are stored in the same mailbox. If Bruce wanted to find his letter he would have to look through the pile/list of letters in the box. In this case if you wanted to add a letter to a mailbox, you look through the pile to find a letter addressed to the person and put the new letter next to it, otherwise you just put it on top of the pile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are hash collisions avoidable? What would be needed to avoid any collisions?&lt;/li&gt;
&lt;li&gt;Would it be better to have more or less buckets? What would happen if we only have one bucket?&lt;/li&gt;
&lt;li&gt;Why would it be undesirable for our hash function to put more entries into one particular bucket over others?&lt;/li&gt;
&lt;li&gt;Why might a residential college in Australia have a &amp;lsquo;XYZ&amp;rsquo; mailbox rather than a box for &amp;lsquo;X&amp;rsquo;,&amp;lsquo;Y&amp;rsquo; and &amp;lsquo;Z&amp;rsquo;? Would this differ in other countries?&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a name=&#34;practical&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;practical-sentiment-analysis-of-superstorm-sandy&#34;&gt;Practical: Sentiment Analysis of Superstorm Sandy&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Files Needed&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Snap! workspace with the Hashset project file is &lt;strong&gt;&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab6-hashr.xml&#34;&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The Snap! workspace Sandy Tweet Visualiser project file is &lt;strong&gt;&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab6-visualiser.xml&#34;&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To demonstrate both of these concepts, we&amp;rsquo;ll use Snap! to analyse the sentiment of tweets about Superstorm Sandy from the United State of America and visualise their polarity on a map.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/screenshot.png&#34; alt=&#34;Screenshot of visualisation&#34; /&gt;&lt;/p&gt;

&lt;p&gt;To do this we&amp;rsquo;ll need to use a sentiment lexicon of positive and negative words and store them in a hash table for fast look up.&lt;/p&gt;

&lt;p&gt;But since our sentiment analysis does not take into account different degrees of positive or negative polarity (i.e. +0.5 or -0.6), it isn&amp;rsquo;t necessary to store both a word and its sentiment polarity value. Instead if we store all positive words in one hash table, and all negative words in another, then we only need to store the word itself since we will know the polarity (positive or negative) of all words we look up in that particular hash table. This is the idea of a &lt;em&gt;Set&lt;/em&gt;, which is simply a collection of distinct elements.&lt;/p&gt;

&lt;p&gt;Here&amp;rsquo;s an example of a set of positive words and negative words:&lt;/p&gt;

&lt;div&gt;
$$S_{positive} = \left\{ \text{happy, love, relief} \right\}\\
S_{negative} = \left\{ \text{angry, damage, afraid} \right\}$$
&lt;/div&gt;

&lt;p&gt;Note that there can be no duplicate elements in a set and that the size of the two example sets is 3.This size of a set is often referred to as it&amp;rsquo;s &lt;em&gt;cardinality&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Since we are using hash tables to implement a set, we call this a &lt;em&gt;hash set&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;ex61&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;implementing-a-hash-function&#34;&gt;Implementing a Hash Function&lt;/h3&gt;

&lt;p&gt;As you&amp;rsquo;ve read, a hash set (or hash table) depends on a hash function for all its operations. However hash collisions are bound to happen and handling these collisions adversely affects the performance of our operations. Consider the example where our hash set uses a hash function that puts all words into the same bucket. To look up or remove a word we would need to possibly go through all the words we have inserted because the bucket contains a chain that is as long as the number of words we have inserted. This is akin to you looking for your letter, when the letters have been randomly placed in boxes.&lt;/p&gt;

&lt;p&gt;On the other extreme end, if we have at least as many buckets as we have words, then a hash function that allocates a word to its own bucket would perform extremely fast since the chain is as small as possible since there are no collisions!. Such a hash function is called a &lt;em&gt;perfect hash function&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;However for most practical purposes, hash collisions are unavoidable. Instead the goal is to create a hashing function that is as &lt;em&gt;uniform&lt;/em&gt; as possible. This means that our hash function should roughly distribute the same number of words into each bucket. Thus if we have &lt;em&gt;m&lt;/em&gt; words and &lt;em&gt;n&lt;/em&gt; buckets, we would expect each bucket to contain &lt;em&gt;m/n&lt;/em&gt; buckets.&lt;/p&gt;

&lt;p&gt;Since the input of our hash function is a word, we need to devise a method (or algorithm) of turning that word into some number. Ideally this number should be determined by using all the characters in a word. We call this a &lt;em&gt;hashing scheme&lt;/em&gt; and it is simply a function that takes a word as input and outputs a number.&lt;/p&gt;

&lt;p&gt;Once we define a suitable hashing scheme our hash set will use it to define its hash function as shown below:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/set_hash_function.png&#34; alt=&#34;Snap block setting hash function&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Notice that &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hash_function.png&#34; alt=&#34;`hash function`&#34; /&gt; uses another function &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hashing_scheme.png&#34; alt=&#34;`hashing scheme`&#34; /&gt; to transform the element (in our case a word) into a number so it can perform modulo on it using &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/mod.png&#34; alt=&#34;`modulo`&#34; /&gt; in order to allocate it to a bucket. The addition of 1 is because modulo can return 0 but Snap! counts positions from 1 (indexing begins at 1).&lt;/p&gt;

&lt;p&gt;Thus the ability of a hash function to distribute elements uniformly across the buckets depends on devising a &amp;lsquo;good&amp;rsquo; hashing scheme.&lt;/p&gt;

&lt;h4 id=&#34;exercise-6-1-implement-a-hashing-scheme-3-points&#34;&gt;Exercise 6.1: Implement a hashing scheme (3 points)&lt;/h4&gt;

&lt;p&gt;To illustrate a bad hashing scheme, we&amp;rsquo;ve implemented a very simple one &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/example_word_hashing_scheme.png&#34; alt=&#34;`example word hashing scheme`&#34; /&gt; that simply uses the first letter of a word. This is bad because it means that all words starting with the same letter would go to the same bucket resulting in a lot of collisions. The goal for this task is to try to come up with a better hashing scheme that results in a hash function that is uniform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming Instructions:&lt;/strong&gt;&lt;br /&gt;
Complete this task by editing &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hash_scheme_block.png&#34; alt=&#34;`hash scheme block`&#34; /&gt; and completing the definition:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hash_scheme_block_definition.png&#34; alt=&#34;`hash scheme block definition`&#34; /&gt;.&lt;/p&gt;

&lt;p&gt;Your code is expected to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/unicode.png&#34; alt=&#34;`unicode`&#34; /&gt; block to transform a letter of a word into a number so we can perform calculations on it. &lt;a href=&#34;http://unicode-table.com/en/&#34;&gt;This table&lt;/a&gt; outlines the mapping between any character to numbers &amp;ndash; it contains not only English (or called ascii) characters, but also alphabets from any written language in the world.&lt;/li&gt;
&lt;li&gt;Using all the letters of a word would help to avoid collisions.&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Using both the letter and their position in the word will help distinguish words that are anargrams of each other, e.g. &lt;em&gt;dog&lt;/em&gt; or &lt;em&gt;god&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Use an appropriate hashing scheme so that your hash set on a modest list of English words is as uniform as possible (i.e. passes the &lt;em&gt;uniformity test&lt;/em&gt; block after finishing the hash set implementation.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;: Prime numbers are useful for preventing collisions. See the 3rd answer answer on &lt;a href=&#34;http://stackoverflow.com/questions/299304/why-does-javas-hashcode-in-string-use-31-as-a-multiplier&#34;&gt;this page&lt;/a&gt; reports an observation of a collision test on 50,000 English words.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Test this block:&lt;/strong&gt; After finishing your implementation, type a few different words in the input slot. Do you get a (large) integer from each that are different?&lt;/p&gt;

&lt;!--[//]: # (Add screenshots of relevant Snap! function stub)--&gt;

&lt;p&gt;&lt;a name=&#34;ex62&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;implementing-a-hash-set&#34;&gt;Implementing a Hash Set&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;hash set&lt;/em&gt; is a specialised version of a hash table. A hash table stores both a key and a value using a hash function. In our mailbox analogy, a person was the key and their associated letters was the value. However for hash sets we only store the key. Thus if we don&amp;rsquo;t need to store a value associated with a key, it is more efficient to use a hash set. Whilst both use hash functions to also look up a key, the difference is that a hash table returns the value associated with a key, where as a hash set simply tells you if it contains or doesn&amp;rsquo;t contain the key.&lt;/p&gt;

&lt;p&gt;A hash set and a hash table are both examples of what is called a &lt;em&gt;data structure&lt;/em&gt;. A data structure is simply a particular way of storing and organising data so that we can perform certain operations on it in a efficient manner. For example, a list is also a data structure. In this case, hash functions are used to store and organise the data for fast look up.&lt;/p&gt;

&lt;p&gt;For the purposes of this practical we only need to implement two operations: one that &lt;code&gt;insert&lt;/code&gt; words into the hash set and another that checks if the hash set &lt;code&gt;contains&lt;/code&gt; a particular word.&lt;/p&gt;

&lt;h4 id=&#34;exercise-6-2-implement-the-insert-operation-3-points&#34;&gt;Exercise 6.2: Implement the insert operation (3 points)&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;insert&lt;/code&gt; operation allows you add additional elements to the set. For our use case, this will be to add additional words into the set.&lt;/p&gt;

&lt;p&gt;To insert an element into the set using separate chaining, we&amp;rsquo;ll need to first create a hash value in order to determine the bucket we will insert it into. Then we&amp;rsquo;ll need to check if the bucket is empty; if so we can simply add the element, otherwise we&amp;rsquo;ll need to add it alongside the other elements already in the bucket. But since sets do not contain duplicates, we should only add the element if the bucket doesn&amp;rsquo;t already contain that element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming Instructions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Completing the definition for &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/insert_function.png&#34; alt=&#34;`insert function`&#34; /&gt; by filling in the stub with working code:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/set_insert_function.png&#34; alt=&#34;`set_insert_function`&#34; /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is a special constant value called &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/empty_bucket_sentinel.png&#34; alt=&#34;`empty bucket sentinel`&#34; /&gt;, which is set as a global variable. Use this to check if a bucket is empty.&lt;/li&gt;
&lt;li&gt;Buckets need to be able to hold multiple elements (due to hash collisions). What Snap! block can we use to hold multiple elements?&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A set cannot contain duplicates of an element. Check that an element is not already in the set before you actually insert it.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Inside a hash set there is a variable called &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/entry_count.png&#34; alt=&#34;`entry count`&#34; /&gt; that keeps track of the number of elements entered into the set. Be sure to increment this by one every time you insert an element.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;At the end of the &amp;lsquo;insert&amp;rsquo; we report the block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/report_list_hash_set.png&#34; alt=&#34;`report list hash set`&#34; /&gt;. It is essentially because this representation of the hash set is implemented using lists. You don&amp;rsquo;t strictly need to know why this is, for your function to work. If that didn&amp;rsquo;t make sense, then don&amp;rsquo;t worry about it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Testing this function:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This group of blocks can be used to visualise the hash set buckets. Use it to test your &lt;code&gt;insert&lt;/code&gt; and &lt;code&gt;remove&lt;/code&gt; functions.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/peek_buckets.png&#34; alt=&#34;`peek_buckets`&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;ex63&#34;&gt;&lt;/a&gt;
&lt;p /&gt;&lt;/p&gt;

&lt;h4 id=&#34;exercise-6-3-implement-the-contains-operation-2-points&#34;&gt;Exercise 6.3: Implement the contains operation (2 points)&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;contains&lt;/code&gt; operation is used to check if a element is a member of a set. We will use it to check if a word is in the positive lexicon or the negative lexicon.&lt;/p&gt;

&lt;p&gt;To check if a word is in a hash set, again we must determine which bucket it belongs to using &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hash_function.png&#34; alt=&#34;&#39;hash function&#39;&#34; /&gt;. Once we have determined which bucket to check, we need to check if our word is contained in that bucket. If we find it then we report &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/true.png&#34; alt=&#34;&#39;true&#39;&#34; /&gt;, otherwise we report &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/false.png&#34; alt=&#34;&#39;false&#39;&#34; /&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Snap Instructions:&lt;/strong&gt;&lt;br /&gt;
Complete this task by completing the definition for &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/contains_block.png&#34; alt=&#34;`contains block`&#34; /&gt; by filling in the stub with working code:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/contains_function.png&#34; alt=&#34;`contains function`&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If the bucket is empty then it clearly cannot contain the element. How can we check this?&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;This lab included a utility block in the &amp;lsquo;variables&amp;rsquo; group, called &lt;em&gt;foreach&lt;/em&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/foreach.png&#34; alt=&#34;`foreach`&#34; /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Testing this function:&lt;/strong&gt; You can test that your &lt;code&gt;contains&lt;/code&gt; function is working by using the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/global_hashset_contains.png&#34; alt=&#34;&#39;global hashset contains&#39;&#34; /&gt; on your customised hashset, like when testing &lt;code&gt;insert&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&#34;testing&#34;&gt;Testing&lt;/h3&gt;

&lt;p&gt;We have provided a number of test blocks, sometimes called a test harness in Software Engineering, to ensure your blocks (code) works.&lt;/p&gt;

&lt;p&gt;To use them to test your blocks, simply provide the test harness with a hash set that has a provided hash scheme as shown below:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/test_insert.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/test_contains.png&#34; alt=&#34;&#34; /&gt;&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/test_uniformity.png&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;

&lt;p&gt;For the uniformity test, you need to provide the block with a set of words. You can use any of the word sets provided. Notice that each word set will produce a different histogram. You can use this histogram to evaluate how uniform your hash function is. If buckets have a roughly equal number of elements, then your hashing scheme is uniform.&lt;/p&gt;

&lt;p&gt;The hash scheme can be &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/example_word_hashing_scheme.png&#34; alt=&#34;`example word hashing scheme`&#34; /&gt;, &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hash_scheme_block.png&#34; alt=&#34;`hash scheme block`&#34; /&gt; or any other suitable block. Make sure that it is put in the correct place.&lt;/p&gt;

&lt;p&gt;Run the test by clicking on the block. It will then then tell you whether it passed or why it failed.&lt;/p&gt;

&lt;p&gt;Your implementation should pass all three tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does testing ensure that your code is completely correct?&lt;/li&gt;
&lt;li&gt;Why do different word sets produce different histograms?&lt;/li&gt;
&lt;li&gt;How does changing the hashing scheme affect the histogram produced?&lt;/li&gt;
&lt;li&gt;Why might Dr Seuss, Rhyme and Alliteration cause particularly bad results for the example hashing scheme (remember how the example hashing scheme works)?&lt;/li&gt;
&lt;li&gt;Is it possible to make a set of words which fail the uniformity test, with your hashing scheme?

&lt;ul&gt;
&lt;li&gt;Is this true of any hashing scheme in this scenario?&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Exporting blocks for Exercise 6.1-6.3:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This assignment has two parts and you must submit them separately.
You should export the blocks that you defined in this lab, along with any other custom blocks that are used by those.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;ldquo;word hashing scheme&amp;rdquo;,&lt;/li&gt;
&lt;li&gt;&amp;ldquo;insert __ into __&amp;rdquo;,&lt;/li&gt;
&lt;li&gt;&amp;ldquo;__ contains __&amp;rdquo;,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Test before you submit!&lt;/strong&gt;
Always, test your submission file &amp;ndash; to make sure everything that
should be included is indeed included!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first test for this assignment is included in the test harness above.&lt;/li&gt;
&lt;li&gt;The second test you can run, is via the Superstorm Sandy visualizer below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a name=&#34;sandy&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;sentiment-analysis-and-visualisation-of-superstorm-sandy-tweets-1-point&#34;&gt;Sentiment Analysis and Visualisation of Superstorm Sandy Tweets (1 point)&lt;/h3&gt;

&lt;p&gt;Once you&amp;rsquo;ve finish implementing your hash set and sentiment score you can now use it to analyse the sentiment of tweets about Superstorm Sandy[&lt;a href=&#34;http://www.nhc.noaa.gov/data/tcr/AL182012_Sandy.pdf&#34;&gt;3&lt;/a&gt;]  over time and visualise them on a map of the continental United States of America (excluding Alaska and Hawaii).&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;ex64&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&#34;exercise-6-4-computing-the-sentiment-score-of-a-tweet-1-point&#34;&gt;Exercise 6.4: Computing the sentiment score of a Tweet (1 point)&lt;/h4&gt;

&lt;p&gt;With the hashset implemented, you are ready to compute the sentiment score of a tweet!&lt;/p&gt;

&lt;p&gt;First use your own hash set and hashing scheme implementation to construct the positive and negative word lists, by executing the following blocks. You need to import all of your blocks from the first project to the current project.&lt;/p&gt;

&lt;p&gt;You will need to put your blocks into their respective locations.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/hashset_construction.png&#34; alt=&#34;hashsets&#34; /&gt;&lt;/p&gt;

&lt;p&gt;You then modify the block that computes sentiment score &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/sentiscore.png&#34; alt=&#34;sentiscore&#34; /&gt; to loop over words in the tweet and compute its sentiment score. A screenshot of the function stub for you to fill in the code is shown below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/sentiment_score.png&#34; alt=&#34;sentiment block&#34; /&gt;&lt;/p&gt;

&lt;p&gt;After implementing it, you should run it through a few test cases. Use the few examples from the beginning of the this lab sheet to test out how well your scoring function works.
For example, the block below should return 1 for recognizing the positive sentiment.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/sentiment_test1.png&#34; alt=&#34;sentiment test&#34; /&gt;&lt;/p&gt;

&lt;!--After testing, submit the file with the saved blocks through
[wattle](http://wattlecourses.anu.edu.au/course/view.php?id=12823).
 --&gt;

&lt;p&gt;&lt;strong&gt;Snap Instructions:&lt;/strong&gt;&lt;/p&gt;

&lt;!--1. Firstly export your completed ![`hash set block`][hash_set_block.png] and ![`hash scheme block`][hash_scheme_block.png] blocks along with all other needed blocks to a file (to be safe, export everything).  
--&gt;

&lt;p&gt;This part assumes that you have a saved a copy of the blocks from Exercise 6.1-6.3.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a new version of &lt;a href=&#34;http://artofcomputing.cecs.anu.edu.au/snap/snap.html&#34;&gt;Snap&lt;/a&gt; and import the Sandy Tweet visualiser project file (available &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab6-visualiser.xml&#34;&gt;here&lt;/a&gt;)&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Import your blocks into the project.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;If you&amp;rsquo;ve imported the visualiser for the first time you need to reset the visualiser:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/reset_visualiser.png&#34; alt=&#34;`reset visualiser`&#34; /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Similar to testing, simply drag your implemented hash set along with its hashing scheme into the load lexicon blocks and your &lt;em&gt;insert&lt;/em&gt; function, and run them:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/load_positive.png&#34; alt=&#34;`load positive`&#34; /&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/load_negative.png&#34; alt=&#34;`load negative`&#34; /&gt;&lt;br /&gt;
6. Run the visualiser from your desired starting tweet, where 1 denote the first tweet in the dataset and the 582269 is the last.&lt;br /&gt;
  &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/run_visualiser.png&#34; alt=&#34;`run visualiser`&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Whilst these tweets cover the dates from 15 Oct 2012 to 12 Nov 2012, the bulk of the tweets come from a very specific time period:&lt;br /&gt;
The tweets in our dataset were tweeted from 15 Oct 2012 to 12 Nov 2012, however the majority of tweets come from a very specific time, as shown below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Frquency of Tweets over Time (Hours)&lt;/strong&gt;&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/tweet_graph.png&#34; alt=&#34;`tweet_graph`&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What do you think is the significance of the peaks?&lt;/li&gt;
&lt;li&gt;The peak number of the tweets occurs between tweets numbered 115000 and 275000. Try visualising and comparing their sentiment.&lt;/li&gt;
&lt;li&gt;Does the sentiment of tweets before the peak differ from the sentiment of tweests after the peak?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submitting your sentiment score block:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Export your sentiment computation block and submit it as a separate xml file&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;ldquo;sentiment score (tweet text, positive word set, negative word set)&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Test before you submit!&lt;/strong&gt;
Always, test your submission file &amp;ndash; to make sure everything that
should be included is indeed included!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submitting a screenshot of the visualization:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You let the visualizer run for while, and submit a snap of the Snap! stage when you are satisfied with the result. Capturing part of the screen can be done &lt;a href=&#34;http://www.printscreenmac.com/&#34;&gt;via keyboard shortcut on a mac&lt;/a&gt;, or using the &lt;a href=&#34;http://windows.microsoft.com/en-us/windows/use-snipping-tool-capture-screen-shots#1TC=windows-8&#34;&gt;Snipping tool&lt;/a&gt; on Windows, or the &lt;a href=&#34;http://askubuntu.com/questions/18867/which-tool-to-crop-a-portion-of-the-screen&#34;&gt;Take Screenshot&lt;/a&gt; tool in Ubuntu.&lt;/p&gt;

&lt;p&gt;Here is mine, what does yours look like?&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/screenshot.png&#34; alt=&#34;stage&#34; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&#34;extension-tasks&#34;&gt;Extension Tasks&lt;/h3&gt;

&lt;p&gt;For those that have completed all the previous tasks, here&amp;rsquo;s an opportunity to further your understanding, improve your programming skills as well as to earn bonus marks! These tasks have less guidance and support than the previous ones so you are expected to do your own reading or research if needed. You only need to implement one of the following:&lt;/p&gt;

&lt;h4 id=&#34;extension-task-1-implement-the-remove-operation&#34;&gt;Extension Task 1: Implement the remove operation&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;remove&lt;/code&gt; operation is used to take out elements from the set.In sentiment analysis we can assume all words loaded into our hash sets are correct and thus we didn&amp;rsquo;t need &lt;code&gt;remove&lt;/code&gt;. Our hash set implementation is incomplete without it though.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Snap Instructions:&lt;/strong&gt;&lt;br /&gt;
Complete this task by completing the definition for &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/remove_function.png&#34; alt=&#34;`remove function`&#34; /&gt; by filling in the stub with working code:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/set_remove_function.png&#34; alt=&#34;`set_remove_function`&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;remove&lt;/code&gt; operation is the opposite of the &lt;code&gt;insert&lt;/code&gt; operation. Determine what steps you need to take to remove an element with this in mind. Writing pseudo-code might help.&lt;/li&gt;
&lt;li&gt;You can&amp;rsquo;t remove an element that is not already part of the set.&lt;/li&gt;
&lt;li&gt;Use the provided test harness to check that it works:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/test_remove.png&#34; alt=&#34;`test remove`&#34; /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;extension-task-2-implement-dynamic-resizing-rehashing&#34;&gt;Extension Task 2: Implement dynamic resizing (rehashing)&lt;/h4&gt;

&lt;p&gt;Ideally, the more buckets we have, the less likely we&amp;rsquo;ll have collisions. If we could estimate how many elements we&amp;rsquo;re processing then we can set the number of buckets to at least this estimate. However if we estimate wrong and have too few buckets, then we&amp;rsquo;ll have unneccesary additional collisions.&lt;/p&gt;

&lt;p&gt;Our hash set would be more robust if it could resize itself depending on the load. To do this we will &lt;em&gt;rehash&lt;/em&gt; all elements into a larger number of buckets once the number of elements in our hash set exceed some threshod. This threshold is the &lt;em&gt;load factor&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Take a look inside the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/insert_function.png&#34; alt=&#34;`insert function`&#34; /&gt; and you will notice that before any elements are inserted, there is a condition being checked to determine if the hash set is exceeding the load factor:&lt;br /&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/rehash_condition.png&#34; alt=&#34;`rehash condition`&#34; /&gt;
Unfortunately the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/rehash_function.png&#34; alt=&#34;`rehash function`&#34; /&gt; is not currently doing anything useful.&lt;/p&gt;

&lt;p&gt;Your task is to edit &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/rehash_function.png&#34; alt=&#34;`rehash function`&#34; /&gt; so that it rehashses all the elements into a new larger number of buckets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What variables do you need to reset?&lt;/li&gt;
&lt;li&gt;How many element in the hash set do you need to go through to rehash?&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;extension-task-3-implement-the-dictionary-data-structure-hash-table&#34;&gt;Extension Task 3: Implement the dictionary data structure (hash table)&lt;/h4&gt;

&lt;p&gt;As our approach to sentiment analysis is very simple (words are either positive or negative), we didn&amp;rsquo;t need to the full capabilities of a hash table to create our lexicon. But if the words in our lexicon were associated with a polarity value between -1 and +1, using hash sets would be infeasible since we would need a hash set for word with a polarity of -1, -0.9 -0.85&amp;hellip; all the way to +1.&lt;/p&gt;

&lt;p&gt;In this case we should actually use a hash table (dictionary) to implement our lexicon. Since hash tables store a key and an associated value, we can use it to store a word (key) along with its sentiment polarity (value). We can then look up the sentiment polarity for all words very quickly from a single data structure.&lt;/p&gt;

&lt;p&gt;In Computer Science, this idea of storing a key associated with a value is called a &lt;em&gt;dictionary&lt;/em&gt; data structure and it is useful for a wide variety of applications. One important area of application is &lt;em&gt;indexing&lt;/em&gt; which is used to quickly retrieve information from a query. For example web pages from a search or visualising the usage of certain words or phrases over time using &lt;a href=&#34;https://books.google.com/ngrams&#34;&gt;Google Ngram Viewer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints:&lt;/strong&gt;
* A hash table is very similar to a hash set, the only difference is that we now need to store both a key and it&amp;rsquo;s value. As a start point make a copy of your hash set implementation and try to tweak it, to make it a hash table.
* Keep the concept of a key separate from the value; we only hash the key but we need to store both the key and the value together in a bucket.
* An example of how you could store the key and the value: &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab6/dictionary_hint.png&#34; alt=&#34;`dictionary hint`&#34; /&gt;.&lt;/p&gt;

&lt;h2 id=&#34;references&#34;&gt;References:&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Map Images of United States of America:&lt;/strong&gt;&lt;br /&gt;
Showeet: Hi-Def Editable PowerPoint Map of USA - Free Map (2010), &lt;a href=&#34;http://www.showeet.com/24/03/2010/maps/hi-def-editable-powerpoint-map-of-usa-free-map/&#34;&gt;http://www.showeet.com/24/03/2010/maps/hi-def-editable-powerpoint-map-of-usa-free-map/&lt;/a&gt; (accessed April 2014).&lt;br /&gt;
Used under the &lt;a href=&#34;http://creativecommons.org/licenses/by-nc-sa/3.0/&#34;&gt;Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sentiment Lexicon:&lt;/strong&gt;&lt;br /&gt;
Liu, B.: A list of positive and negative opinion words or sentiment words for English (2004), &lt;a href=&#34;http://www.cs.uic.edu/~liub/FBS/opinion-lexicon-English.rar&#34;&gt;http://www.cs.uic.edu/~liub/FBS/opinion-lexicon-English.rar&lt;/a&gt; (accessed April 2014).&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Takeshi Sakaki, Makoto Okazaki, and Yutaka Matsuo. 2010. Earthquake shakes Twitter users: real-time event detection by social sensors. In Proceedings of the 19th international conference on World wide web (WWW &amp;lsquo;10). (&lt;a href=&#34;http://dl.acm.org/citation.cfm?id=1772777&#34;&gt;abstract&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Bertrand De Longueville, Robin S. Smith, and Gianluca Luraschi. 2009. &amp;ldquo;OMG, from here, I can see the flames!&amp;rdquo;: a use case of mining location based social networks to acquire spatio-temporal data on forest fires. In Proceedings of the 2009 International Workshop on Location Based Social Networks (LBSN &amp;lsquo;09). (&lt;a href=&#34;http://dl.acm.org/citation.cfm?id=1629907&#34;&gt;abstract&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Lab 6: Sequence alignment (with pointers)</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/bioinfo/</link>
      <pubDate>Tue, 21 Mar 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/bioinfo/</guid>
      <description>

&lt;p&gt;This weeks lab is a practical test of algorithms based on
&amp;ldquo;dynamic programming&amp;rdquo;, applied to one of the fundamental
problems in bioinformatics.&lt;/p&gt;

&lt;h3 id=&#34;determining-similarity&#34;&gt;Determining Similarity&lt;/h3&gt;

&lt;p&gt;One of the central problems pursued in bioinformatics is determining
similarity between sequences of nucleotides or amino acids (the basic
information that makes up our genetic structure). Similarity
information is required to perform some typical tasks including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using a given sequence of amino acids to infer a protein&amp;rsquo;s shape
and function, and&lt;/li&gt;
&lt;li&gt;Finding all the genes and proteins in a given genome.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Usually, when given a particular sequence, you would search through
one of the publicly availiable databases (visit, for example, the
&lt;a href=&#34;http://www.ncbi.nlm.nih.gov/&#34;&gt;NCBI database&lt;/a&gt; for more information)
and find multiple sequences that have varying degrees of similarity
to the sequence in question. It is then up to the researcher to select
the ones of most interest. In this lab we will focus on the underlying
problem of determining similarity between two nucleotide sequences.&lt;/p&gt;

&lt;h3 id=&#34;exercise-5-1-70&#34;&gt;Exercise 5.1 (70%)&lt;/h3&gt;

&lt;p&gt;For this assignment you will write a program in Snap! which finds the
optimal global alignment between two sequences of nucleotides.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Snap link:&lt;/strong&gt; A project file with the framework for the assignment
is available &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/bioinfo.xml&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;the-global-alignment-needleman-wunsch-http-en-wikipedia-org-wiki-needleman-e2-80-93wunsch-algorithm-algorithm&#34;&gt;The Global Alignment (&lt;a href=&#34;http://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm&#34;&gt;Needleman-Wunsch&lt;/a&gt;) Algorithm&lt;/h3&gt;

&lt;p&gt;As described in the lectures, the global alignment algorithm is a
dynamic programming algorithm. Given two sequences, at any point in
the alignment we have three choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Align the two nucleotides&lt;/li&gt;
&lt;li&gt;Introduce a gap in the first sequence&lt;/li&gt;
&lt;li&gt;Introduce a gap in the second sequence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/three_choices.png&#34; alt=&#34;The three alignment options&#34; /&gt;&lt;/p&gt;

&lt;p&gt;So as we align our sequence, at each point the optimal alignment is
given by the optimal alignment up to that point, plus whichever of the
above choices gives us the greatest alignment score.&lt;/p&gt;

&lt;p&gt;To achieve this we will construct a score matrix &lt;code&gt;$F$&lt;/code&gt; with the number
of rows equal to the length of the first sequence plus one and the number
of columns equal to the length of the second sequence plus one. Each
element in this matrix represents the score of the optimal alignment
up to that point in each sequence. To fill in the matrix we start at
the top left element (inititalised to 0) and move left-right,
top-bottom. At each element &lt;code&gt;$F(i,j)$&lt;/code&gt;, the elements above (&lt;code&gt;$F(i-1,j)$&lt;/code&gt;),
to the top-left (&lt;code&gt;$F(i-1,j-1)$&lt;/code&gt;) and to the left (&lt;code&gt;$F(i,j-1)$&lt;/code&gt;) represent
the decision to introduce a gap in the second sequence, align the two
nucleotides, or introduce a gap in the first sequence respectively. So
to fill in in the element &lt;code&gt;$F(i,j)$&lt;/code&gt; we use the formula&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/score_function.png&#34; alt=&#34;Score function&#34; /&gt;&lt;/p&gt;

&lt;p&gt;where &lt;code&gt;$d$&lt;/code&gt; is the penalty for introducing a gap and &lt;code&gt;$s(x,y)$&lt;/code&gt; is the
score for aligning the two nucleotides.&lt;/p&gt;

&lt;p&gt;This is illustrated in the following figure&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/score_matrix_function.png&#34; alt=&#34;How to compute a value in the score matrix&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Each element &lt;code&gt;$F(i,j)$&lt;/code&gt; must not only store the score of the optimal
alignment, but it must also store a pointer to the cell that it obtained
the optimal value from, allowing you to trace the path that corresponds
to the optimal alignment when the matrix is completed.
Thus, if the finished score matrix is the following&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/score_matrix_finished.png&#34; alt=&#34;A completed score matrix&#34; /&gt;&lt;/p&gt;

&lt;p&gt;the corresponding optimal alignment is&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/the_optimal_alignment.png&#34; alt=&#34;Optimal alignment&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The optimal alignment is found by starting at the bottom right element
in the matrix, and tracing back the steps taken to get there. This is
done by following the pointers (arrows) stored at each element.
Depending on the direction of the arrow do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrow points up: Add the nucleotide for sequence 1 and a gap for
sequence 2.&lt;/li&gt;
&lt;li&gt;Arrow points diagonally: Add the nucleotide from both sequence 1
and sequence 2.&lt;/li&gt;
&lt;li&gt;Arrow points left: Add a gap for sequence 1 and the nucleotide for
sequence 2.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try to reconstruct the aligned sequences above by following the
arrows in the completed score matrix.&lt;/p&gt;

&lt;h4 id=&#34;implement-the-global-alignment-algorithm&#34;&gt;Implement the global alignment algorithm&lt;/h4&gt;

&lt;p&gt;The lab project provides a block which creates the score matrix and
handles the visualisation. To initialise a new matrix, select (or type
in) two sequences you wish to align and run the following blocks&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/initialise_blocks.png&#34; alt=&#34;initialise blocks&#34; /&gt;&lt;/p&gt;

&lt;p&gt;You should see the outline of the score matrix appear on the stage.
Your task is to implement the global alignment algorithm, described
above. Place your solution in the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/solution_block.png&#34; alt=&#34;solution&#34; /&gt; block.
A basic stub of the block is provided to illustrate how to use the
helper functions.&lt;/p&gt;

&lt;p&gt;The three inputs to the solution block are the values to use for
&lt;code&gt;$s(x,y)$&lt;/code&gt; and &lt;code&gt;$d$&lt;/code&gt; in the algorithm:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first input (&lt;em&gt;good alignment score&lt;/em&gt;) is the score for aligning
two equal nucleotides, i.e., &lt;code&gt;$s(x,y)$&lt;/code&gt; when &lt;code&gt;$x = y$&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The second input (&lt;em&gt;misalignment penalty&lt;/em&gt;) is the penalty for aligning
two unequal nucleotides, i.e., &lt;code&gt;$-s(x,y)$&lt;/code&gt; when &lt;code&gt;$x \neq y$&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The third input (&lt;em&gt;gap penalty&lt;/em&gt;) is the penalty for introducing a gap
in either sequence, i.e., &lt;code&gt;$-d$&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you have completed and run your code, you can use the following
blocks to display the optimal alignment corresponding to the computed
score matrix:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/show_global_alignment_block.png&#34; alt=&#34;show global alignment&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hints&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can use the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/set_value_block.png&#34; alt=&#34;set element&#34; /&gt; block
to set an element of the score matrix to a particular value. Note that
when you do this, the pointer for that element is automatically set
to &lt;em&gt;null&lt;/em&gt; (a value indicating no arrow). It will also update the matrix
shown on the stage.&lt;/li&gt;
&lt;li&gt;To set the pointer for an element in the score matrix you can use
the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/set_pointer_block.png&#34; alt=&#34;set pointer&#34; /&gt; block.
You should set the pointer to a list which contains the indices of
the cell you are pointing to in the score matrix. The pointer (if
set correctly) will also show up as an arrow between the entries in
the matrix shown on the stage.&lt;/li&gt;
&lt;li&gt;Remember to check the edges of the matrix: If &lt;code&gt;$i = 1$&lt;/code&gt;, there is no
row at &lt;code&gt;$i - 1$&lt;/code&gt;, and likewise when &lt;code&gt;$j = 1$&lt;/code&gt;, there is no column at
&lt;code&gt;$j - 1$&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You can use local variables, say &amp;ldquo;Max Score&amp;rdquo; and &amp;ldquo;Max Score Pointer&amp;rdquo;,
to keep track of the best choice as you evaluate each one in turn.
Calculate the score for each of the choices (skipping the ones that do
not apply) and update both variables when you find a new best score.
Don&amp;rsquo;t forget that you must initialise &amp;ldquo;Max Score&amp;rdquo; to a value that is
lower than the score for any of the choices can be.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The lab project comes with some sample sequences to test your block
on, four of length 7 and two shorter of length 5.
The example score matrix above is for aligning two of them, GAATTCA
and GGATCGA, with default scores. The optimal alignment has one
mismatch (in the second position) and one gap in each sequence.&lt;/p&gt;

&lt;p&gt;Try comparing all sequences of the same length pair-wise.&lt;/p&gt;

&lt;p&gt;You should also try varying the scores. If you keep the gap penalty
at 1 and increase the misalignment penalty to any value greater than
2, you should get alignments that have no mismatches (because a
mismatch can always be avoided by introducing two gaps). Verify that
your implementation does this! On the other hand, if you increase the
gap penalty while keeping the misalignment penalty at 1 you should see
fewer and fewer gaps.&lt;/p&gt;

&lt;h3 id=&#34;exercise-5-2-30&#34;&gt;Exercise 5.2 (30%)&lt;/h3&gt;

&lt;p&gt;The block you have implemented so far computes the best alignment
between two complete sequences. Sometimes, however, the objective is
to find similar &lt;em&gt;subsequences&lt;/em&gt; in two given sequences.
Fortunately, only a few small modifications are needed to compute
an optimal &lt;em&gt;local alignment&lt;/em&gt;. (This is known as the
&lt;a href=&#34;http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm&#34;&gt;Smith-Waterman algoritm&lt;/a&gt;.)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For local alignment, the maximum score function is given by&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/local_score_function.png&#34; alt=&#34;The local alignment scoring function&#34; /&gt;&lt;/p&gt;

&lt;p&gt;In other words, an alignment between two subsequences with a
negative score is never optimal, because in that case a better
alignment can be made between shorter subsequences.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;When the score matrix is completed and we wish to find an optimal
local alignment, we need to start tracing back from the &lt;em&gt;largest&lt;/em&gt;
score in the matrix (instead of the bottom right corner) and trace
back until we reach a score of 0 which is where we stop.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your task is to implement the local alignment algorithm, in the block
called
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/solution_local_block.png&#34; alt=&#34;&amp;quot;Solution for Local Alignment&amp;quot;&#34; /&gt;.
(Remember that you can use the &amp;ldquo;duplicate&amp;rdquo; function to copy your earlier
implementation so that you don&amp;rsquo;t have to rebuild it from scratch.)
To find and display the optimal local alignment after you have computed
the matrix, use the following blocks:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/bioinfo/show_local_alignment_block.png&#34; alt=&#34;&amp;quot;find optimal local alignment in (score matrix)&amp;quot;&#34; /&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can use the same test cases as for the global alignment.
However, local alignment is more sensitive to the score given to
a good aligment (match): The higher it is, relative the the
misalignment and gap penalties, the more willing we are to
accept a worse alignment of longer subsequences. As an example,
aligning the sequences GCATGCT and GGATCGA with good alignment
scores of 2 and 1, keeping both penalties at 1, gives subsequences
of different lengths.&lt;/p&gt;

&lt;h2 id=&#34;assignment-submission&#34;&gt;Assignment submission&lt;/h2&gt;

&lt;p&gt;To submit your assignment, you must export blocks (as described on
&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/lab/lab1/&#34;&gt;the lab 1 page&lt;/a&gt;.
You should export the blocks that you defined in this lab
(&amp;ldquo;Solution&amp;rdquo;, &amp;ldquo;Solution for Local Alignment&amp;rdquo; and
&amp;ldquo;Show optimal local alignment&amp;rdquo;), along with any other custom you
created that are used by those.&lt;/p&gt;

&lt;p&gt;Submit the file with the saved blocks through wattle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test before you submit!&lt;/strong&gt;
Always, test your submission file &amp;ndash; to make sure everything that
should be included is indeed included!&lt;/p&gt;

&lt;p&gt;To do so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start a fresh chrome/chronium session/&lt;/li&gt;
&lt;li&gt;Load the &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab5.xml&#34;&gt;Lab 5 Snap project&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Use the &amp;ldquo;import &amp;hellip; &amp;rdquo; function from Snap to load your submission
file, containing your exported blocks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now run these blocks &amp;ndash; does you solution still work?&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Lab 5: Solving Sudoku</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/sudoku/</link>
      <pubDate>Wed, 15 Mar 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/sudoku/</guid>
      <description>

&lt;p&gt;In this lab, we explore how reasoning, and figuring things out by
trial-and-error, can be coded as an algorithm, and use it to solve
Sudoku puzzles.&lt;/p&gt;

&lt;h3 id=&#34;sudoku-the-search-for-a-solution&#34;&gt;Sudoku: The search for a solution&lt;/h3&gt;

&lt;p&gt;The most well known form of a sudoku puzzle is a 9-by-9 grid in which
the numbers 1-9 must be placed such that each row, column and 3-by-3
box contains exactly one of each of the 9 digits. A typical puzzle
will initially have enough of the numbers filled in to ensure that the
puzzle has exactly one solution.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/sudoku_nine.png&#34; alt=&#34;9-by-9 Sudoku Puzzle&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Finding a solution to the puzzle is a &lt;em&gt;constraint satisfaction
problem&lt;/em&gt;, just like the n-queens problem described in the lecture.
(This differs from the constrained optimisation problems also talked
about in the lectures only in that there is no objective function:
Any way of satisfying the constraints is equally good.)&lt;/p&gt;

&lt;p&gt;To find the solution we must search through the state space (all
possible sets of 81 numbers that satisfy the constraints, i.e. all
valid sudoku puzzles), trying different options until we find one that
works. One possible (but certainly not ideal) way to approach this
problem is to search through the &lt;strong&gt;entire&lt;/strong&gt; state space until you find
one that matches the puzzle you have been given. Considering that the
total number of valid sudoku puzzles is
&lt;a href=&#34;http://en.wikipedia.org/wiki/Mathematics_of_Sudoku&#34;&gt;6,670,903,752,021,072,936,960&lt;/a&gt;,
you would hope that there was a better way to go about it.&lt;/p&gt;

&lt;p&gt;Indeed, as you have seen in the lectures we can use certain search
algorithms to narrow the state space considerably as we work towards
finding the solution. In this assignment you will implement one (or
two) of these search algorithms to create your very own sudoku solver.&lt;/p&gt;

&lt;h3 id=&#34;exercise-7-1-60&#34;&gt;Exercise 7.1 (60%)&lt;/h3&gt;

&lt;p&gt;Implement the backtracking (depth-first search) algorithm with forward
checking to solve 4-by-4 sudoku puzzles. (The rules for 4-by-4 sudokus
are the same for 9-by-9&amp;rsquo;s as described above, but you will only use
the digits 1-4 and the box constraint applies to the four 2-by-2 boxes.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/sudoku_four.png&#34; alt=&#34;4-by-4 Sudoku Puzzle&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Snap link:&lt;/strong&gt; A project file with the framework for the assignment
is available &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/sudoku.xml&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You must implement the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/solve_block.png&#34; alt=&#34;Solve (sudoku)&#34; /&gt; block.&lt;/p&gt;

&lt;p&gt;To run your solver, select a sudoku using the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/set_sudoku.png&#34; alt=&#34;set sudoku&#34; /&gt; block.
Then run your Solve block, sit back and watch it solve the sudoku.
To check that your finished sudoku is correct (satisfies all the
constraints) you can run the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/check_sudoku.png&#34; alt=&#34;Check (sudoku)&#34; /&gt;
block.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Note that your sudoku block &lt;em&gt;must&lt;/em&gt; return a value, to indicate whether it is successful or not in reaching a valid solution that fills the board.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A number of helpful blocks are provided:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/set_element.png&#34; alt=&#34;set element&#34; /&gt;: This block sets the element
at (row) (column) of (sudoku) to the given (value). It also updates what
is shown on the stage. If the cell already had a value, it will be
replaced.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/get_element.png&#34; alt=&#34;get element&#34; /&gt;: This block to reports the
current value of the element at (row) (column) of (sudoku). If the
element is not set, the block reports the same value as the &amp;ldquo;Null&amp;rdquo;
block.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/clear_element.png&#34; alt=&#34;clear element&#34; /&gt;: This block clears
(removes) the element at (row) (column) in (sudoku), and also updates
the drawing on the stage.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/check_element.png&#34; alt=&#34;check element&#34; /&gt;: This block implements
forward checking. It will check if setting the element at (row) (column)
ti the given value in the current partially filled-in sudoku violates
any constraints.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/find_element.png&#34; alt=&#34;find empty element&#34; /&gt;: This block reports
whether there is any unset element in the sudoku. It returns a list,
whose first element is
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/constant-true-block.png&#34; alt=&#34;&amp;lt;true&amp;gt;&#34; /&gt; or
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/constant-false-block.png&#34; alt=&#34;&amp;lt;false&amp;gt;&#34; /&gt;.
If the first element is true, then the next two are the row and column
of one of the empty elements in the sudoku.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;extension-to-exercise-7-1&#34;&gt;Extension to Exercise 7.1:&lt;/h3&gt;

&lt;p&gt;Each time that the algorithm commits to a choice (assignment of a value
to a cell in the sudoku puzzle), this choice is has been been vetted by
the forward checking procedure. But forward checking is not complete,
and therefore sometimes gets it wrong: When this happens, the search
algorithm will eventually have to undo this bad choice, and try another
option. When this kind of &amp;ldquo;mistake&amp;rdquo; is discovered, we call it a &lt;em&gt;backtrack&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Add to you implementation a variable that counts how many backtracks are
made while solving each puzzle. (Hint: It is probably easiest to do this
with a global variable. If you use a global variable, please name it
&lt;strong&gt;backtracks&lt;/strong&gt;, so that we know how to make your exported blocks work.
Also, don&amp;rsquo;t forget to reset it to zero before you start a new search.)
Can you determine which of the example puzzles are the most difficult,
based on the number of backtracks needed to solve them?&lt;/p&gt;

&lt;h3 id=&#34;exercise-7-2-40&#34;&gt;Exercise 7.2 (40%)&lt;/h3&gt;

&lt;p&gt;The amount of search (backtracks) is influenced by, among other things,
the choice of which empty cell is filled in next, and the choice of the
order in which the possible values are tried (such as 1,2,3,4 or 4,3,2,1).
The &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/sudoku/find_element.png&#34; alt=&#34;find empty element&#34; /&gt; block provided simply
returns the first unset element in the sudoku. Is there a smarter
strategy?&lt;/p&gt;

&lt;p&gt;A common rule-of-thumb for variable ordering is to pick the variable
(cell) with the fewest options first. In the extreme case, if a cell
has only value that passes the forward check, then we cannot make a
&amp;ldquo;mistake&amp;rdquo; in choosing this value (if that value doesn&amp;rsquo;t lead to a
solution, it&amp;rsquo;s because of some mistake we had already made earlier).&lt;/p&gt;

&lt;p&gt;Change the &amp;ldquo;find empty element&amp;rdquo; block so that it checks all empty
spaces, and returns (in the same form as before) the one that has
the fewest options (values that pass the forward check). To improve
the efficiency of your solver, you can make this block return the
list of possible values for the chosen empty cell, in addition to
the true/false flag and the coordinates of the cell. This saves your
search from having to call the forward check again on each value.
Remember, though, that it must still return a list containing only
&amp;ldquo;false&amp;rdquo; if there is no empty cell left.&lt;/p&gt;

&lt;h3 id=&#34;extension-to-exercise-7-2&#34;&gt;Extension to Exercise 7.2:&lt;/h3&gt;

&lt;p&gt;Assuming you did the extension to the first exercise, does the modified
variable ordering change the number of backtracks needed to solve the
example puzzles?&lt;/p&gt;

&lt;h2 id=&#34;assignment-submission&#34;&gt;Assignment submission&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Commenting:&lt;/strong&gt; Good programming practice includes providing adequate
and useful comments in your code. Please make sure that you use comments
where it is motivated: that is, where you need to explain what is going
on in your code.&lt;/p&gt;

&lt;p&gt;As important as providing good comments is to not clutter the code with
useless comments. In particular, we sometimes provides hints and
explanations to you as comments in the project files. These comments
do not help us understand (and mark) your code, so they should, in
most cases, not be included in the blocks that you submit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submission:&lt;/strong&gt;
To submit your assignment, you must export blocks (as described on
&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/lab/lab1/&#34;&gt;the lab 1 page&lt;/a&gt;).
For this assignment, you need to export and submit two files: The
first with the &amp;ldquo;Solve&amp;rdquo; block that you created for exercise 7.1,
and the second with &amp;ldquo;Find empty element&amp;rdquo; block, and the &amp;ldquo;Solve&amp;rdquo; block
if you have modified it, for exercise 7.2. (As usual, also export
any other custom blocks you created that are used by those.)&lt;/p&gt;

&lt;p&gt;Submit both files through wattle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Always test before you submit!&lt;/strong&gt; Make sure everything that should
be included is indeed included!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marking:&lt;/strong&gt; There are no marks for the extension tasks.&lt;/p&gt;

&lt;h2 id=&#34;sources&#34;&gt;Sources&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Nine by Nine Sudoku Puzzle:&lt;/strong&gt;
Licensed under the terms of the
&lt;a href=&#34;http://en.wikipedia.org/wiki/GNU_Free_Documentation_License&#34;&gt;GNU Free Documentation License&lt;/a&gt; version 1.2 or later.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;http://en.wikipedia.org/wiki/File:Oceans_Sudoku17_Puzzle-39451.svg&#34;&gt;http://en.wikipedia.org/wiki/File:Oceans_Sudoku17_Puzzle-39451.svg&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Lab 4: Recursion</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/lab4/</link>
      <pubDate>Thu, 02 Mar 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/lab4/</guid>
      <description>&lt;p&gt;This week we will practice recursion &amp;ndash; with Karel, and with a
special-purpose calculator.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;This is the farmer sowing the corn, that kept the cock that
crowed in the morn, that waked the priest all shaven and
shorn, that married the man all tattered and torn, that kissed
the maiden all forlorn, that milked the cow with the crumpled
horn, that tossed the dog, that worried the cat, that killed
the rat, that ate the malt that lay in the house that Jack
built.

Children&#39;s song &amp;quot;The House that Jack Built&amp;quot;, from 
http://www.ling.upenn.edu/~dringe/CorpStuff/Thesis/IntroSyntax.html#detour
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href=&#34;http://en.wikipedia.org/wiki/Recursion&#34;&gt;Recursion&lt;/a&gt; is a phenomena,
that exist not only in mathematics, but also in linguistics and
physics, arts &amp;hellip;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Snap link&lt;/strong&gt;: the URL to open Snap! with the environment for this
week already loaded is &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab4.xml&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marking rubric&lt;/strong&gt;: Getting either one of the two questions right is
worth 70%, getting the other one right is worth another 30% of this
assignment.&lt;/p&gt;

&lt;h3 id=&#34;exercise-4-1-a-calculator-for-combinations-50&#34;&gt;Exercise 4.1 A calculator for combinations (50%)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are 10 friends wanting to play basketball, how many different
arrangements are there to split them into two teams of 5?&lt;/li&gt;
&lt;li&gt;There are 8 courses to choose from in Semester 2. You want to take one
of them because a good friend is taking it, and need to choose the other
three. How many possible choices do you have for the remaining 3 courses?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More broadly, computing combinations is useful in other scientific
problems, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sampling design in ecology, for example &lt;a href=&#34;https://theoreticalecology.wordpress.com/2014/01/14/sampling-design-combinatorics/&#34;&gt;https://theoreticalecology.wordpress.com/2014/01/14/sampling-design-combinatorics/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Combinatorial chemistry for designing and discovering drugs, as
illustrated in &lt;a href=&#34;https://www.youtube.com/watch?v=MVgsX7PM4F4&#34;&gt;this video&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=/images/lab4/pascal.001.png width=280 align=right&gt;
&lt;strong&gt;Calculation&lt;/strong&gt;:
Here is a standard recipe for counting combinations.
One way to visualize this recipe is to pile such counts as a triangle,
known as
&lt;a href=&#34;http://en.wikipedia.org/wiki/Pascal%27s_triangle&#34;&gt;Pascal&amp;rsquo;s triangle&lt;/a&gt;.
The &lt;code&gt;$k$&lt;/code&gt;-th number in the &lt;code&gt;$n$&lt;/code&gt;-th row is the number of combinations for
choosing &lt;code&gt;$(k)$&lt;/code&gt;-items out of a total of &lt;code&gt;$n$&lt;/code&gt; items. Note that you
should count both &lt;code&gt;$n$&lt;/code&gt; and &lt;code&gt;$k$&lt;/code&gt; from zero, not from &lt;code&gt;$1$&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, the number &lt;code&gt;$1$&lt;/code&gt; circled in green means there is one way
to take &lt;code&gt;$0$&lt;/code&gt; items among &lt;code&gt;$3$&lt;/code&gt; choices, denoted as &lt;code&gt;$C(3,0)$&lt;/code&gt;; the
number &lt;code&gt;$6$&lt;/code&gt; in the blue circle in the figure is the number of taking
&lt;code&gt;$k=2$&lt;/code&gt; items from a collection of &lt;code&gt;$n=4$&lt;/code&gt; items, , denoted as
&lt;code&gt;$C(4,2)$&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This triangle has two prominent properties, which will allow us to
construct the solution to &lt;code&gt;$C(n,k)$&lt;/code&gt; for any number of choices &lt;code&gt;$n$&lt;/code&gt;
and size of selection &lt;code&gt;$k$&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The boundary of this triangle are all &lt;code&gt;$1$&lt;/code&gt;s. Or intuitively, there
is only one way to take &lt;code&gt;$0$&lt;/code&gt; items or all &lt;code&gt;$n$&lt;/code&gt; items from &lt;code&gt;$n$&lt;/code&gt;
choices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img align=right src=http://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A number in the middle of the triangle is the sum of the two number
on its &lt;em&gt;shoulder&lt;/em&gt; rows above. Intuitively, let&amp;rsquo;s say we label the
first one among &lt;code&gt;$n$&lt;/code&gt; items as &amp;ldquo;&lt;em&gt;special&lt;/em&gt;&amp;rdquo;, and the combination
&lt;code&gt;$C(n,k)$&lt;/code&gt; now breaks down into two cases: (A) We include the
&lt;em&gt;special&lt;/em&gt; item in the selection, then the problem becomes taking
&lt;code&gt;$k-1$&lt;/code&gt; items among the remaining &lt;code&gt;$n-1$&lt;/code&gt; choices (i.e. &lt;code&gt;$C(n-1,
k-1)$&lt;/code&gt;). (B) We do not include the &lt;em&gt;special&lt;/em&gt; item in the selection,
then we still need to take &lt;code&gt;$k$&lt;/code&gt; items among the remaining &lt;code&gt;$n-1$&lt;/code&gt;
choices (i.e. &lt;code&gt;$C(n-1, k-1)$&lt;/code&gt;). Adding the results from these two
possibilities will give us the number of combinations gives us
&lt;code&gt;$C(n, k)$&lt;/code&gt;. This insight can be summarized with the following
equation, and by the animation on the right.&lt;/li&gt;
&lt;/ul&gt;

&lt;div&gt;
$$C(n,k) = C(n-1,k-1) + C(n-1,k)$$
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Programming&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;In the Snap workspace you will find this block
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab4/compute_combinations.png&#34; alt=&#34;cc&#34; /&gt;,
its content has been left blank.&lt;/p&gt;

&lt;p&gt;Finish the implementation for
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab4/compute_combinations.png&#34; alt=&#34;cc&#34; /&gt;, with the following
summary of a recursive solution to Pascal&amp;rsquo;s Triangle.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if k=0 OR k=n
	report 1
otherwise
	report compute_combination(n-1, k-1) + compute_combination(n-1, k)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Your code should check for invalid input. i.e. n and k should be integers, otherwise report error and stop; and k should be less or equal than n, otherwise return 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing your block:&lt;/strong&gt;
Here, you should test your block for syntax (i.e. it runs and reports
back a number), but also compare its results against known results of
combinations, such as on the triangle above, and other values of &lt;code&gt;$n$&lt;/code&gt;
and &lt;code&gt;$k$&lt;/code&gt; from online calculator
&lt;a href=&#34;http://stattrek.com/online-calculator/combinations-permutations.aspx&#34;&gt;http://stattrek.com/online-calculator/combinations-permutations.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Showing errors:&lt;/strong&gt;
If you need to output a warning or an error to the user, you can get Karel to say it for you!
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab4/warning-block.png&#34; alt=&#34;warning&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;
Explore more (this part is worth 0 marks):&lt;/p&gt;

&lt;p&gt;This exercise focuses on building a recursive solution for the
combination problem. There are ready-made formulas for computing
combinations, such as listed on this page
&lt;a href=&#34;http://www.mathwords.com/c/combination_formula.htm&#34;&gt;http://www.mathwords.com/c/combination_formula.htm&lt;/a&gt; You can compare the
two solutions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First implement another block for the formula on the webpage
&lt;code&gt;$C(n,k)=\dfrac{n (n-1)\ldots(n-k+1)}{k!}$&lt;/code&gt; using loops.&lt;/li&gt;
&lt;li&gt;Call both blocks with some larger &lt;code&gt;$n$&lt;/code&gt; and &lt;code&gt;$k$&lt;/code&gt;, e.g., &lt;code&gt;$n=10$&lt;/code&gt;
(&lt;code&gt;$15$&lt;/code&gt;, &lt;code&gt;$20$&lt;/code&gt;, &lt;code&gt;$25$&lt;/code&gt;, etc.) and &lt;code&gt;$k=5$&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Which block is faster? Why? Which Solution do you prefer?
&lt;/small&gt;&lt;/p&gt;

&lt;h3 id=&#34;exercise-4-2-karel-as-a-navigator-following-a-trace-and-coming-back-50&#34;&gt;Exercise 4.2 Karel as a navigator: following a trace and coming back (50%)&lt;/h3&gt;

&lt;p&gt;In Exercise 2.1 you told Karel how to follow a trail of beepers. In
Exercise 4.2 Karel will gain navigation skills, by tracing the same
trail backwards and return to where she started, as follows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Karel start from the lower left corner of the grid.&lt;/li&gt;
&lt;li&gt;Karel follows a trail of beepers until the end, picks up the beepers
(at most one at each location) as she goes.&lt;/li&gt;
&lt;li&gt;Karel stacks all the collected beepers at the end of the trail.&lt;/li&gt;
&lt;li&gt;Karel traces back to the origin on the same trail. Furthermore,
she marks her path with a beeper whenever she has made a turn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will find a block
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab4/FollowTrailAndBacktrack.png&#34; alt=&#34;Follow trail and come back&#34; /&gt;
in the motion category, put your implementation there. You should feel
free to change the input of this block as you see fit, or change it to
a reporter if you feel it is useful to return values. Leaving it with
a default input of 0 also works.&lt;/p&gt;

&lt;p&gt;Here are two ways that you can implement this.&lt;/p&gt;

&lt;p&gt;Method 1 &amp;ndash; one step at a time, using recursion&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;Follow trail and come back (beepers to drop = 0)

Find the next beeper in the trail
If it is straight ahead
	go forward one step
	pick up the beeper
	Follow trail and come back (beepers to drop + 1)
	go backward one step

If it is left or right
	turn and go forward one step
	pick up the beeper
	Follow trail and come back (beepers to drop)
	go backward one step
	drop the beeper (to mark the turn)
	turn back

If there is no next beeper
	put down beeper (beepers to drop) times
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Method 2 &amp;ndash; using arrays and reusing &amp;ldquo;Follow a Trail&amp;rdquo; from
&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/lab/lab2&#34;&gt;lab 2&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;Follow a Trail -- but modified to record trail directions in an array

put down beepers at the end (remember to keep enough to mark the turns!)

Follow the recorded trail backwards to the origin, dropping a beeper at each turn
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You are free to use either method to implement the solution.&lt;/p&gt;

&lt;p&gt;Note that a few utility blocks such as &amp;ldquo;Beeper in front?&amp;rdquo; and
&amp;ldquo;Move Karel backward&amp;rdquo; are included. After each attempt, you can use
these set of blocks &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab4/karel_reset.png&#34; alt=&#34;cc&#34; /&gt; to clear
the field and put Karel back to the lower-left corner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing your block&lt;/strong&gt;:
The project file contains three different trails for you to test your
program (as shown below), lay them out using the blocks called &amp;ldquo;Lay
short trail&amp;rdquo; (recommended for debugging), &amp;ldquo;Lay beeper trail&amp;rdquo; and &amp;ldquo;Lay
a long trail&amp;rdquo; &amp;ndash; as shown below.&lt;/p&gt;

&lt;p&gt;&lt;img src=/images/lab4/trail_short.png width=250&gt;
&lt;img src=/images/lab4/trail2.png width=250&gt;
&lt;img src=/images/lab4/trail_long.png width=250&gt;&lt;/p&gt;

&lt;p&gt;After executing your block for the &amp;ldquo;long trail&amp;rdquo; on the right, the stage would look like this:
&lt;img src=/images/lab4/trail_long_result.png width=250&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submission&lt;/strong&gt;:
You need to export and submit the blocks called &amp;ldquo;compute combinations&amp;rdquo;
and &amp;ldquo;Follow trail and come back&amp;rdquo;, along with any other blocks you created that
are used by these blocks.
Follow the &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/submit&#34;&gt;submission instructions&lt;/a&gt; for file naming and block
testing.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;
Image credits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pascal&amp;rsquo;s triangle. Adapted from Wikipedia - User:Conrad.Irwin and originally User:Drini, &lt;a href=&#34;http://en.wikipedia.org/wiki/Pascal%27s_triangle#mediaviewer/File:Pascal%27s_triangle_5.svg&#34;&gt;http://en.wikipedia.org/wiki/Pascal%27s_triangle#mediaviewer/File:Pascal%27s_triangle_5.svg&lt;/a&gt;, &lt;a href=&#34;http://creativecommons.org/licenses/by-sa/3.0&#34;&gt;CC BY-SA 3.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Animation of Pascal&amp;rsquo;s triangle. From wikipedia, by User:Hersfold. Public domain, &lt;a href=&#34;http://en.wikipedia.org/wiki/Pascal%27s_triangle#mediaviewer/File:PascalTriangleAnimated2.gif&#34;&gt;http://en.wikipedia.org/wiki/Pascal%27s_triangle#mediaviewer/File:PascalTriangleAnimated2.gif&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;/small&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Lab 3: Make Your Computer Sing (tunes) and Talk (nonsense)</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/lab3/</link>
      <pubDate>Wed, 01 Feb 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/lab3/</guid>
      <description>&lt;p&gt;This week, Snap will sing and talk! &amp;ndash; all using the notion of lists and arrays learned this week.&lt;/p&gt;

&lt;p&gt;
Note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/submit&#34;&gt;here&lt;/a&gt; for due dates and submission instructions.&lt;/li&gt;
&lt;li&gt;The Snap! project for lab 3 can be accessed &lt;strong&gt;&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab3.xml&#34;&gt;here&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a name=&#34;nonsense&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;exercise-3-1-snap-can-talk-nonsense-10&#34;&gt;Exercise 3.1  Snap can talk &amp;hellip; nonsense (10%)&lt;/h3&gt;

&lt;p&gt;You&amp;rsquo;re now sufficiently warmed up by the singing excercises above on reading and interpreting lists/arrays. Now let&amp;rsquo;s make Snap! talk (or write), and this is achieved by assembling a list from other lists.&lt;/p&gt;

&lt;p&gt;The goal of this task is to get Snap to &amp;ldquo;say&amp;rdquo; some &lt;a href=&#34;http://en.wikipedia.org/wiki/Literary_nonsense&#34;&gt;literary nonsense&lt;/a&gt; that look grammatically correct. One well-known example for this type of literary nonsense is &amp;ldquo;&lt;strong&gt;the cow jumped over the moon&lt;/strong&gt;&amp;rdquo; from the English nursery rhyme &lt;a href=&#34;http://en.wikipedia.org/wiki/Hey_Diddle_Diddle&#34;&gt;Hey Diddle Diddle&lt;/a&gt;, as illustrated here.&lt;/p&gt;

&lt;p&gt;&lt;img width=200 align=rigth src=&#34;http://upload.wikimedia.org/wikipedia/commons/1/1c/Hey_Diddle_Diddle_2_-_WW_Denslow_-_Project_Gutenberg_etext_18546.jpg&#34;/&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background:&lt;/strong&gt;
You may ask: why should I care about nonsense like this? Breaking text down into its structrual components, and assembling words are the basic operations of &lt;a href=&#34;http://en.wikipedia.org/wiki/Computational_linguistics&#34;&gt;computational linguistics&lt;/a&gt; or the computer science sub-field &lt;a href=&#34;http://en.wikipedia.org/wiki/Natural_language_processing&#34;&gt;natural language processing&lt;/a&gt;. The well-known &lt;a href=&#34;http://en.wikipedia.org/wiki/Turing_test&#34;&gt;Turing test&lt;/a&gt;, once known as one of the ultimate test of a machine&amp;rsquo;s intelligence, requires the machine to generate text and carry out conversation with a human. What you are going to do below is a small building block of internet &lt;a href=&#34;http://en.wikipedia.org/wiki/Outline_of_natural_language_processing#Chatterbots&#34;&gt;chatterbots&lt;/a&gt;, such as &lt;a href=&#34;http://alice.pandorabots.com&#34;&gt;A.L.I.C.E.&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let&amp;rsquo;s program:&lt;/strong&gt;
This task starts with a simple three-part sentence template &amp;ldquo;SUBJECT-VERB-LOCATION&amp;rdquo;. Open the editor for the block called &amp;ldquo;talking_setup&amp;rdquo;, you will see three variables SUB, V and LOC, each containing candidates for SUBJECT, VERB, and LOCATION, respectively.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/talking_setup.png&#34; alt=&#34;var&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Run these two blocks in workspace &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/sentence.png&#34; alt=&#34;var&#34; /&gt;, and you will see the same nonsense &amp;ndash; &amp;ldquo;the cow jumped over the moon&amp;rdquo; printed five times on the screen. Let&amp;rsquo;s try to get some new nonsense:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the block &lt;em&gt;generate_nonsense&lt;/em&gt;, and you will see a program as below. It prints &amp;ldquo;the cow jumped over the moon&amp;rdquo; by taking the first element from each of the three input lists (called &lt;em&gt;subject&lt;/em&gt;, &lt;em&gt;verb&lt;/em&gt; and &lt;em&gt;location&lt;/em&gt;).
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/generate_sentence.png&#34; alt=&#34;var&#34; /&gt;&lt;/p&gt;

&lt;p&gt;In particular, notice the &lt;em&gt;join&lt;/em&gt; block.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/join.png&#34; alt=&#34;var&#34; /&gt;
It does the opposite of the &lt;em&gt;split&lt;/em&gt; block introduced above, i.e. assemble a string of text by concatenating a list of words and spaces.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Your task is to make some changes in the &lt;em&gt;join&lt;/em&gt; block, so that each time the program will &lt;strong&gt;randomly pick&lt;/strong&gt; one element from each of the candidate lists to assemble a &lt;em&gt;sentence&lt;/em&gt;. Notice that the candidate lists have different number of candidate words, make sure your program can deal with this, and when the list of words change.&lt;/p&gt;

&lt;p&gt;You will need a new block for this task, &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/random.png&#34; alt=&#34;random&#34; /&gt;. Try clicking it to excute (you get a number!), then execute it again (you get a different number!) &amp;hellip; What this block does is equivalent to picking a number (from 1 to 10) from a hat &amp;ndash; you won&amp;rsquo;t know which exact one you will get, but the chances for getting any of the possible number is (roughly&lt;small&gt;^&lt;/small&gt;) equal.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Change the candidate words by changing the lists inside the block &lt;em&gt;talking_setup&lt;/em&gt;, keep generating sentences until you are happy with the result. If you want, you can also change the template to generate more complex nonsense!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;!--
#### Just for fun:
Post the most ridiculous/funny sentences that your program generated to [the corresponding thread on piazza](https://piazza.com/class/i5m3ankwcvc4av?cid=27). 
--&gt;

&lt;p&gt;&lt;strong&gt;Some more background:&lt;/strong&gt;
You may also ask: why is this nonsense?
This can be understood with two concepts. &lt;strong&gt;Syntax&lt;/strong&gt; is concerned with the structure of language. &lt;strong&gt;Semantics&lt;/strong&gt; is concerned with the meaning of words and sentences. In &amp;ldquo;the cow jumped over the moon&amp;rdquo;, the syntax (grammar) is correct, but its semantics (content or meaning) does not agree with commonsense &amp;ndash; leading to the memorable, and sometimes laughable effects of the literary nonsense. More broadly, the notions of syntax and semantics not only applies to natural languages (e.g., English), they also applies to programming languages. These topics are discussed further in later-year computer science classes such as &lt;a href=&#34;http://programsandcourses.anu.edu.au/course/comp4650&#34;&gt;Document analysis&lt;/a&gt; or &lt;a href=&#34;http://programsandcourses.anu.edu.au/course/comp3610&#34;&gt;Principles of programming languages&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;music-preparation-0&#34;&gt;Music Preparation (0%)&lt;/h3&gt;

&lt;p&gt;We&amp;rsquo;d like you to test your computer sound setup, and briefly review a primer on &amp;lsquo;singing&amp;rsquo;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Testing your setup&lt;/p&gt;

&lt;p&gt;Plug an earphone to your computer, &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html&#34;&gt;open Snap!&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Find this block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/default_note.png&#34; alt=&#34;default-note&#34; /&gt; from the left-hand-side menu, drag it to your workspace, click to execute it.&lt;/p&gt;

&lt;p&gt;Did you hear a note? (if not, check your sound settings and computer volume)&lt;/p&gt;

&lt;p&gt;Try changing the first and second number in the block to something else. How did the sound change?&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Review: Notes&lt;/p&gt;

&lt;p&gt;A note is the basic building block of music.&lt;/p&gt;

&lt;p&gt;Now lets put a few notes together and hear them. Put together five note blocks as shown below, change the first number to successively increment by one.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/five_note.png&#34; alt=&#34;five-note&#34; title=&#34;Code for the first 5 notes on a chromatic scale starting from C.&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Click to execute, and you will hear the first five notes in this picture &lt;img src=&#34;http://upload.wikimedia.org/wikipedia/commons/e/eb/Chromatic_scale_full_octave_ascending_and_descending_on_C.PNG&#34; width=500 /&gt;, i.e. the standard &lt;a href=&#34;http://en.wikipedia.org/wiki/Chromatic_scale&#34;&gt;chromatic scale&lt;/a&gt; starting from C, or the five shaded white and black keys on a piano keyboard &lt;img src=/images/lab3/keyboard.png width=400 /&gt;&lt;/p&gt;

&lt;p&gt;Now let&amp;rsquo;s do this:
Make a program (i.e. a set of note blocks) so that Snap! sings the &lt;a href=&#34;http://en.wikipedia.org/wiki/Scale_%28music%29&#34;&gt;C Major scale&lt;/a&gt;,
i.e. notes below, or the white keys within an octave on the piano keyboard.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;http://upload.wikimedia.org/wikipedia/commons/c/ce/C_major_scale.png&#34; alt=&#34;scale in C&#34; /&gt;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Review: Rhythms&lt;/p&gt;

&lt;p&gt;So far we&amp;rsquo;ve been changing the first number on the note block &amp;ndash; this is the pitch, mapped to numbers in midi notation (so that 60 is C, 69 is A, and so on).&lt;/p&gt;

&lt;p&gt;The second number represents the &lt;a href=&#34;http://en.wikipedia.org/wiki/Note_value&#34;&gt;note value&lt;/a&gt;, i.e., how long the note should be sung.&lt;/p&gt;

&lt;p&gt;Now let&amp;rsquo;s implement rhythm on an old-and-boring scale with &lt;a href=&#34;http://en.wikipedia.org/wiki/Dotted_note&#34;&gt;dotted notes&lt;/a&gt;, a most-commonly used &lt;a href=&#34;http://en.wikipedia.org/wiki/Note_value#Modifiers&#34;&gt;note modifier&lt;/a&gt;. Take the first five notes from your C-major scale above, and change them as follows:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/dotted.png&#34; alt=&#34;dotted-note&#34; title=&#34;dotted rhythm on a scale&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Excute this code and listen. Does this sound &lt;em&gt;a little less&lt;/em&gt; boring to you?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Question&lt;/em&gt;:
What rythm(s) cannot be accurately represented in the Snap! block we use?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Question&lt;/em&gt;: What is the score of these five notes with dotted rhythm?&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;!-- As of this writing, Markdown has no syntax for specifying the
dimensions of an image; if this is important to you, you can simply
use regular HTML `&lt;img&gt;` tags. --&gt;

&lt;h3 id=&#34;exercise-3-2-singing-a-tune-30&#34;&gt;Exercise 3.2  Singing a tune (30%)&lt;/h3&gt;

&lt;p&gt;How can you teach Snap! to sing any tuned? Let&amp;rsquo;s use what you learned about lists and arrays to help here.&lt;/p&gt;

&lt;p&gt;First open &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/lab3.xml&#34;&gt;this link&lt;/a&gt; to see the project for lab3. You&amp;rsquo;re provided an first list in a variable called &amp;ldquo;score_amazing_grace&amp;rdquo; &amp;ndash;containing the opening phase for &lt;a href=&#34;http://en.wikipedia.org/wiki/Amazing_Grace&#34;&gt;Amazing Grace&lt;/a&gt;. Click on the organge &amp;ldquo;set&amp;rdquo; block to initialize this variable.&lt;/p&gt;

&lt;p&gt;Open the function called &amp;ldquo;sing_a_tune&amp;rdquo; by right-clicking the grey function block, and selecting the last menu item &amp;ldquo;edit&amp;rdquo; as shown below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/edit_block.png&#34; alt=&#34;edit&#34; title=&#34;edit a function&#34; /&gt;&lt;/p&gt;

&lt;p&gt;A skeleton of this function is already provided, it will look like the one below:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/sing_a_tune_problem2.png&#34; alt=&#34;empty func&#34; title=&#34;skeleton of the singing function&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Here you are provided with a variable &lt;em&gt;index&lt;/em&gt; to loop through the score, and the variable &lt;em&gt;note&lt;/em&gt; stores information about each note as implemented there. Note that the &amp;ldquo;split block&amp;rdquo; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/split.png&#34; alt=&#34;split&#34; /&gt; takes a string as input, and returns a list of substrings that were originally separated by one given character &amp;ndash; in the &amp;ldquo;hello world&amp;rdquo; case, it&amp;rsquo;s two words separated by a space; in the score list, we split each element of a note as two numbers (pitch and value) separated by a comma. You just need to replace the purple &amp;ldquo;think&amp;rdquo; block with code that makes the correct sound given information in variable &lt;em&gt;note&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;When you&amp;rsquo;re done, click on the block &amp;lsquo;sing_a_tune(score_amazing_grace)&amp;rsquo; to hear the result &amp;ndash; does this sound right?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: You will need to remove the placeholder purple &amp;ldquo;Think&amp;rdquo; block and place your code in its place. Otherwise Snap will still sing but it will not sound quite right!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test your block!&lt;/strong&gt;
Testing (and testing, and testing again) is the key to creating correct software.
Don&amp;rsquo;t be discouraged if it doesn&amp;rsquo;t sound right (or doesn&amp;rsquo;t even make a sound) the first time, try to find where things went wrong and fix it. Feel free to ask tutors/lectures to help&lt;/p&gt;

&lt;h3 id=&#34;exercise-3-3-improving-your-function-20&#34;&gt;Exercise 3.3 Improving your function (20%)&lt;/h3&gt;

&lt;p&gt;Now let&amp;rsquo;s work on a differnt tune &amp;ndash; the opening phrase of &lt;a href=&#34;http://en.wikipedia.org/wiki/Radetzky_March&#34;&gt;Radetzky March&lt;/a&gt; by J Strauss. You can listen to it on YouTube &lt;a href=&#34;https://www.youtube.com/watch?v=2ORHVroiWHk&#34;&gt;by Vienna Philharmonic orchestra&lt;/a&gt; in 2014 New Year concert, or &lt;a href=&#34;https://www.youtube.com/watch?v=-nG2Et7VORg&#34;&gt;by a piano&lt;/a&gt;. This will reveal two aspects of our &amp;ldquo;sing_a_tune&amp;rdquo; function that needs improvement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;??&lt;/strong&gt; What is the pitch &amp;ldquo;0&amp;rdquo; in the score? This is used to denote rest, i.e. a silent note in for a particular duration. Use the rest block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/rest.png&#34; alt=&#34;rest&#34; /&gt; to make this happen.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Making a list&lt;/p&gt;

&lt;p&gt;The first is the input: it can be a pain to write a long list every time you&amp;rsquo;d like to sing a tune!&lt;/p&gt;

&lt;p&gt;An easier way is to represent the score in one long string &amp;ndash; with notes separated by semi-colons, and within each note the pitch and value are separated by a comma. Can you parse this long string in to a list of notes?&lt;/p&gt;

&lt;p&gt;This should be implemented in the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/str2score.png&#34; alt=&#34;str_to_score&#34; /&gt; block that takes the string as input, and output a list in the format as above &amp;ndash; and you assign the output to variable _score_radtzsky&lt;em&gt;march&lt;/em&gt; as in the project.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Changing the tempo&lt;/p&gt;

&lt;p&gt;Now you use the &amp;ldquo;sing_a_tune(score_radtzsky_march)&amp;rdquo; to play this tune using block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/radtzsky_slow.png&#34; alt=&#34;slowsinging&#34; /&gt;&amp;hellip; wait, Why does this march sound like everyone is falling asleep?  &amp;ndash; It&amp;rsquo;s too slow!&lt;/p&gt;

&lt;p&gt;In music the notion of being fast or slow is captpured in a property called tempo (as explained by &lt;a href=&#34;http://www.bbc.co.uk/schools/gcsebitesize/music/elements_of_music/rhythm_metre1.shtml&#34;&gt;bbc&lt;/a&gt; and &lt;a href=&#34;http://en.wikipedia.org/wiki/Tempo&#34;&gt;wikipedia&lt;/a&gt;). Tempo is measured in BPM, or Beats Per Minute. When you foot-tap along the music, a beat &lt;em&gt;very roughly&lt;/em&gt; correspond to a unit of &amp;lsquo;tapping&amp;rsquo;. 60bpm is one beat every second. We know that the tempo for Amazing Grace is 72bpm, as seen in the sing-a-tune function, whereas the tempo for energetic music, such as marches, is about 140bpm (i.e. a little more than two beats per second).&lt;/p&gt;

&lt;p&gt;Now make a new function &amp;ldquo;sing_a_tune2&amp;rdquo; to take into account tempo. Hint: you can duplicate-and-drag the existing structure in sing_a_tune and move them to sing_a_tune2, and take it from there!&lt;/p&gt;

&lt;p&gt;Once you are done, play this tune using &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/radtzsky_144.png&#34; alt=&#34;correctspeed&#34; /&gt; &amp;ndash; now does it sound right?&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&#34;exercise-3-4-shifting-keys-20&#34;&gt;Exercise 3.4  Shifting keys (20%)&lt;/h3&gt;

&lt;p&gt;Now you can sing-along or hum-along your Snap! program with your friends.&lt;/p&gt;

&lt;p&gt;But wait &amp;hellip; you may have a different &lt;a href=&#34;http://en.wikipedia.org/wiki/Vocal_range&#34;&gt;vocal range&lt;/a&gt; than where the tune is at. In other words, the tune may be &amp;lsquo;too high&amp;rsquo; or &amp;lsquo;too low&amp;rsquo; for you to sing. For example, someone with baritone or bass voice may have difficulty singing the Radtzsky March in our assignment. One commonly used solution is to shift the pitches of notes, up or down.&lt;/p&gt;

&lt;p&gt;In Snap!, shifting keys can be done with the simple arithmetic operations of addition and substraction.&lt;/p&gt;

&lt;p&gt;You start by stacking three blocks, initially playing a note sequence E3-G3-C4. The range of these notes starts from a low-E, your bass or baritone friends may not be able to sing this one.
&lt;small&gt;
    (And if you know a bit of how chords work, this is a transposed &lt;a href=&#34;http://en.wikipedia.org/wiki/Major_chord&#34;&gt;C major chord&lt;/a&gt; ending in central C)
&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/C.png&#34; alt=&#34;C&#34; title=&#34;C major chord&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Now you make three other blocks as below, &lt;em&gt;shifting&lt;/em&gt; the whole chord lower to G-major ending in the middle G.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/G.png&#34; alt=&#34;G&#34; title=&#34;G major chord&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Now the note sequence sounds lower overall, but the relationships between adjacent notes sounds the same. The Baritones are happy, but the first note is so low that your soporano friends may not be able to sing this one. Note how you can substract 5 from the pitch value of each note in the first picture to get the second picture. btw, this is called five &lt;a href=&#34;http://en.wikipedia.org/wiki/Semitone&#34;&gt;semitones&lt;/a&gt;, i.e. there are four black and white keys, between G and high C, and hence four intervals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your task&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implement a function called &amp;ldquo;shift_and_sing&amp;rdquo; to shift the key of a song up or down for a given amount, in a variable given as &amp;ldquo;shift&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Midi notes should be a positive integer, and &amp;ldquo;0&amp;rdquo; is used to denote rest. Within your function, check that all notes are euqal or above zero &amp;ndash; otherwise output an error message and halt the program.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hint: you can re-use the singing function you just made.&lt;/p&gt;

&lt;p&gt;Now sing along the Radtzky &amp;ndash; is this more comfortable?&lt;/p&gt;

&lt;p&gt;&lt;a name=&#34;crab&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;exercise-3-5-the-crab-cannon-20&#34;&gt;Exercise 3.5  The Crab Cannon (20%)&lt;/h3&gt;

&lt;p&gt;Now we are ready to play some advanced music! We explore the possibilities of singing in Snap! via the famous &lt;a href=&#34;https://en.wikipedia.org/wiki/Crab_canon&#34;&gt;&lt;em&gt;Crab Canon&lt;/em&gt;&lt;/a&gt; as seen in the book &lt;a href=&#34;https://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bach&#34;&gt;&lt;em&gt;Gödel, Escher, Bach&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&#34;preparation-concurrency-and-playing-chords&#34;&gt;Preparation: concurrency and playing chords&lt;/h4&gt;

&lt;p&gt;Our computers are often doing more than one thing at any given time &amp;ndash; for example, recieving an instant message while showing you a google search result. Making music also often require doing more than one thing at a time, such as, bowing more than one string at a time on a violin, hitting more than one key on a piano, or more than one person playing at any given time in an orchestra! Let&amp;rsquo;s use the computers&amp;rsquo; ability to mutli-task (called concurrency) to play poly-phonic music.&lt;/p&gt;

&lt;p&gt;The way Snap! achieves multi-tasking is via sending and receiving messages. Look at the code block below, excute the following steps, observe and hear the behavior.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1 &amp;ndash; click on each of the two groups of tone-playing-blocks. Do you hear &amp;ldquo;C-E-G&amp;rdquo; and &amp;ldquo;A3-C-E&amp;rdquo;?&lt;/li&gt;
&lt;li&gt;Step 2 &amp;ndash; now click on the left-most group with the &amp;ldquo;broadcast&amp;rdquo; block. Do you hear chords?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/chord_example.png&#34; alt=&#34;chord_example&#34; /&gt;
The &amp;ldquo;broadcast&amp;rdquo; block is acting like a commander here, it is responsible for &lt;em&gt;shouting&lt;/em&gt; out the &amp;ldquo;play_chord&amp;rdquo; message. The two &amp;ldquo;When I receive&amp;rdquo; block act like soldiers, they are tuned in to &amp;ldquo;play_chord&amp;rdquo; message, and will start acting (i.e. excuting their respective programs) upon hearing it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Just like naming variables, you should assign sensible names to the messages.&lt;/p&gt;

&lt;p&gt;Additional reading: You can find &lt;a href=&#34;http://bjc.eecs.berkeley.edu/bjc-r/cur/programming/concurrency/snap/snap-machine-concepts.html?topic=berkeley_bjc%2Fareas%2Fconcurrency.topic&#34;&gt;another explanation of concurrency in snap!&lt;/a&gt; here,
plus another code example of &lt;a href=&#34;https://inst.eecs.berkeley.edu/~cs10/labs/cur/programming/concurrency/snap/snap-play-1.html?topic=berkeley_bjc%2Fareas%2Fconcurrency.topic&amp;amp;novideo=true&amp;amp;noreading=true&amp;amp;noassingment=true&amp;amp;course=cs10_fa14.html&amp;amp;step=16&#34;&gt;broadcasting and recieving messagings in Snap!&lt;/a&gt; via a fun drawing program.&lt;/p&gt;

&lt;h4 id=&#34;the-crab-canon&#34;&gt;The Crab Canon&lt;/h4&gt;

&lt;p&gt;The enigmatic Canon 1 à 2 from J. S. Bachs &lt;a href=&#34;https://en.wikipedia.org/wiki/The_Musical_Offering&#34;&gt;Musical Offering&lt;/a&gt; (1747) depicts a single musical sequence that is to be played front to back and back to front.&lt;/p&gt;

&lt;p&gt;Here is a musical video that visualizes the manuscript while it&amp;rsquo;s being played, its reverse, the two voices played together, then the two voices visualized on a &lt;a href=&#34;https://en.wikipedia.org/wiki/M%C3%B6bius_strip&#34;&gt;mobius strip&lt;/a&gt;, and finally the two voices with different instruments.&lt;/p&gt;

&lt;iframe width=&#34;420&#34; height=&#34;300&#34; src=&#34;https://www.youtube.com/embed/xUHQ2ybTejU&#34; frameborder=&#34;0&#34; allowfullscreen&gt;&lt;/iframe&gt;

&lt;h4 id=&#34;your-crab-canon&#34;&gt;Your Crab Canon&lt;/h4&gt;

&lt;p&gt;We use the &amp;ldquo;https&amp;rdquo; block to get a copy of the top voice of the crab canon from the course website (you can see it &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/crab_score.txt&#34;&gt;here&lt;/a&gt;). And then you can use the &amp;lsquo;sing_a_tune2&amp;rsquo; block to play this voice, as shown below.
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/crab_prep.png&#34; alt=&#34;crab_block&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The way to have the second voice for the crab canon is by implementing the function that &lt;em&gt;reverses&lt;/em&gt; the first voice in time.
Put your implementation in this place-holder block &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lab3/reverse_fn.png&#34; alt=&#34;crab_revserse&#34; /&gt;.&lt;/p&gt;

&lt;p&gt;First test your block by playing out the reversed voice.
And then test your music by playing the two voices at the same time.&lt;/p&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;h3 id=&#34;for-fun-sing-your-own-tune&#34;&gt;For fun: Sing your own tune&lt;/h3&gt;

&lt;p&gt;Pick some other tune that you are familiar with (or make one up!), and ask Snap! to sing it.&lt;/p&gt;

&lt;p&gt;Post your song (and score) to the piazza discussion board.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Include its score as one or a few line of text (as the example above). Include a reference to its source if you have taken it from somewhere.&lt;/li&gt;
&lt;li&gt;Record your tune using a software, e.g. the voice memo or recorder app on your phone, and share it with the class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Submission, and testing your submission&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you are done, export your &lt;em&gt;talking_setup&lt;/em&gt; and &lt;em&gt;generate_nonsense&lt;/em&gt; blocks along with the singing blocks, and include them in your submission.&lt;/p&gt;

&lt;p&gt;As always, test your submission file
&amp;ndash; to make sure everything that should be included is indeed included!&lt;/p&gt;

&lt;p&gt;To do so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start a fresh chrome/chronium session&lt;/li&gt;
&lt;li&gt;Load the project for lab3.&lt;/li&gt;
&lt;li&gt;Use the &amp;ldquo;import &amp;hellip; &amp;rdquo; function from Snap to load your submission file containing the blocks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now run these blocks &amp;ndash; make sure the singing and talking works as before.&lt;/p&gt;

&lt;!--
    http://en.wikipedia.org/wiki/Literary_nonsense
    http://en.wikipedia.org/wiki/Jabberwocky
    http://en.wikipedia.org/wiki/Hey_Diddle_Diddle

### Exercise 3.3 The &#34;Crab Canon&#34; (0 point)

(Advanced) If you have used existing programming languages, here is a software package that can extract tunes from midi files. 

--&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;small&gt;
Image credits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;ldquo;Chromatic scale&amp;rdquo;, wikimedia user &lt;a href=&#34;http://commons.wikimedia.org/wiki/User:Chrupo%C5%A1&#34;&gt;Chrupos&lt;/a&gt;, &lt;a href=&#34;http://creativecommons.org/licenses/by-sa/3.0&#34;&gt;CC BY-SA 3.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Scale in C-Major&amp;rdquo;, wikimedia user &lt;a href=&#34;http://commons.wikimedia.org/wiki/User:%E3%81%A3&#34;&gt;っ&lt;/a&gt;, &lt;a href=&#34;http://creativecommons.org/licenses/by-sa/3.0&#34;&gt;CC BY-SA 3.0&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Triplets (and sixtuplets). As their fractional note values (e.g. &lt;sup&gt;1&lt;/sup&gt;&amp;frasl;&lt;sub&gt;3&lt;/sub&gt;) cannot be written out (exactly) as a real number with a finite number of digits.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;(Left for tutors to discuss/draw during labs).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Footnote:&lt;/p&gt;

&lt;p&gt;^ Further reading: here is an explanation about the history and basic technique for peudorandom numbers at the Khan Academy &lt;a href=&#34;https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/random-vs-pseudorandom-number-generators&#34;&gt;https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/random-vs-pseudorandom-number-generators&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;/small&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Lab 1: Karel the Robot</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/lab1/</link>
      <pubDate>Sun, 15 Jan 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/lab1/</guid>
      <description>

&lt;h2 id=&#34;lab-1-programming-karel&#34;&gt;Lab 1: Programming Karel&lt;/h2&gt;

&lt;p&gt;First, open &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/karel-lab1.xml&#34;&gt;Snap with Karel&lt;/a&gt;,
in a new tab or window so that you can do the lab exercises and continue
reading these instructions at the same time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slow to load?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Loading the page can take some time - anywhere from 20 seconds to 5
minutes. Exactly how long it takes depends on which browser you&amp;rsquo;re
using and the computer you&amp;rsquo;re on. We recommend using an up-to-date
version of the &lt;a href=&#34;http://www.chromium.org/&#34;&gt;chromium&lt;/a&gt; (chrome) browser,
but we have tested Snap! also with
&lt;a href=&#34;https://www.mozilla.org/en-US/firefox/new/&#34;&gt;firefox&lt;/a&gt;
and Internet Explorer.&lt;/p&gt;

&lt;p&gt;If the browser shows a message like &amp;ldquo;a script on this page has stopped
responding&amp;rdquo;, and asking you whether to &amp;ldquo;&lt;strong&gt;Stop script&lt;/strong&gt;&amp;rdquo; or &amp;ldquo;&lt;strong&gt;Continue&lt;/strong&gt;&amp;rdquo;,
choose &amp;ldquo;Continue&amp;rdquo;. (This may happen several times.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Karel ready to go&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before you can start Karel, or do run any program, you have to
initialise the grid and robot:
Click the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/setup-block.png&#34; alt=&#34;&amp;quot;Setup&amp;quot;&#34; /&gt; block. A green highlight
appears around the edges of the block while it is run. (Setup can also
take some time, up to a minute. If you don&amp;rsquo;t see the setup block at the
top of the work area, click the Karel icon in the lower right area.)
After that, you can start Karel by clicking the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/start-karel-block.png&#34; alt=&#34;&amp;quot;Turn Karel on&amp;quot;&#34; /&gt; block, and then
move him around by clicking the two movement blocks.&lt;/p&gt;

&lt;h3 id=&#34;exercise-1-1&#34;&gt;Exercise 1.1&lt;/h3&gt;

&lt;p&gt;In the first lecture, we showed you how to add a new &amp;ldquo;block&amp;rdquo; that made
Karel turn right (clockwise). You can find this block, as well as Karel&amp;rsquo;s
basic actions, in the &amp;ldquo;Motion&amp;rdquo; category of blocks.&lt;/p&gt;

&lt;p&gt;If you want to see how &amp;ldquo;Turn Karel right&amp;rdquo; works, right-click on it and
select &amp;ldquo;edit&amp;rdquo;: an editor with the definition of the block will show up.&lt;/p&gt;

&lt;p&gt;Now, create a new block that uses Karel&amp;rsquo;s basic actions (moving forward,
turning left) to make him move as if he had taken one step backwards.&lt;/p&gt;

&lt;p&gt;To create a new block, click on &amp;ldquo;Make a block&amp;rdquo; (in the &amp;ldquo;Variables&amp;rdquo;
category). A window pops up where you can name the new block (call
it &amp;ldquo;Move Karel backward&amp;rdquo;) and select its type (&amp;ldquo;Command&amp;rdquo;) and what
category it should be placed in (&amp;ldquo;Motion&amp;rdquo; would be the right choice).&lt;/p&gt;

&lt;p&gt;&lt;center&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/make-a-block-dialog.png&#34; alt=&#34;&amp;quot;Make a block&amp;quot; dialog&#34; /&gt;
&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;Click &amp;ldquo;Ok&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;This opens an editor for the new block. Create it by dragging in
appropriate blocks from the collections on the left (you may find
the blocks you need in different categories). When done, click
&amp;ldquo;Apply&amp;rdquo; or &amp;ldquo;Ok&amp;rdquo; and the block appears in the category where you
placed it. (Blocks in the &amp;ldquo;Other&amp;rdquo; category, coloured grey, appear
in the &amp;ldquo;Variables&amp;rdquo; tab.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test your new block!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Testing (and testing, and testing again) is the key to creating
correct software. To test the block, drag a copy of it into the
work area, and click on it: this will run the block. You can
compose it with other blocks, for example to make Karel walk
forwards and then backwards again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saving and loading blocks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After you have created some blocks that may be useful in future
labs, you may want to save them. (Starting from next week, you
will also need to save blocks so that you can submit your
assignment for marking.)
To do this, click the &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/file-menu.png&#34; alt=&#34;file menu&#34; /&gt; button,
and select &amp;ldquo;Export blocks&amp;rdquo;. This opens a window where you can
select which blocks to save. The default is to save all custom
blocks, which is probably more than you want so you will have to
deselect some. After you&amp;rsquo;ve made your selection, press &amp;ldquo;Ok&amp;rdquo; and the
browser will open a new tab (or window) with a description of
your chosen blocks. To save it, use your browsers &amp;ldquo;Save as&amp;rdquo;
function (usually found by right-clicking, or in the &amp;ldquo;File&amp;rdquo; menu).&lt;/p&gt;

&lt;p&gt;If you want to see an example of how it&amp;rsquo;s done,
&lt;a href=&#34;https://www.youtube.com/watch?v=96W45Ik7t_k&#34;&gt;here is a video&lt;/a&gt; (click on the last icon at the bottom to watch at full screen, click on the link to watch the larger version on youtube website).&lt;/p&gt;

&lt;iframe width=&#34;420&#34; height=&#34;315&#34; src=&#34;https://www.youtube.com/embed/96W45Ik7t_k&#34; frameborder=&#34;0&#34; allowfullscreen&gt;&lt;/iframe&gt;

&lt;h3 id=&#34;exercise-1-2&#34;&gt;Exercise 1.2&lt;/h3&gt;

&lt;p&gt;Now for something slightly more challenging. Click the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/setup-with-walls-block.png&#34; alt=&#34;&amp;quot;Setup with walls&amp;quot;&#34; /&gt; to
change Karel&amp;rsquo;s world to one that has some &amp;ldquo;hurdles&amp;rdquo; sticking
up from the bottom wall. We want to make Karel move along
the bottom wall, crossing each hurdle that he encounters.
To solve the problem, begin by breaking it down into small
parts, such as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Move Karel forwards until he is in front of a wall.&lt;/li&gt;
&lt;li&gt;Make Karel follow a wall (on his right) until it ends.&lt;/li&gt;
&lt;li&gt;Make Karel go over a hurdle, and back down to the bottom wall.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Make a block for each part. You should find that the first two
are useful in constructing the third.&lt;/p&gt;

&lt;p&gt;Finally, make Karel traverse the whole obstacle course. How do
you make him stop when he has reached the bottom-right corner?&lt;/p&gt;

&lt;h3 id=&#34;exercise-1-3&#34;&gt;Exercise 1.3&lt;/h3&gt;

&lt;p&gt;Karel wakes up, not knowing where he is (or which way he is facing)!
In one (and only one) of the corners of the grid, there is a beeper.
How can he get to it?&lt;/p&gt;

&lt;p&gt;To put Karel in this precarious situation, use the block
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/reset-random.png&#34; alt=&#34;&amp;quot;[tell (karel) reset_random] followed by [Turn Karel on]&amp;quot;&#34; /&gt;,
and &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/tell-grid-put-beeper.png&#34; alt=&#34;&amp;quot;[tell (grid) put_beeper]&amp;quot;&#34; /&gt;,
with the coordinates of one of the corners (for example, 11 and 1 is
the lower right corner). You can do this on the grid with hurdles
or without.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To Preserve your work for Lab 1&lt;/strong&gt;
Make one xml file with the new blocks you made for excercises 1.1 - 1.3 (and only those blocks), save it somewhere on your computer &amp;ndash; this way you can refer to them in future labs if you need to!&lt;/p&gt;

&lt;h2 id=&#34;assignment-submission&#34;&gt;Assignment submission&lt;/h2&gt;

&lt;p&gt;There is no assignment to submit this week. The first assignment
will be on lab 2, in which you will continue to teach Karel how to
do more things.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Lab 2: Karel the Robot (II)</title>
      <link>https://artofcomputing.cecs.anu.edu.au/lab/lab2/</link>
      <pubDate>Sun, 15 Jan 2017 00:00:00 UTC</pubDate>
      <author>Enthusiastic Hugo User</author>
      <guid>https://artofcomputing.cecs.anu.edu.au/lab/lab2/</guid>
      <description>

&lt;h2 id=&#34;lab-2-programming-karel-part-ii&#34;&gt;Lab 2: Programming Karel (part II)&lt;/h2&gt;

&lt;p&gt;Again, start by opening
&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/karel-lab2.xml&#34;&gt;Snap with Karel&lt;/a&gt;.
(Note that this is not the same link as in lab 1: This version
comes with a few other blocks ready-made.)
Open it in a new tab or window so that you can do the lab
exercises and continue reading these instructions at the
same time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reminder:&lt;/strong&gt; Loading the page can take a long time - how long
depends on which browser you&amp;rsquo;re using and the computer you&amp;rsquo;re on.
We recommend using an up-to-date version of the
&lt;a href=&#34;http://www.chromium.org/&#34;&gt;chromium&lt;/a&gt; (chrome) browser,
but we have tested Snap! also with
&lt;a href=&#34;https://www.mozilla.org/en-US/firefox/new/&#34;&gt;firefox&lt;/a&gt;
and Internet Explorer.
If the browser asks you to &amp;ldquo;Stop script&amp;rdquo; or &amp;ldquo;Continue&amp;rdquo; while
loading, choose &amp;ldquo;&lt;em&gt;Continue&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reminder:&lt;/strong&gt; Before you can start Karel, or run any program,
you have to initialise the grid and robot, by clicking the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/setup-block.png&#34; alt=&#34;&amp;quot;Setup&amp;quot;&#34; /&gt; block.&lt;/p&gt;

&lt;p&gt;For the first exercise, you should use a block called
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/setup-with-maze-block.png&#34; alt=&#34;&amp;quot;Setup with maze&amp;quot;&#34; /&gt;
instead. You will find it near the end of the list in the
Variables category.&lt;/p&gt;

&lt;h3 id=&#34;exercise-2-1&#34;&gt;Exercise 2.1&lt;/h3&gt;

&lt;p&gt;As we talked about in the lectures, a reporter block (also known
as a &lt;em&gt;function&lt;/em&gt;) is a block that returns a value, and that can be
used in expressions (like +, join, etc). Reporter blocks are
distinguished from command blocks by having rounded corners.
Snap! also has a third shape of block, called a &lt;em&gt;predicate&lt;/em&gt;.
This is a reporter block that always returns one of the values
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/constant-true-block.png&#34; alt=&#34;true&#34; /&gt; or
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/constant-false-block.png&#34; alt=&#34;false&#34; /&gt;.
Predicate blocks can be used in conditional blocks, like &lt;em&gt;if&lt;/em&gt; and
&lt;em&gt;repeat until&lt;/em&gt;.
Snap! allows you to define custom predicate blocks, just the same
as custom reporters and command blocks.&lt;/p&gt;

&lt;p&gt;Karels perception abilities are limited: he can only look for a
wall right in front of him, or a beeper on the spot where he stands.
In the Sensing category, you will find a predicate called
&amp;ldquo;Beeper in front?&amp;rdquo; Right-click and select &amp;ldquo;edit&amp;rdquo; to open it in the
block editor. This predicate is incomplete. You must fill it in so
that it&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reports true if the corner in front of Karel contains a beeper,
and there is no wall blocking the way there;&lt;/li&gt;
&lt;li&gt;reports false if there is a wall in front of Karel, or no beeper
on the corner in front; and&lt;/li&gt;
&lt;li&gt;after execution of the block, Karel is in the same place and
facing the same direction as he was before it started.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;In front&amp;rdquo; means in front of Karel with one step away.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Testing your new block&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As always, test your new block! Set up test cases by placing a beeper
in front of Karel, turning him to face a wall, and so on.&lt;/p&gt;

&lt;p&gt;After you are satisfied that it works correctly, try using it to make
Karel follow a trail. You will find a block called
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/lay-a-trail-block.png&#34; alt=&#34;&amp;quot;Lay a trail&amp;quot;&#34; /&gt;
which lays out a trail to get Karel out of the maze,
and a block called &amp;ldquo;Follow a trail&amp;rdquo; (in the Motion category) that
makes Karel follow this trail. &amp;ldquo;Follow a trail&amp;rdquo; uses your
&amp;ldquo;Beeper in front?&amp;rdquo; predicate, so if that does not work correctly,
it is likely that trail following will not either.&lt;/p&gt;

&lt;h3 id=&#34;exercise-2-2&#34;&gt;Exercise 2.2&lt;/h3&gt;

&lt;p&gt;In the lectures, we have shown you how to make Karel collect beepers.
Now it is time to load up Karel with a stack of beepers and instruct
him to lay them out in a nice pattern. Specifically, given any number
of beepers, we want him to lay them out in a square field, or as close
to a square as he can. (If the number is not a perfect square, the
number of rows and columns should not differ by more than one, and the
number of beepers in either rows or columns should be the same except
for possibly the last one.) For example,
&lt;center&gt;
&lt;table border=&#34;0&#34;&gt;
&lt;tr&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-1.png&#34; alt=&#34;&amp;quot;layout 1&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-2.png&#34; alt=&#34;&amp;quot;layout 2&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-3.png&#34; alt=&#34;&amp;quot;layout 3&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-4.png&#34; alt=&#34;&amp;quot;layout 4&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-5.png&#34; alt=&#34;&amp;quot;layout 5&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-6.png&#34; alt=&#34;&amp;quot;layout 6&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-7.png&#34; alt=&#34;&amp;quot;layout 7&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-8.png&#34; alt=&#34;&amp;quot;layout 8&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-9.png&#34; alt=&#34;&amp;quot;layout 9&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;td&gt; &lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/layout-square-10.png&#34; alt=&#34;&amp;quot;layout 10&amp;quot;&#34; /&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;You should create a top-level block called
&amp;ldquo;Make a square with (number) beepers&amp;rdquo;, where the number is the
input. To make sure that Karel has enough beepers to fill the
square, use the block &amp;ldquo;tell&amp;rdquo; block, like this:
&lt;center&gt;
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/make-a-square-definition.png&#34; alt=&#34;Definition of the block &amp;quot;Make a square with (number) beepers&amp;quot;&#34; /&gt;
&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;Before you start on this exercise, run the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/setup-block.png&#34; alt=&#34;&amp;quot;Setup&amp;quot;&#34; /&gt; block again.
This will remove the maze, giving Karel space to lay out his beepers.
You can use the
&lt;img src=&#34;https://artofcomputing.cecs.anu.edu.au/images/clear-beepers-and-reset.png&#34; alt=&#34;clear beepers and reset&#34; /&gt; blocks
to remove all beepers from the grid and put Karel back in his starting
corner; that will probably be useful as you test and debug the square
layout block.&lt;/p&gt;

&lt;h2 id=&#34;assignment-submission&#34;&gt;Assignment submission&lt;/h2&gt;

&lt;p&gt;To submit your assignment, you need to export blocks (as described on
&lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/lab/lab1/&#34;&gt;the lab 1 page&lt;/a&gt; and
&lt;a href=&#34;https://www.youtube.com/watch?v=96W45Ik7t_k&#34;&gt;shown in this video&lt;/a&gt;).
You should export the two blocks that you defined in this lab,
&amp;ldquo;Beeper in front?&amp;rdquo; and &amp;ldquo;Make a square with (number) of beepers&amp;rdquo;, as
well as any other custom blocks you created that are used inside
those two (or used inside those used inside those two, and so on).&lt;/p&gt;

&lt;p&gt;Submit the file with the saved blocks through
&lt;a href=&#34;http://wattlecourses.anu.edu.au/course/view.php?id=12823&#34;&gt;wattle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing your submission&lt;/strong&gt;
As always, test your submission file
&amp;ndash; to make sure everything that should be included is indeed included!&lt;/p&gt;

&lt;p&gt;To do so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start a fresh chrome/chronium session&lt;/li&gt;
&lt;li&gt;Load the &lt;a href=&#34;https://artofcomputing.cecs.anu.edu.au/snap/snap.html#open:https://artofcomputing.cecs.anu.edu.au/code/karel-lab2.xml&#34;&gt;Snap+Karel workspace for Lab 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Use the &amp;ldquo;import &amp;hellip; &amp;rdquo; function from Snap to load your submission file containing the blocks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now run these blocks &amp;ndash; is Karel doing what she&amp;rsquo;s asked to do in 2.1 and 2.2?&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>