<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Mps on CPSC221 2018W2: Data Structures</title>
    <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/</link>
    <description>Recent content in Mps on CPSC221 2018W2: Data Structures</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 12 Mar 2019 12:00:00 +0000</lastBuildDate>
    <atom:link href="/~cs-221/2018W2/mps/" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>PA3</title>
      <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/p3/</link>
      <pubDate>Tue, 12 Mar 2019 12:00:00 +0000</pubDate>
      
      <guid>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/p3/</guid>
      <description>

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;UPDATES!&lt;/strong&gt;
&lt;p&gt;NOTE: Clarifications, updates, and hints to solving this PA can be found on this piazza page:  &lt;a href=&#34;https://piazza.com/class/jpu51kyvbx9ps?cid=1779&#34;&gt;https://piazza.com/class/jpu51kyvbx9ps?cid=1779&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;Lab machines&lt;/strong&gt;
&lt;p&gt;We will be grading the PAs for this course using an image similar to the remote Linux machines. Any
errors that you run into as a result of developing your code on &lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/resources/own-machine/&#34;&gt;other
machines&lt;/a&gt; are your own responsibility.&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;goals-and-overview&#34;&gt;Goals and Overview&lt;/h2&gt;

&lt;p&gt;In this PA (Programming Assignment) you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;learn about algorithmic art.&lt;/li&gt;
&lt;li&gt;learn about an unusual algorithm for lossy image compression.&lt;/li&gt;
&lt;li&gt;learn about space partitioning trees called Quad Trees.&lt;/li&gt;
&lt;li&gt;learn about clever mechanisms for speeding up statistical algorithms.&lt;/li&gt;
&lt;li&gt;learn to be aware of memory usage in recursive programs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;the-assignment-part-1-inspiration-and-background&#34;&gt;The Assignment, Part 1: Inspiration and Background&lt;/h2&gt;

&lt;p&gt;The inspiration for this assignment came from an &lt;a href=&#34;https://mymodernmet.com/algorithm-art-color-study-dimitris-ladopoulos/&#34;&gt;article&lt;/a&gt; about an artist whose work
recreates classic portraits with a blocky effect. The exact algorithm he used is not given in the
article, but we will create similar images using a strategy for image representation that
underlies common lossy image compression algorithms.&lt;/p&gt;

&lt;p&gt;The two images below illustrate the result of this assignment. Note that the image on the right sacrifices color
detail in rectangles that do not contain much color variability in the original image, but maintains
detail by using smaller rectangles in areas of the original image containing lots of variability.&lt;/p&gt;

&lt;p&gt;&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;PA3pic1.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt; &lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;prelim-stanley.05.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;In specifying the algorithm we make several conventional assumptions, illustrated below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The origin, position (0,0), is in the upper left corner of the image.&lt;/li&gt;
&lt;li&gt;Rectangles are typically specified either by a pair of points at its upper left and lower right corners, or by an upper left point, together with dimensions (this assingment uses both).&lt;/li&gt;
&lt;li&gt;The upper left corner of a rectangle is the one nearest to the origin.&lt;/li&gt;
&lt;li&gt;Image locations are typically specified as (x,y), where x is a horizontal offset, and y is a vertical offset.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;PA3pic3.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;h3 id=&#34;quadtrees-on-a-torus&#34;&gt;QuadTrees on a Torus&lt;/h3&gt;

