{"id":403,"date":"2015-03-16T12:00:01","date_gmt":"2015-03-16T19:00:01","guid":{"rendered":"https:\/\/blogs.ubc.ca\/cpsc320\/?p=403"},"modified":"2015-03-16T12:00:01","modified_gmt":"2015-03-16T19:00:01","slug":"tutorial-7-problems","status":"publish","type":"post","link":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/2015\/03\/16\/tutorial-7-problems\/","title":{"rendered":"Tutorial #7 Problems"},"content":{"rendered":"<p>Provide a recurrence relation for the quantity described in each of the following problems. For each one, also indicate either a memoized or dynamic programming approach to solving the recurrence and analyse its efficiency. (Do DP at least once. Remember that it&#8217;s the harder one because you must order the subproblems &#8220;manually&#8221; and so worth a bit of extra practice.)<\/p>\n<ol>\n<li>Let <i>G = (V, E)<\/i> be an undirected graph with <i>n<\/i> nodes. A subset of the nodes is called an <em>independent set<\/em> if no two of them are joined by an edge. Finding large independent sets is difficult in general, but it can be done efficiently if the graph is simple enough.\n<p>Let us call the graph <i>G<\/i> a <em>path<\/em> if its nodes can be written as <i>v<sub>0<\/sub>, v<sub>1<\/sub>, &#8230;, v<sub>n-1<\/sub><\/i> with an edge between <i>v<sub>i<\/sub><\/i> and <i>v<sub>j<\/sub><\/i> if and only if the numbers <i>i<\/i> and <i>j<\/i> are consecutive. With each node\u00a0<i>v<sub>i<\/sub><\/i> we associate a positive integer <em>weight<\/em> <i>w<sub>i<\/sub><\/i>. For example, in the following path, the weights are the numbers drawn inside the nodes.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.ugrad.cs.ubc.ca\/~cs320\/2014W1\/tutorials\/path-graph.png\" alt=\"\" \/><\/p>\n<p>Define recurrence relations for<\/p>\n<ul>\n<li><i>With[i]<\/i>: the maximum sum we can obtain using non-consecutive elements from <i>v<sub>0<\/sub>, &#8230;, v<sub>i<\/sub><\/i>, including the element <i>v<sub>i<\/sub><\/i> in the sum.<\/li>\n<li><i>Without[i]<\/i>: the maximum sum we can obtain using non-consecutive elements from <i>v<sub>0<\/sub>, &#8230;, v<sub>i<\/sub><\/i>, without including the element <i>v<sub>i<\/sub><\/i> in the sum.<\/li>\n<\/ul>\n<\/li>\n<li>There are many sunny Spring days in Vancouver. Unfortunately, this year, it is raining on the day of the CSSS (CS student society) boat cruise and dinner. The CSSS president decides to rebook the cruise for another day, and needs to contact everybody who has made reservations. Luckily, every student made his\/her reservation by talking to another student who had already made his\/hers. That is, the students who have reservations for the cruise form a tree, whose root is the CSSS president!\n<p>To notify everyone of the postponement, the CSSS president first calls each of the students who bought their tickets directly from him\/her, one at a time (his\/her &#8220;children&#8221;). As soon as one of these students has been notified, he\/she can then notify all of his\/her &#8220;children&#8221;.<\/p>\n<p>We can picture this process as being divided into rounds. In one round, each person who has already learned of the postponement can call one of his\/her children. The number of rounds it takes for everyone to be notified depends on the sequence in which each person makes their phone calls. For instance, in the following figure, it will take only two rounds if <i>A<\/i> calls <i>B<\/i> first, but three rounds if <i>A<\/i> starts by calling <i>D<\/i> (note that <i>A<\/i> can not call <i>C<\/i> directly).<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.ugrad.cs.ubc.ca\/~cs320\/2014W1\/tutorials\/broadcast.png\" alt=\"\" \/><\/p>\n<p>Write a recurrence relation for <i>R(N)<\/i>, the minimum number of rounds needed to inform all descendants of a node <i>N<\/i>.<\/li>\n<li>As some of you know well, and others of you may be interested to learn, a number of languages (including Chinese and Janapese) are written without spaces between the words. Consequently, software that works with text written in these languages must address the <em>word segmentation<\/em> problem: inferring likely boundaries between consecutive words in the text. If English were written without spaces, the analogous problem would consist of taking a string like &#8220;meetaeight&#8221; and deciding that the best segmentation is &#8220;meet at eight&#8221; (and not &#8220;me et at eight&#8221;, or &#8220;meet ate ight&#8221;, or any of the huge number of even less plausible alternatives). How could we automate this process?A simple approach that is at least reasonably effective is to find a segmentation that simply maximizes the cumulative &#8220;quality&#8221; of its individual constituent words. Thus, suppose you are given a black box that for any string of letters <i>x = x<sub>0<\/sub>, x<sub>1<\/sub>, &#8230;, x<sub>k<\/sub><\/i> will return a number <i>Q(x)<\/i>. This number can be either positive or negative; larger numbers correspond to more plausible English words. So <i>Q(me)<\/i> would be positive, while <i>Q(ght)<\/i> would be negative.\n<p>Given a long string of letters <i>y = y<sub>0<\/sub>, y<sub>1<\/sub>, &#8230;, y<sub>n-1<\/sub><\/i>, a segmentation of <i>y<\/i> is a partition of its letters into contiguous blocks of letters; each block corresponds to a word in the segmentation. The <em>total quality<\/em> of a segmentation is determined by adding up the qualities of each of its blocks. So we would get the right answer for the problem above provided that <i>Q(meet) + Q(at) + Q(eight)<\/i> was greater than the total quality of any other segmentation of the string.<\/p>\n<p>Give a recurrence relation for <i>TQ(i)<\/i>: the maximum total quality of any segmentation of the letters <i>y<sub>0<\/sub>, y<sub>1<\/sub>, &#8230;, y<sub>i<\/sub><\/i>. Hint: look for the position of the first letter of the current &#8220;word&#8221;.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Provide a recurrence relation for the quantity described in each of the following problems. For each one, also indicate either a memoized or dynamic programming approach to solving the recurrence and analyse its efficiency. (Do DP at least once. Remember that it&#8217;s the harder one because you must order the subproblems &#8220;manually&#8221; and so worth [&hellip;]<\/p>\n","protected":false},"author":7560,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3426],"tags":[],"class_list":["post-403","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/posts\/403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/users\/7560"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":0,"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/cpsc3202014w2\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}