&lt;p&gt;The original image will be represented in memory as a 4-ary tree whose nodes contain information about square subsets of the image.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every node is the root of a subtree that represents a subset of the original image. Note that the region might not be contiguous in the original image.&lt;/li&gt;
&lt;li&gt;Every node also contains a pixel that represents the average color over the square in the original image.&lt;/li&gt;
&lt;li&gt;Every node contains a dimension that determines the size of the square it represents. If dimension == d, then the node represents a $$2^d\times 2^d$$ square.&lt;/li&gt;
&lt;li&gt;When a square is split into four smaller squares, the parent node represents the whole square, and the 4 children each contain a quadrant of the original.&lt;/li&gt;
&lt;li&gt;Each square is split into 4 equal sized quadrants by an optimal choice of &amp;ldquo;splitting&amp;rdquo; point, described below.&lt;/li&gt;
&lt;li&gt;Before pruning, every leaf in the tree corresponds to a pixel in the original image, and every pixel is represented by some leaf. The image below represents a part of the unpruned quadtree. We did not draw the leaves in the diagram.&lt;/li&gt;
&lt;/ul&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;quadtrees.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;Consider every node to represent a square image that you will subdivide into 4 children nodes. In order to determine how to partition the square, you will find a splitting point from among the points in the light green region in the image below (in general, this will be a $$2^{k-1} \times 2^{k-1}$$ square in the middle of the $$2^k\times 2^k$$ image:&lt;/p&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;splitting.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;Traverse the pixels in the green square, looking for the one which minimizes the average entropy (described below) over the 4 squares it determines.  In this example, we suppose the pixel containing the orange dot gives the minimum entropy score. That orange dot pixel will become the upper left corner of the SE quadrant of the 4-way split.&lt;/p&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;squares.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;The center found in the illustration will be the upper left corner of the square that we will call SE, for Southeast because it is below and to the right of the optimal splitting point.  The squares marked NW, SW, and NE are the upper left corners of the 3 other squares determined by the split. You will need to compute these locations, given the optimal splitting point, and considering that the edges of the square image wrap around to meet.&lt;/p&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;biglittlesquares.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;Once you have an optimal splitting point, and the upper left corner of all 4 squares, you will explicitly create the 4 squares as the bases for the current node’s children. The illustration shows you how to build the NW child.&lt;/p&gt;

&lt;p&gt;Note that in the general case, one of the 4 squares will be a whole square subset of the current image, one will be a horizontal shift into segments where part of the square is on the right of the image, and part is on the left, corresponding to SW in the example above (note that the number of shifted locations might be 0), one will be a similar vertical shift (again, where the shift might be 0), and one will be both a horizontal and a vertical shift (again, where one or both directions’ shifts might be 0).&lt;/p&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;child.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;Finally, the squares you reconstruct out of a partition of the current square are (recursively) the basis for the child nodes.&lt;/p&gt;

&lt;h3 id=&#34;entropy&#34;&gt;Entropy&lt;/h3&gt;

&lt;p&gt;Splits are performed so as to minimize hue variability across the resulting squares. The variability
measurement we use is the &lt;em&gt;entropy&lt;/em&gt;, which is computed as a function of the distribution of colors
in a rectangle as follows:
Given a relative frequency table of the colors over some rectangle,
where $p_i$ represents
the fraction of pixels whose hue, $h$, is $10\cdot i\leq h &amp;lt; 10\cdot(i+1)$, the entropy for the
rectangle is&lt;/p&gt;

&lt;div&gt;
$$ -\Sigma_{i=0}^{35} ~p_i\log_2(p_i). $$ 
&lt;/div&gt;

&lt;p&gt;The entropy of a &lt;em&gt;split&lt;/em&gt; is the average of the entropy of the 4 resulting squares. (In the case of ties, we choose the split which occurs first in a column-wise navigation of the feasible region of splits.)&lt;/p&gt;

&lt;p&gt;As part of this assignment, we build a data structure that allows us to find the histogram of colors
for any rectangle, in constant time. To that end we build a 2D vector structure whose cells, (i,j),
each contain a frequency table for the rectangle with upper left corner (0,0), and lower right
corner (i,j).&lt;/p&gt;

&lt;p&gt;The first two splits of the image of Vancouver City Hall are
illustrated in the second image below.&lt;/p&gt;

&lt;p&gt;&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;PA3pic5.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt; &lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;prelim-CP3.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;To achieve an artistic effect we prune, or cut off, parts of the quadtree. A parameter, tolerance,
is used to evaluate a subtree&amp;rsquo;s suitability for pruning. A node is pruned if all of the
leaves in its subtree are within tolerance of its average. To prune a node, simply clear the memory associated with each of its four children, leaving the node a leaf. Distances between colors are computed
using the HSLAPixel dist function.&lt;/p&gt;

&lt;h2 id=&#34;the-assignment-part-2-coding&#34;&gt;The Assignment, Part 2: Coding&lt;/h2&gt;

&lt;h3 id=&#34;problem-specification&#34;&gt;Problem Specification&lt;/h3&gt;

&lt;p&gt;Specifications for each function you write are contained in the
given code. The list of functions here should serve as a
checklist for completing the exercise.&lt;/p&gt;

&lt;h4 id=&#34;in-class-stats&#34;&gt;In &lt;code&gt;class stats&lt;/code&gt;:&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;stats(PNG &amp;amp; im)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HSLAPixel getAvg(pair&amp;lt;int,int&amp;gt; ul, pair&amp;lt;int,int&amp;gt; lr)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;long rectArea(pair&amp;lt;int,int&amp;gt; ul, pair&amp;lt;int,int&amp;gt; lr)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;double entropy(pair&amp;lt;int,int&amp;gt; ul, pair&amp;lt;int,int&amp;gt; lr)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;double entropy(vector&amp;lt;int&amp;gt; distn, int area)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;in-class-toqutree&#34;&gt;In &lt;code&gt;class toqutree&lt;/code&gt;:&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;void clear(Node * &amp;amp; croot)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Node * copy(const Node * croot)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toqutree(PNG &amp;amp; imIn, int dim)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PNG render()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void prune(int tol)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int size()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Node * buildTree(PNG * im, int k)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;implementation-constraints-and-advice&#34;&gt;Implementation Constraints and Advice&lt;/h3&gt;

&lt;p&gt;We will be grading your work on functionality, efficiency, and memory use.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;stats&lt;/code&gt; class is used only for constructing a node of the &lt;code&gt;toqutree&lt;/code&gt;. The choice of optimal split requires the computation of
statistics over
each candidate split, and these are simply too expensive to compute in real time, especially given the number of
squares in our recursively defined tree!  Instead, we precompute support
structures that allow the necessary statistics to be computed in constant time. We request a particular set of
structures, but
we leave it as a puzzle for you to figure out how to use them to get the info you need.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;toqutree&lt;/code&gt; class is a standard quadtree class, with a twist. We consider a square image to be a &lt;code&gt;torus&lt;/code&gt; or a donut, in the sense that the right side of the image is considered to be adjacent to the left, and the top of the image is considered to be adjacent to the bottom. We&amp;rsquo;ve defined the &lt;code&gt;Node&lt;/code&gt; class for you, and a few other necessary
memory management functions, but everything else is left to you. Since we will be grading both the &lt;code&gt;.h&lt;/code&gt; and &lt;code&gt;.cpp&lt;/code&gt; files,
you are welcome to add helper functions to the class.&lt;/p&gt;

&lt;h3 id=&#34;getting-the-given-code&#34;&gt;Getting the Given Code&lt;/h3&gt;

&lt;p&gt;Download the source files from &lt;a href=&#34;pa3.zip&#34;&gt;pa3.zip&lt;/a&gt;, and follow the
procedures you learned in lab to move them to your home directory
on the remote linux machines.&lt;/p&gt;

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

&lt;p&gt;We have provided two avenues for your exploration and testing, neither
of which is sufficient to completely verify the correct implementation
of all of your functions. You should add additional tests yourself!&lt;/p&gt;

&lt;p&gt;When you type &lt;code&gt;make&lt;/code&gt; two executables are produced. One depends on the
given main.cpp, and the other depends on the file testComp.cpp which
is a small collection of test cases using the catch framework (as in
previous assignments).&lt;/p&gt;

&lt;h3 id=&#34;handing-in-your-code&#34;&gt;Handing in your code&lt;/h3&gt;

&lt;p&gt;To facilitate anonymous grading, &lt;strong&gt;do not&lt;/strong&gt; include any personally-identifiable
information (like your name, your University ID number, or your cwl) in any
of your source files. Instead, before you hand in this assignment,
create a file called &lt;code&gt;partners.txt&lt;/code&gt; that contains only the CSIDs of
 people in your collaboration partnership (if one exists), one per line.
If you worked alone, include only your own
CSID in this file. We will be automatically processing this information, so do
not include anything else in the file.
As always, if you&amp;rsquo;re working in a group, each
group member must hand in the assignment. (Failure to cite collaborators
violates our academic integrity policy;)&lt;/p&gt;

&lt;p&gt;The following files are used to grade PA3:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;stats.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stats.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toqutree.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toqutree.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;partners.txt&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All other files will not be used for grading.&lt;/p&gt;

&lt;p&gt;You will submit your work to &lt;a href=&#34;https://www.gradescope.com/courses/33829&#34;&gt;gradeScope&lt;/a&gt; as you did for PA2.&lt;/p&gt;

&lt;h2 id=&#34;good-luck&#34;&gt;Good luck!&lt;/h2&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Homework 3</title>
      <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/h3/</link>
      <pubDate>Tue, 19 Feb 2019 22:00:00 +0000</pubDate>
      
      <guid>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/h3/</guid>
      <description>

&lt;p&gt;Link to document: &lt;a href=&#34;https://www.overleaf.com/read/fbfftqnqhjxx&#34;&gt;hw3 overleaf&lt;/a&gt;
 | &lt;a href=&#34;cpsc221_2018W2_HW3_samplesoln.pdf&#34;&gt;solutions&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;instructions-for-hw3&#34;&gt;Instructions for HW3&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;This homework assignment allows you to work with a partner&lt;/strong&gt;! Please submit
only one copy of your work for the partnership. GradeScope allows you to
identify both members of the pair upon submission.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;legible&lt;/strong&gt; pdf of your solution must be checked in to &lt;a href=&#34;https://gradescope.com/courses/33829&#34;&gt;GradeScope&lt;/a&gt;
by the deadline.&lt;/p&gt;

&lt;h3 id=&#34;using-overleaf&#34;&gt;Using Overleaf&lt;/h3&gt;

&lt;p&gt;Assignments will be distributed via Overleaf, an online latex editor. Before you begin,
create an account and log in to Overleaf, then return to this page to link to the document. The initial document is read-only, so you&amp;rsquo;ll have to click on the up-arrow in the upper left corner of the screen to bring up your Overleaf dashboard. Then you can make a copy of the homework and begin to craft your solutions.  We recommend that you use the Overleaf editor to typeset
    your answers to the problems. Then, when you&amp;rsquo;re finished, download your completed assignment as
    a .pdf, and upload it to Gradescope. (Detailed instructrions below.)&lt;/p&gt;

&lt;p&gt;Latex is a powerful and popular typsetting package, commonly used for documents that have
    sophisticated diagrams and figures (like math and code!). The learning curve for fluency in Latex
    is fairly steep, but it&amp;rsquo;s a valuable skill, so we&amp;rsquo;re asking you to try to use it to compose your
    homework solutions. We are assisting your learning in three specific ways: 1) the homework&amp;rsquo;s latex source code
    contains examples of most of the tags you will need in your answers, 2) we are happy to answer any of your latex questions on piazza,
    and 3) the Overleaf web
    site has several short tutorials and videos to give you an overview of the kinds of things you can do.
    Like every latex user EVER, you will find
    google to be your best source of technical assistance.&lt;/p&gt;

&lt;h3 id=&#34;marking-on-gradescope&#34;&gt;Marking on Gradescope&lt;/h3&gt;

&lt;p&gt;Assignments will be collected and graded on [Gradescope]((&lt;a href=&#34;https://gradescope.com/courses/33829&#34;&gt;https://gradescope.com/courses/33829&lt;/a&gt;). You will access GradeScope using your
    csid. We will be preloading the course roster into GradeScope, after which you will be
    able to log in.&lt;/p&gt;

&lt;p&gt;NOTE: You will be required to follow the instructions below for submitting your assignments on Gradescope. The overall goal is for you to tell us, via the interface, where each of the problem parts appears on your submission. You MUST align the regions for every problem, even if your homeworks solution isn&amp;rsquo;t complete. We will not be able to mark any problem we can&amp;rsquo;t find.&lt;/p&gt;

&lt;p&gt;Log in to Gradescope using your csid. Navigate to HW3 and follow the instructions to submit a pdf.&lt;/p&gt;

&lt;p&gt;Then follow the instructions found here: &lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/info/gs-submission/&#34;&gt;Gradescope Submission Guidelines&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;group-work&#34;&gt;Group Work&lt;/h3&gt;

&lt;p&gt;We highly encourage you to do assignments in groups of two,
    though you may work alone if you choose. Groups larger than two
    students are not allowed. Only one Gradescope submission is expected for each
    group. Be sure to identify your group on Gradescope.&lt;/p&gt;

&lt;h3 id=&#34;marking&#34;&gt;Marking&lt;/h3&gt;

&lt;p&gt;As a rule of thumb,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A solution to a question that is correct, complete, and legible will be worth full marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A legible solution that contains some errors or is not quite complete, but shows a
clear grasp of how the concepts and techniques required apply to this problem, will be
worth about 66% of the marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A  legible solution  that is  either correct  but difficult  to read,  or contains
errors or  is not complete,  but shows  a clear grasp  of the concepts  and techniques
required, although not  their application to this problem, will be  worth about 33% of
the marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A solution that contains substantial errors, is far from complete, does not show a
clear grasp of the concepts and techniques required, or is illegible will receive very
few marks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This  marking scheme reflects  our intent  for you  to learn  the key  concepts and
    techniques  underlying  computation,  determine  where  they  apply,  and  apply  them
    correctly  to  interesting  problems. It  also  reflects  a  practical fact:  we  have
    insufficient time to decipher illegible answers. All typeset solutions will be considered
    legible.&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>PA 2</title>
      <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/p2/</link>
      <pubDate>Sat, 09 Feb 2019 00:00:00 +0000</pubDate>
      
      <guid>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/p2/</guid>
      <description>

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;GradeScope submission&lt;/strong&gt;
&lt;p&gt;We will be grading this PA using GradeScope. Our basic test cases will
be run against your code every time you submit, so we encourage you to submit early
and often! Code which does not compile will not be given any credit. Basic test
cases will be available within a few days after the PA release. We will add the
grading test cases sometime during the reading week.&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;goals-and-overview&#34;&gt;Goals and Overview&lt;/h2&gt;

&lt;p&gt;In this PA you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;learn about Stacks, Queues, and Deques&lt;/li&gt;
&lt;li&gt;learn about depth-first-search (DFS) and breadth-first-search (BFS) traversal&lt;/li&gt;
&lt;li&gt;learn about some more advanced C++ constucts, including basic templates and inheritance&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;getting-the-given-code&#34;&gt;Getting the Given Code&lt;/h2&gt;

&lt;p&gt;Download the source files from &lt;a href=&#34;pa2.zip&#34;&gt;pa2.zip&lt;/a&gt;, and follow the
procedures you learned in lab to move them to your home directory
on the remote linux machines.&lt;/p&gt;

&lt;h2 id=&#34;part1&#34;&gt;Part 1: The &lt;code&gt;Stack&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, and &lt;code&gt;Deque&lt;/code&gt; Classes&lt;/h2&gt;

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;Template Compilation&lt;/strong&gt;
&lt;p&gt;Note that the &lt;code&gt;stack.h&lt;/code&gt;, &lt;code&gt;queue.h&lt;/code&gt;, and &lt;code&gt;deque.h&lt;/code&gt; files we&amp;rsquo;ve given you include the
&lt;code&gt;.cpp&lt;/code&gt; files at the end, so you should NOT
use a &lt;code&gt;#include &amp;quot;XXX.h&amp;quot;&lt;/code&gt; at the top of
the &lt;code&gt;XXX.cpp&lt;/code&gt; file. We have done it this way so that the
template types are instantiated appropriately.&lt;/p&gt;

&lt;/div&gt;

&lt;h3 id=&#34;the-deque-class&#34;&gt;The &lt;code&gt;Deque&lt;/code&gt; Class&lt;/h3&gt;

&lt;p&gt;You will write a class named &lt;code&gt;Deque&lt;/code&gt; which is a modification of a doubly ended
queue structure. While the standard deque allows for insertion and
removal at both ends of a contiguous arrangement of data, our deque will allow
insertion and removal at one end, but only removal at the other. For convenience,
we will refer to the removal-only end as the left end, and the other as the right.&lt;/p&gt;

&lt;p&gt;Your deque should be implemented as follows: The underlying data structure will
be a C++ standard vector. Following the convention of the queue we discussed in
class, you will allow the data to &amp;ldquo;float&amp;rdquo; in the vector, with the following
difference: If, upon a removal, you discover that the contiguous block of data
(whose size is, say, k)
will &amp;ldquo;fit&amp;rdquo; in the first k positions of the vector, then you should resize down
by making a new vector and copying the k pieces of data into that new vector
using the &lt;code&gt;push_back&lt;/code&gt; function. Additions to the structure can use the standard
vector functions, and can only occur at the &amp;ldquo;right&amp;rdquo; side of the contiguous data (i.e.
the position of largest index).
(Note that in this implementation the structure is not &amp;ldquo;circular&amp;rdquo;&amp;ndash;
we do not wrap the data using the modulo of the array size.)&lt;/p&gt;

&lt;h3 id=&#34;the-stack-class&#34;&gt;The &lt;code&gt;Stack&lt;/code&gt; Class&lt;/h3&gt;

&lt;p&gt;You will write a class named &lt;code&gt;Stack&lt;/code&gt; that works just like the stack you heard
about in lecture, with the addition of the &lt;code&gt;peek()&lt;/code&gt; function. It is declared in
the given file &lt;code&gt;stack.h&lt;/code&gt;. You will implement it in &lt;code&gt;stack.cpp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;Stack&lt;/code&gt; class must implement all of the methods mentioned in the
given code. Please read the documentation
in the header file to see what limitations we have placed on your
&lt;code&gt;Stack&lt;/code&gt; class and what the running times of each function should be.&lt;/p&gt;

&lt;h3 id=&#34;the-queue-class&#34;&gt;The &lt;code&gt;Queue&lt;/code&gt; Class&lt;/h3&gt;

&lt;p&gt;You will write a class named &lt;code&gt;Queue&lt;/code&gt; that works just like the queue you heard
about in lecture, with the addition of the &lt;code&gt;peek()&lt;/code&gt; function. It is declared in
the given file &lt;code&gt;queue.h&lt;/code&gt;. You will implement it in &lt;code&gt;queue.cpp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;Queue&lt;/code&gt; class must implement all of the methods mentioned in the
given code. Please read the documentation
in the header file to see what limitations we have placed on
your &lt;code&gt;Queue&lt;/code&gt; class and what the running times of each function should be.&lt;/p&gt;

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

&lt;p&gt;We have provided a file &lt;code&gt;testStackQueue.cpp&lt;/code&gt; which includes a few (albeit
trivial) test cases that your code should pass if it is correct. To compile
this executable, type:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;make testStackQueue
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These test cases are deliberately insufficient. We encourage you to augment
this file with additional test cases, using the provided ones as examples.
In particular, we have not provided test cases for your &lt;code&gt;deque&lt;/code&gt; class. You
will want to add those yourself!&lt;/p&gt;

&lt;h3 id=&#34;grading-information-for-part-1&#34;&gt;Grading Information for Part 1&lt;/h3&gt;

&lt;p&gt;The following files are used to grade the stack and queue classes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;deque.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stack.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;queue.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;partners.txt&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All other files (including any testing files you create) will not be used for
grading.&lt;/p&gt;

&lt;h2 id=&#34;part-2-flood-fill&#34;&gt;Part 2: Flood Fill&lt;/h2&gt;

&lt;div style=&#34;text-align: left;&#34;&gt;
&lt;p&gt;
&lt;figure class=&#34;inline-figure&#34; style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;bfsraingirl.gif&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;
&lt;div style=&#34;display: inline-block; width: 1em;&#34;&gt;&lt;/div&gt;
&lt;figure class=&#34;inline-figure&#34; style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;dfsraingirl.gif&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;
&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For this part of the assignment, you will be writing a number of functions that
execute a &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Flood_fill&#34;&gt;flood fill&lt;/a&gt;&amp;rdquo; on a &lt;code&gt;PNG&lt;/code&gt; image. To flood fill a region of an image,
you specify a point on the image and a fill color (or pattern) and all points
similar in color and adjacent to the chosen point are changed to the fill color
(or pattern). We will implement two different fill algorithms and three different
fill patterns. The two fill algorithms are animated in the pictures above with
a rainbow color fill pattern that we implemented.&lt;/p&gt;

&lt;h3 id=&#34;functors&#34;&gt;Functors&lt;/h3&gt;

&lt;p&gt;Your first task in this part of the project is to implement the mechanism by
which colors are selected for the fill pattern. To do this, you will create
function objects (or &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Function_object&#34;&gt;functors&lt;/a&gt;&amp;rdquo;) which will be passed into the fill algorithm
and applied to pixels in a &lt;code&gt;PNG&lt;/code&gt;. Specifically you will be making two new
functors, each of which will be derived classes of the abstract base class
called &lt;code&gt;colorPicker&lt;/code&gt;, which is provided and described in the given code file
&lt;code&gt;colorPicker.h&lt;/code&gt;. We have also given you an example functor so you
can see how things are supposed to work. Our functor is called
&lt;code&gt;rainColorPicker&lt;/code&gt;. The &lt;code&gt;colorPicker&lt;/code&gt; base class
has one purely virtual function that you &lt;strong&gt;must&lt;/strong&gt; implement in your
derived classes, but you may add
others if you wish. In particular, you should expect your derived class
constructors to initialize the functor with situation-dependent variables.&lt;/p&gt;

&lt;p&gt;The purpose of any &lt;code&gt;colorPicker&lt;/code&gt; is to take an image coordinate as its &lt;code&gt;(x,y)&lt;/code&gt;
parameters to &lt;code&gt;operator()&lt;/code&gt;, and return the color it would suggest the client
recolor the source &lt;code&gt;PNG&lt;/code&gt; to. So in the examples above, the
&lt;code&gt;colorPicker&lt;/code&gt; is returning rainbow colors, based on the number of iterations in the
fill algorithm.&lt;/p&gt;

&lt;p&gt;Your task is to implement the &lt;code&gt;stripeColorPicker&lt;/code&gt; and &lt;code&gt;borderColorPicker&lt;/code&gt;
and &lt;code&gt;customColorPicker&lt;/code&gt;
function objects. Refer to the given code for implementation details: they
&lt;strong&gt;must&lt;/strong&gt; overwrite the abstract &lt;strong&gt;operator()&lt;/strong&gt;!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;stripeColorPicker&lt;/code&gt;&lt;/strong&gt; The first pattern will be a simple stripe flood fill. Its behavior is
described in the given code, and sample images are given.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;borderColorPicker&lt;/code&gt;&lt;/strong&gt; The second fill pattern will leave most of the region unchanged, but
it will draw a border around the edge of the region. Again, the specification is
described in the given code.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;customColorPicker&lt;/code&gt;&lt;/strong&gt; The third exercise will be a fill pattern of your own creation!! You must create files
&lt;code&gt;customColorPicker.h&lt;/code&gt; and &lt;code&gt;customColorPicker.cpp&lt;/code&gt; to change the pixels in the fill
using some interesting pattern you design. You&amp;rsquo;ll also give us the &lt;code&gt;.gif&lt;/code&gt;
images created by your custom work. Note that we&amp;rsquo;ll leave it to you to figure out
how to change your &lt;code&gt;Makefile&lt;/code&gt;, &lt;code&gt;filler.h&lt;/code&gt;, and &lt;code&gt;filler.cpp&lt;/code&gt; to accommdate the new
color picker.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;the-fill-algorithms&#34;&gt;The Fill Algorithms&lt;/h3&gt;

&lt;p&gt;The animations in the .gif images above are the result of
&lt;strong&gt;breadth-first-search&lt;/strong&gt; (BFS) and &lt;strong&gt;depth-first-search&lt;/strong&gt; (DFS), respectively, both with a rainbow
fill. We have given you the rainbow fill functions as an example for the others.&lt;/p&gt;

&lt;p&gt;You will be implementing both DFS and BFS, each with the
three different fill &lt;code&gt;patterns&lt;/code&gt; described above.&lt;/p&gt;

&lt;p&gt;You must implement &lt;strong&gt;all&lt;/strong&gt; of the functions inside the &lt;code&gt;filler&lt;/code&gt;
namespace. Refer to the documentation in the header file for implementation details.&lt;/p&gt;

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

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;ImageMagick&lt;/strong&gt;
&lt;p&gt;Note that you must have ImageMagick installed if you&amp;rsquo;re developing on your
personal machine. You can test for this requirement by running&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;convert
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;in your terminal. Windows users should visit
&lt;a href=&#34;http://www.imagemagick.org/script/binary-releases.php&#34;&gt;ImageMagick&lt;/a&gt; to
download the latest binary. OSX users can use homebrew or MacPorts to install
it if missing. Linux users likely already have it installed. If not, then you
can install it via your system&amp;rsquo;s package manager.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;We have provided a file &lt;code&gt;testFills.cpp&lt;/code&gt; which includes several test cases that
your code should pass if it is correct. To compile this executable, type:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;make testFills
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will create executable &lt;code&gt;testFills&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One important thing to note about this PA is that the &lt;code&gt;.gif&lt;/code&gt; compression may
take some time. In general, on the remote machines via &lt;code&gt;ssh&lt;/code&gt;,
the solution code runs in somewhere from 5-20 seconds when all the tests are
enabled and completed and the server is under a light load. It is advisable to
comment out the tests for things you have already completed, so that you don&amp;rsquo;t
have to wait as long (and use the CPU up) for things you already did. That
said, the main point is that if you code doesn&amp;rsquo;t finish immediately don&amp;rsquo;t fret.
Also note that as more traffic is happening on the server things will slow
down. This may be an incentive to not wait until the last minute and have to
try to run your code when everyone else is too!&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;testFills&lt;/code&gt; program will generate images and animated gifs in the &lt;code&gt;images/&lt;/code&gt;
folder, which can be diffed with the solution images in &lt;code&gt;soln_images/&lt;/code&gt;. For
animated gifs, the frames making up the animation are placed in &lt;code&gt;frames/&lt;/code&gt;, and
can be diffed with their corresponding expected frames in &lt;code&gt;soln_frames/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can check your color picker outputs by redirecting &lt;code&gt;testFills&lt;/code&gt;&amp;rsquo; output to a
file and &lt;code&gt;diff&lt;/code&gt;ing that with our solution output:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;./testFills all &amp;gt; testFills.out
diff testFills.out soln_testFills.out
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can also diff each frame created for the animation, which will probably be
useful for debugging:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;diff frames/bfssolid00.png soln_frames/bfssolid00.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These test cases are deliberately insufficient. We encourage you to augment
this file with additional test cases, using the provided ones as examples.&lt;/p&gt;

&lt;h2 id=&#34;handing-in-your-code&#34;&gt;Handing in Your Code&lt;/h2&gt;

&lt;p&gt;To facilitate anonymous grading, &lt;strong&gt;do not&lt;/strong&gt; include any personally-identifiable
information in any of your source
files. Instead, before you hand in this assignment, create a file called
&lt;code&gt;partners.txt&lt;/code&gt; that contains only the CSIDs of people in your collaboration
group (if it exists), one per line. If you worked alone, include only your own
CSID in this file. We will be automatically processing this information, so do
not include anything else in the file. If we must manually correct your
submission, you may lose points. As always, if you&amp;rsquo;re working in a group, each
group member must hand in the assignment. Failure to cite collaborators
violates our academic integrity policy; we will be aggressively pursuing such
violators.&lt;/p&gt;

&lt;p&gt;You will submit your work to &lt;a href=&#34;https://www.gradescope.com/courses/33829&#34;&gt;gradeScope&lt;/a&gt; as you did for PA1.&lt;/p&gt;

&lt;h2 id=&#34;grading-information&#34;&gt;Grading Information&lt;/h2&gt;

&lt;p&gt;The following files are used to grade PA 2:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;deque.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stack.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;queue.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stripeColorPicker.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stripeColorPicker.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;borderColorPicker.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;borderColorPicker.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;customColorPicker.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;customColorPicker.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;filler.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;filler.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;customDFS.gif&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;customBFS.gif&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;partners.txt&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All other files will not be used for grading.&lt;/p&gt;

&lt;h2 id=&#34;good-luck&#34;&gt;Good luck!&lt;/h2&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Homework 2</title>
      <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/h2/</link>
      <pubDate>Sun, 27 Jan 2019 12:00:00 +0000</pubDate>
      
      <guid>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/h2/</guid>
      <description>

&lt;p&gt;Link to document: &lt;a href=&#34;https://www.overleaf.com/read/gsvmbrhwhyps&#34;&gt;hw2 overleaf&lt;/a&gt;
 | &lt;a href=&#34;cpsc221_2018W2_HW2_samplesoln.pdf&#34;&gt;solutions&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;instructions-for-hw2&#34;&gt;Instructions for HW2&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;This homework assignment allows you to work with a partner&lt;/strong&gt;! Please submit
only one copy of your work for the partnership. GradeScope allows you to
identify both members of the pair upon submission.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;legible&lt;/strong&gt; pdf of your solution must be checked in to &lt;a href=&#34;https://gradescope.com/courses/33829&#34;&gt;GradeScope&lt;/a&gt;
by the deadline.&lt;/p&gt;

&lt;h3 id=&#34;using-overleaf&#34;&gt;Using Overleaf&lt;/h3&gt;

&lt;p&gt;Assignments will be distributed via Overleaf, an online latex editor. Before you begin,
create an account and log in to Overleaf, then return to this page to link to the document. The initial document is read-only, so you&amp;rsquo;ll have to click on the up-arrow in the upper left corner of the screen to bring up your Overleaf dashboard. Then you can make a copy of the homework and begin to craft your solutions.  We recommend that you use the Overleaf editor to typeset
    your answers to the problems. Then, when you&amp;rsquo;re finished, download your completed assignment as
    a .pdf, and upload it to Gradescope. (Detailed instructrions below.)&lt;/p&gt;

&lt;p&gt;Latex is a powerful and popular typsetting package, commonly used for documents that have
    sophisticated diagrams and figures (like math and code!). The learning curve for fluency in Latex
    is fairly steep, but it&amp;rsquo;s a valuable skill, so we&amp;rsquo;re asking you to try to use it to compose your
    homework solutions. We are assisting your learning in three specific ways: 1) the homework&amp;rsquo;s latex source code
    contains examples of most of the tags you will need in your answers, 2) we are happy to answer any of your latex questions on piazza,
    and 3) the Overleaf web
    site has several short tutorials and videos to give you an overview of the kinds of things you can do.
    Like every latex user EVER, you will find
    google to be your best source of technical assistance.&lt;/p&gt;

&lt;h3 id=&#34;marking-on-gradescope&#34;&gt;Marking on Gradescope&lt;/h3&gt;

&lt;p&gt;Assignments will be collected and graded on [Gradescope]((&lt;a href=&#34;https://gradescope.com/courses/33829&#34;&gt;https://gradescope.com/courses/33829&lt;/a&gt;). You will access GradeScope using your
    csid. We will be preloading the course roster into GradeScope, after which you will be
    able to log in.&lt;/p&gt;

&lt;p&gt;NOTE: You will be required to follow the instructions below for submitting your assignments on Gradescope. The overall goal is for you to tell us, via the interface, where each of the problem parts appears on your submission. You MUST align the regions for every problem, even if your homeworks solution isn&amp;rsquo;t complete. We will not be able to mark any problem we can&amp;rsquo;t find.&lt;/p&gt;

&lt;p&gt;Log in to Gradescope using your csid. Navigate to HW1 and follow the instructions to submit a pdf.&lt;/p&gt;

&lt;p&gt;Then follow the instructions found here: &lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/info/gs-submission/&#34;&gt;Gradescope Submission Guidelines&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;group-work&#34;&gt;Group Work&lt;/h3&gt;

&lt;p&gt;We highly encourage you to do assignments in groups of two,
    though you may work alone if you choose. Groups larger than two
    students are not allowed. Only one Gradescope submission is expected for each
    group. Be sure to identify your group on Gradescope.&lt;/p&gt;

&lt;h3 id=&#34;marking&#34;&gt;Marking&lt;/h3&gt;

&lt;p&gt;As a rule of thumb,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A solution to a question that is correct, complete, and legible will be worth full marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A legible solution that contains some errors or is not quite complete, but shows a
clear grasp of how the concepts and techniques required apply to this problem, will be
worth about 66% of the marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A  legible solution  that is  either correct  but difficult  to read,  or contains
errors or  is not complete,  but shows  a clear grasp  of the concepts  and techniques
required, although not  their application to this problem, will be  worth about 33% of
the marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A solution that contains substantial errors, is far from complete, does not show a
clear grasp of the concepts and techniques required, or is illegible will receive very
few marks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This  marking scheme reflects  our intent  for you  to learn  the key  concepts and
    techniques  underlying  computation,  determine  where  they  apply,  and  apply  them
    correctly  to  interesting  problems. It  also  reflects  a  practical fact:  we  have
    insufficient time to decipher illegible answers. All typeset solutions will be considered
    legible.&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>PA1</title>
      <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/p1/</link>
      <pubDate>Fri, 11 Jan 2019 12:00:00 +0000</pubDate>
      
      <guid>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/p1/</guid>
      <description>

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;Lab machines&lt;/strong&gt;
&lt;p&gt;We will be grading the PAs for this course using the remote Linux machines. Any
errors that you run into as a result of developing your code on &lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/resources/own-machine/&#34;&gt;other
machines&lt;/a&gt; are your own responsibility.&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;goals-and-overview&#34;&gt;Goals and Overview&lt;/h2&gt;

&lt;p&gt;In this PA (Programming Assignment) you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;learn about the course programming environment&lt;/li&gt;
&lt;li&gt;learn about vectors&lt;/li&gt;
&lt;li&gt;learn about pointers&lt;/li&gt;
&lt;li&gt;learn about linked lists&lt;/li&gt;
&lt;li&gt;learn about management of dynamic memory&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;the-assignment-part-1-reading-and-understanding-the-policies&#34;&gt;The Assignment, Part 1: Reading and Understanding the Policies&lt;/h2&gt;

&lt;p&gt;Read and understand the following information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/info/syllabus/&#34;&gt;Course Info&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/info/collaboration/&#34;&gt;Collaboration Policy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/info/style/&#34;&gt;Coding Style Policy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;alert alert-warning&#34;&gt;
    &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;24&#34; height=&#34;24&#34; viewBox=&#34;0 0 24 24&#34;&gt;&lt;path d=&#34;M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z&#34;/&gt;&lt;/svg&gt;
    &lt;strong&gt;Important Information&lt;/strong&gt;
&lt;p&gt;The information in these links is relevant to not just this PA, but every
future PA as well, and you &lt;strong&gt;will&lt;/strong&gt; be held responsible for having read and
understood all of the information. So, part of this PA assignment is to read
over this part 1 material, and to gain a complete understanding of it before
moving on to part 2 of this assignment. This means that you should ASK
QUESTIONS ON ANY OF THIS PART 1 MATERIAL THAT YOU DO NOT UNDERSTAND.&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;the-assignment-part-2-coding&#34;&gt;The Assignment, Part 2: Coding&lt;/h2&gt;

&lt;h3 id=&#34;problem-specification&#34;&gt;Problem Specification&lt;/h3&gt;

&lt;p&gt;A Linked List is a dynamic linear structure designed to hold any
type of data. In this exercise, we develop and use a
linked list to manipulate blocks of pixels from an image.&lt;/p&gt;

&lt;p&gt;We have broken the image below into 6 &lt;code&gt;Block&lt;/code&gt;s.&lt;/p&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;PA1pic1.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;Each &lt;code&gt;Block&lt;/code&gt; is placed into a &lt;code&gt;Node&lt;/code&gt; of a &lt;code&gt;Chain&lt;/code&gt;, as shown here:&lt;/p&gt;

&lt;figure  style=&#34;text-align: center;&#34;&gt;
    
    &lt;img
        src=&#34;PA1pic2.png&#34;
        
        
        /&gt;
    
    
&lt;/figure&gt;

&lt;p&gt;The &lt;code&gt;Chain&lt;/code&gt; can be rearranged, and the image reassembled to create fascinating visual results.&lt;/p&gt;

&lt;p&gt;We have provided a starting point for achieving this functionality. It is your task to complete and expand on
our implementation.&lt;/p&gt;

&lt;p&gt;Specifications for each function you write are contained in the
given code. The list of functions here should serve as a
checklist for completing the exercise.&lt;/p&gt;

&lt;h4 id=&#34;in-block-cpp&#34;&gt;In &lt;code&gt;block.cpp&lt;/code&gt;&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;int width() const;&lt;/code&gt; Returns the width of the current block.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int height() const;&lt;/code&gt; Returns the height of the current block.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void build(PNG &amp;amp; im, int column, int width);&lt;/code&gt; From &lt;code&gt;im&lt;/code&gt;, grabs the
vertical strip of pixels whose upper left corner is at position &lt;code&gt;(column,0)&lt;/code&gt;,
and whose width is &lt;code&gt;width&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void render(PNG &amp;amp; im, int column ) const;&lt;/code&gt; Draws the current block at position (&lt;code&gt;column&lt;/code&gt;,&lt;code&gt;0&lt;/code&gt;) in &lt;code&gt;im&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void greyscale();&lt;/code&gt; This function changes the saturation of every pixel in the block to 0, which removes the color, leaving grey.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;in-chain-cpp&#34;&gt;In &lt;code&gt;chain.cpp&lt;/code&gt;&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;void clear();&lt;/code&gt; Helper function for destructor and assignment operator.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void copy(const Chain &amp;amp; other);&lt;/code&gt; Helper function for copy constructor and assignment operator.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;~Chain();&lt;/code&gt; Destructor.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void insertBack(const Block &amp;amp; ndata);&lt;/code&gt; Insert a new node at the end of the &lt;code&gt;Chain&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void moveBack(int startPos, int len, int dist);&lt;/code&gt; Move &lt;code&gt;len&lt;/code&gt; nodes from &lt;code&gt;startPos&lt;/code&gt; toward the end of the &lt;code&gt;Chain&lt;/code&gt;, shifting by &lt;code&gt;dist&lt;/code&gt; positions.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void roll(int k);&lt;/code&gt; Move &lt;code&gt;k&lt;/code&gt; nodes from the end of the &lt;code&gt;Chain&lt;/code&gt; to the front. Their order does not change.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void reverseSub(int pos1, int pos2);&lt;/code&gt; Reverses the order of the nodes in the chain from &lt;code&gt;pos1&lt;/code&gt; to &lt;code&gt;pos2&lt;/code&gt;, inclusive.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void weave(Chain &amp;amp; other);&lt;/code&gt; consumes the nodes in &lt;code&gt;other&lt;/code&gt; placing them in alternating positions in the current &lt;code&gt;Chain&lt;/code&gt;. In the final chain, the original &lt;code&gt;Chain&lt;/code&gt; will occupy the odd nodes, and the nodes from &lt;code&gt;other&lt;/code&gt; will be in the even positions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;implementation-constraints-and-advice&#34;&gt;Implementation Constraints and Advice&lt;/h3&gt;

&lt;p&gt;We will be grading your work on functionality, efficiency, and memory use. All &lt;code&gt;Chain&lt;/code&gt; functionality, aside from the insert and the copy functions, can be achieved by moving existing nodes, rather than by allocating new ones and/or making copies. If you are tempted to use the &lt;code&gt;new&lt;/code&gt; function when you are manipulating the &lt;code&gt;Chain&lt;/code&gt;, ask yourself if you can achieve your goal by reassigning pointers, instead.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Chain&lt;/code&gt; structure is a circular doubly-linked list with one head
sentinel. The sentinel is simply a place-holding &lt;code&gt;Node&lt;/code&gt;, whose purpose
is to define the start (and end) of the list.  An empty list is simply
a sentinel node whose &lt;code&gt;next&lt;/code&gt; and &lt;code&gt;prev&lt;/code&gt; pointers both point to
itself.  This creates a simplifying invariant: every &lt;code&gt;Node&lt;/code&gt; containing
data is guaranteed to have a node both before and after it. This
invariant eliminates the special cases typically associated with the
front and end of lists, thereby reducing the number of conditionals in
your code. In our solution for &lt;code&gt;chain.cpp&lt;/code&gt;, we have fewer than 3
conditionals involving pointers!&lt;/p&gt;

&lt;p&gt;Finally, you&amp;rsquo;ll note that we are asking you to implement special memory management functions for the &lt;code&gt;Chain&lt;/code&gt; class. You should ask yourself why we have not made similar requests for the &lt;code&gt;Block&lt;/code&gt; class. Why doesn&amp;rsquo;t it need a destructor, copy constructor, or assignment operator?&lt;/p&gt;

&lt;h3 id=&#34;getting-the-given-code&#34;&gt;Getting the Given Code&lt;/h3&gt;

&lt;p&gt;Download the source files from &lt;a href=&#34;pa1.zip&#34;&gt;pa1.zip&lt;/a&gt;, and follow the
procedures you learned in lab to move them to your home directory
on the remote linux machines.&lt;/p&gt;

&lt;h3 id=&#34;handing-in-your-code&#34;&gt;Handing in your code&lt;/h3&gt;

&lt;p&gt;To facilitate anonymous grading, &lt;strong&gt;do not&lt;/strong&gt; include any personally-identifiable
information (like your name, your University ID number, or your cwl) in any
of your source files. Instead, before you hand in this assignment,
create a file called &lt;code&gt;partners.txt&lt;/code&gt; that contains only the CSIDs of
people in your collaboration partnership (if one exists), one per line.
If you worked alone, include only your own
CSID in this file. We will be automatically processing this information, so do
not include anything else in the file. (If we must manually correct your
submission, you may lose points.) As always, if you&amp;rsquo;re working in a group, each
group member must hand in the assignment. (Failure to cite collaborators
violates our academic integrity policy;)&lt;/p&gt;

&lt;p&gt;The following files are used to grade PA1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;block.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;chain.cpp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;chain.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;partners.txt&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All other files will not be used for grading.&lt;/p&gt;

&lt;p&gt;Detailed instructions for handing in your work will be added to
this page within the next few days.&lt;/p&gt;

&lt;h2 id=&#34;good-luck&#34;&gt;Good luck!&lt;/h2&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Homework 1</title>
      <link>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/h1/</link>
      <pubDate>Fri, 04 Jan 2019 08:00:00 +0000</pubDate>
      
      <guid>https://www.students.cs.ubc.ca/~cs-221/2018W2/mps/h1/</guid>
      <description>

&lt;p&gt;Link to document: &lt;a href=&#34;https://www.overleaf.com/read/gcxddgjjvjdm&#34;&gt;hw1 overleaf&lt;/a&gt;
 | &lt;a href=&#34;cpsc221_2018W2_HW1_draft_soln.pdf&#34;&gt;solutions&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;instructions-for-hw1&#34;&gt;Instructions for HW1&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;This homework assignment allows you to work with a partner&lt;/strong&gt;! Please submit
only one copy of your work for the partnership. GradeScope allows you to
identify both members of the pair upon submission.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;legible&lt;/strong&gt; pdf of your solution must be checked in to &lt;a href=&#34;https://gradescope.com/courses/33829&#34;&gt;GradeScope&lt;/a&gt;
by the deadline.&lt;/p&gt;

&lt;h3 id=&#34;using-overleaf&#34;&gt;Using Overleaf&lt;/h3&gt;

&lt;p&gt;Assignments will be distributed via Overleaf, an online latex editor. Before you begin,
create an account and log in to Overleaf, then return to this page to link to the document. The initial document is read-only, so you&amp;rsquo;ll have to click on the up-arrow in the upper left corner of the screen to bring up your Overleaf dashboard. Then you can make a copy of the homework and begin to craft your solutions.  We recommend that you use the Overleaf editor to typeset
    your answers to the problems. Then, when you&amp;rsquo;re finished, download your completed assignment as
    a .pdf, and upload it to Gradescope. (Detailed instructrions below.)&lt;/p&gt;

&lt;p&gt;Latex is a powerful and popular typsetting package, commonly used for documents that have
    sophisticated diagrams and figures (like math and code!). The learning curve for fluency in Latex
    is fairly steep, but it&amp;rsquo;s a valuable skill, so we&amp;rsquo;re asking you to try to use it to compose your
    homework solutions. We are assisting your learning in three specific ways: 1) the homework&amp;rsquo;s latex source code
    contains examples of most of the tags you will need in your answers, 2) we are happy to answer any of your latex questions on piazza,
    and 3) the Overleaf web
    site has several short tutorials and videos to give you an overview of the kinds of things you can do.
    Like every latex user EVER, you will find
    google to be your best source of technical assistance.&lt;/p&gt;

&lt;h3 id=&#34;marking-on-gradescope&#34;&gt;Marking on Gradescope&lt;/h3&gt;

&lt;p&gt;Assignments will be collected and graded on [Gradescope]((&lt;a href=&#34;https://gradescope.com/courses/33829&#34;&gt;https://gradescope.com/courses/33829&lt;/a&gt;). You will access GradeScope using your
    csid. We will be preloading the course roster into GradeScope, after which you will be
    able to log in.&lt;/p&gt;

&lt;p&gt;NOTE: You will be required to follow the instructions below for submitting your assignments on Gradescope. The overall goal is for you to tell us, via the interface, where each of the problem parts appears on your submission. You MUST align the regions for every problem, even if your homeworks solution isn&amp;rsquo;t complete. We will not be able to mark any problem we can&amp;rsquo;t find.&lt;/p&gt;

&lt;p&gt;Log in to Gradescope using your csid. Navigate to HW1 and follow the instructions to submit a pdf.&lt;/p&gt;

&lt;p&gt;Then follow the instructions found here: &lt;a href=&#34;https://www.students.cs.ubc.ca/~cs-221/2018W2/~cs-221/2018W2/info/gs-submission/&#34;&gt;Gradescope Submission Guidelines&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;group-work&#34;&gt;Group Work&lt;/h3&gt;

&lt;p&gt;We highly encourage you to do assignments in groups of two,
    though you may work alone if you choose. Groups larger than two
    students are not allowed. Only one Gradescope submission is expected for each
    group. Be sure to identify your group on Gradescope.&lt;/p&gt;

&lt;h3 id=&#34;marking&#34;&gt;Marking&lt;/h3&gt;

&lt;p&gt;As a rule of thumb,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A solution to a question that is correct, complete, and legible will be worth full marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A legible solution that contains some errors or is not quite complete, but shows a
clear grasp of how the concepts and techniques required apply to this problem, will be
worth about 66% of the marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A  legible solution  that is  either correct  but difficult  to read,  or contains
errors or  is not complete,  but shows  a clear grasp  of the concepts  and techniques
required, although not  their application to this problem, will be  worth about 33% of
the marks.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A solution that contains substantial errors, is far from complete, does not show a
clear grasp of the concepts and techniques required, or is illegible will receive very
few marks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This  marking scheme reflects  our intent  for you  to learn  the key  concepts and
    techniques  underlying  computation,  determine  where  they  apply,  and  apply  them
    correctly  to  interesting  problems. It  also  reflects  a  practical fact:  we  have
    insufficient time to decipher illegible answers. All typeset solutions will be considered
    legible.&lt;/p&gt;
</description>
    </item>
    
    
    
    
  </channel>
</rss>
