<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://algorist.com/algowiki_v2/index.php?action=history&amp;feed=atom&amp;title=Divide-TADM2E</id>
		<title>Divide-TADM2E - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://algorist.com/algowiki_v2/index.php?action=history&amp;feed=atom&amp;title=Divide-TADM2E"/>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;action=history"/>
		<updated>2026-04-30T19:18:56Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;diff=211&amp;oldid=prev</id>
		<title>Algowikiadmin: Protected &quot;Divide-TADM2E&quot; ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;diff=211&amp;oldid=prev"/>
				<updated>2014-09-11T18:43:39Z</updated>
		
		<summary type="html">&lt;p&gt;Protected &amp;quot;&lt;a href=&quot;/algowiki_v2/index.php/Divide-TADM2E&quot; title=&quot;Divide-TADM2E&quot;&gt;Divide-TADM2E&lt;/a&gt;&amp;quot; ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 18:43, 11 September 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Algowikiadmin</name></author>	</entry>

	<entry>
		<id>https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;diff=172&amp;oldid=prev</id>
		<title>Algowikiadmin: Recovering wiki</title>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;diff=172&amp;oldid=prev"/>
				<updated>2014-09-11T18:23:45Z</updated>
		
		<summary type="html">&lt;p&gt;Recovering wiki&lt;/p&gt;
&lt;a href=&quot;https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;amp;diff=172&amp;amp;oldid=92&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Algowikiadmin</name></author>	</entry>

	<entry>
		<id>https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;diff=92&amp;oldid=prev</id>
		<title>Algowikiadmin: Recovering wiki</title>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=Divide-TADM2E&amp;diff=92&amp;oldid=prev"/>
				<updated>2014-09-11T18:14:08Z</updated>
		
		<summary type="html">&lt;p&gt;Recovering wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Dynamic Programming =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Edit Distance'''&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-1. &lt;br /&gt;
Typists often make transposition errors exchanging&lt;br /&gt;
neighboring characters, such as typing ''setve'' when you mean ''steve.''&lt;br /&gt;
This requires two substitutions to fix under the conventional definition&lt;br /&gt;
of edit distance.&lt;br /&gt;
Incorporate a swap operation into our edit distance function,&lt;br /&gt;
so that such neighboring transposition errors can be fixed at the&lt;br /&gt;
cost of one operation.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.1|(Solution 8.1)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-2. &lt;br /&gt;
Suppose you are given three strings of characters: &amp;amp;lt;math&amp;amp;gt;X&amp;amp;lt;/math&amp;amp;gt;, &amp;amp;lt;math&amp;amp;gt;Y&amp;amp;lt;/math&amp;amp;gt;, and &amp;amp;lt;math&amp;amp;gt;Z&amp;amp;lt;/math&amp;amp;gt;,&lt;br /&gt;
where &amp;amp;lt;math&amp;amp;gt;|X| = n&amp;amp;lt;/math&amp;amp;gt;, &amp;amp;lt;math&amp;amp;gt;|Y|=m&amp;amp;lt;/math&amp;amp;gt;, and &amp;amp;lt;math&amp;amp;gt;|Z|=n+m&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;Z&amp;amp;lt;/math&amp;amp;gt; is said to be a ''shuffle''&lt;br /&gt;
of &amp;amp;lt;math&amp;amp;gt;X&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;Y&amp;amp;lt;/math&amp;amp;gt; iff &amp;amp;lt;math&amp;amp;gt;Z&amp;amp;lt;/math&amp;amp;gt; can be formed by interleaving the characters from &amp;amp;lt;math&amp;amp;gt;X&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
and &amp;amp;lt;math&amp;amp;gt;Y&amp;amp;lt;/math&amp;amp;gt; in a way that maintains the left-to-right ordering of the characters&lt;br /&gt;
from each string.&lt;br /&gt;
#Show that ''cchocohilaptes'' is a shuffle of ''chocolate'' and ''chips'', but ''chocochilatspe'' is not.&lt;br /&gt;
#Give an efficient dynamic-programming algorithm that determines whether &amp;amp;lt;math&amp;amp;gt;Z&amp;amp;lt;/math&amp;amp;gt; is a shuffle of &amp;amp;lt;math&amp;amp;gt;X&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;Y&amp;amp;lt;/math&amp;amp;gt;. Hint: the values of the dynamic programming matrix you construct should be Boolean, not numeric.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-3. &lt;br /&gt;
The longest common ''substring'' (not subsequence) of two strings &amp;amp;lt;math&amp;amp;gt;X&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;Y&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
is the longest string that appears as a run of consecutive letters&lt;br /&gt;
in both strings.&lt;br /&gt;
For example, the longest common substring of&lt;br /&gt;
''photograph'' and ''tomography'' is ''ograph''.&lt;br /&gt;
#Let &amp;amp;lt;math&amp;amp;gt;n=|X|&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;m=|Y|&amp;amp;lt;/math&amp;amp;gt;. Give a &amp;amp;lt;math&amp;amp;gt;\Theta(nm)&amp;amp;lt;/math&amp;amp;gt; dynamic programming algorithm for longest common substring based on the longest common subsequence/edit distance algorithm.&lt;br /&gt;
#Give a simpler &amp;amp;lt;math&amp;amp;gt;\Theta(nm)&amp;amp;lt;/math&amp;amp;gt; algorithm that does not rely on dynamic programming.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.3|(Solution 8.3)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-4. &lt;br /&gt;
The ''longest common subsequence (LCS)''&lt;br /&gt;
of two sequences &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;P&amp;amp;lt;/math&amp;amp;gt; is the longest&lt;br /&gt;
sequence &amp;amp;lt;math&amp;amp;gt;L&amp;amp;lt;/math&amp;amp;gt; such that &amp;amp;lt;math&amp;amp;gt;L&amp;amp;lt;/math&amp;amp;gt; is a subsequence of both &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;P&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
The ''shortest common supersequence (SCS)'' of &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;P&amp;amp;lt;/math&amp;amp;gt; is the smallest sequence &amp;amp;lt;math&amp;amp;gt;L&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
such that both &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;P&amp;amp;lt;/math&amp;amp;gt; are a subsequence of &amp;amp;lt;math&amp;amp;gt;L&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
#Give efficient algorithms to find the LCS and SCS of two given sequences.&lt;br /&gt;
#Let &amp;amp;lt;math&amp;amp;gt;d(T,P)&amp;amp;lt;/math&amp;amp;gt; be the minimum edit distance between &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;P&amp;amp;lt;/math&amp;amp;gt; when no substitutions are allowed (i.e., the only changes are character insertion and deletion). Prove that &amp;amp;lt;math&amp;amp;gt;d(T,P)=|SCS(T,P)|-|LCS(T,P)|&amp;amp;lt;/math&amp;amp;gt; where &amp;amp;lt;math&amp;amp;gt;|SCS(T,P)|&amp;amp;lt;/math&amp;amp;gt; (&amp;amp;lt;math&amp;amp;gt;|LCS(T,P)|&amp;amp;lt;/math&amp;amp;gt;) is the size of the shortest &amp;amp;lt;math&amp;amp;gt;SCS&amp;amp;lt;/math&amp;amp;gt; (longest LCS) of &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;P&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Greedy Algorithms'''&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-5. &lt;br /&gt;
Let &amp;amp;lt;math&amp;amp;gt;P_1 ,P_2, \ldots, P_n&amp;amp;lt;/math&amp;amp;gt; be &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; programs to be stored on a disk&lt;br /&gt;
with capacity &amp;amp;lt;math&amp;amp;gt;D&amp;amp;lt;/math&amp;amp;gt; megabytes.&lt;br /&gt;
Program &amp;amp;lt;math&amp;amp;gt;P_i&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
requires &amp;amp;lt;math&amp;amp;gt;s_i&amp;amp;lt;/math&amp;amp;gt; megabytes of storage.&lt;br /&gt;
We cannot store them all because &amp;amp;lt;math&amp;amp;gt;D &amp;amp;lt; \sum_{i=1}^n s_i&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
#Does a greedy algorithm that selects programs in order of nondecreasing &amp;amp;lt;math&amp;amp;gt;s_i&amp;amp;lt;/math&amp;amp;gt; maximize the number of programs held on the disk? Prove or give a counter-example.&lt;br /&gt;
#Does a greedy algorithm that selects programs in order of nonincreasing order &amp;amp;lt;math&amp;amp;gt;s_i&amp;amp;lt;/math&amp;amp;gt; use as much of the capacity of the disk as possible? Prove or give a counter-example.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.5|(Solution 8.5)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-6. &lt;br /&gt;
Coins in the United States are minted with denominations of&lt;br /&gt;
1, 5, 10, 25, and 50 cents.&lt;br /&gt;
Now consider a country whose coins are minted with&lt;br /&gt;
denominations of &amp;amp;lt;math&amp;amp;gt;\{d_1, \ldots, d_k \}&amp;amp;lt;/math&amp;amp;gt; units.&lt;br /&gt;
We seek an algorithm to make change of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; units&lt;br /&gt;
using the minimum number of coins for this country.&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;&lt;br /&gt;
(a)  The greedy algorithm repeatedly selects the biggest coin&lt;br /&gt;
no bigger than the amount to be changed and repeats until it is zero.&lt;br /&gt;
Show that the greedy algorithm does not always use the minimum number of&lt;br /&gt;
coins in a country whose denominations are &amp;amp;lt;math&amp;amp;gt;\{1,6,10\}&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;&lt;br /&gt;
(b)  Give an efficient algorithm that correctly determines the minimum number&lt;br /&gt;
of coins needed to make change of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; units using&lt;br /&gt;
denominations &amp;amp;lt;math&amp;amp;gt;\{d_1, \ldots, d_k \}&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Analyze its running time.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-7. &lt;br /&gt;
In the United States, coins are minted with denominations of&lt;br /&gt;
1, 5, 10, 25, and 50 cents.&lt;br /&gt;
Now consider a country whose coins are minted with&lt;br /&gt;
denominations of &amp;amp;lt;math&amp;amp;gt;\{d_1, \ldots, d_k \}&amp;amp;lt;/math&amp;amp;gt; units.&lt;br /&gt;
We want to count how many distinct ways &amp;amp;lt;math&amp;amp;gt;C(n)&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
there are to make change of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; units.&lt;br /&gt;
For example, in a country whose denominations are &amp;amp;lt;math&amp;amp;gt;\{1,6,10\}&amp;amp;lt;/math&amp;amp;gt;,&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;C(5) = 1&amp;amp;lt;/math&amp;amp;gt;, &amp;amp;lt;math&amp;amp;gt;C(6)&amp;amp;lt;/math&amp;amp;gt; to &amp;amp;lt;math&amp;amp;gt;C(9)=2&amp;amp;lt;/math&amp;amp;gt;, &amp;amp;lt;math&amp;amp;gt;C(10)=3&amp;amp;lt;/math&amp;amp;gt;, and &amp;amp;lt;math&amp;amp;gt;C(12)=4&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
#How many ways are there to make change of 20 units from &amp;amp;lt;math&amp;amp;gt;\{1,6,10\}&amp;amp;lt;/math&amp;amp;gt;?&lt;br /&gt;
#Give an efficient algorithm to compute &amp;amp;lt;math&amp;amp;gt;C(n)&amp;amp;lt;/math&amp;amp;gt;, and analyze its complexity. (Hint: think in terms of computing &amp;amp;lt;math&amp;amp;gt;C(n,d)&amp;amp;lt;/math&amp;amp;gt;, the number of ways to make change of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; units with highest denomination &amp;amp;lt;math&amp;amp;gt;d&amp;amp;lt;/math&amp;amp;gt;. Be careful to avoid overcounting.)&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.7|(Solution 8.7)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-8. &lt;br /&gt;
In the ''single-processor scheduling problem'', we are&lt;br /&gt;
given a set of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; jobs &amp;amp;lt;math&amp;amp;gt;J&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Each job &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt; has a processing time &amp;amp;lt;math&amp;amp;gt;t_i&amp;amp;lt;/math&amp;amp;gt;, and a deadline &amp;amp;lt;math&amp;amp;gt;d_i&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
A feasible schedule is a permutation of the jobs&lt;br /&gt;
such that when the jobs are performed in that order, every job is&lt;br /&gt;
finished before its deadline.&lt;br /&gt;
The greedy algorithm for single-processor&lt;br /&gt;
scheduling selects the job with the earliest deadline first.&lt;br /&gt;
Show that if a feasible schedule exists, then the&lt;br /&gt;
schedule produced by this greedy algorithm is feasible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Number Problems'''&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-9. &lt;br /&gt;
The ''knapsack problem''&lt;br /&gt;
is as follows: given a set of integers &amp;amp;lt;math&amp;amp;gt;S = \{s_1, s_2, \ldots, s_n\}&amp;amp;lt;/math&amp;amp;gt;, and&lt;br /&gt;
a given target number &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt;, find a subset of &amp;amp;lt;math&amp;amp;gt;S&amp;amp;lt;/math&amp;amp;gt; that adds up&lt;br /&gt;
exactly to &amp;amp;lt;math&amp;amp;gt;T&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
For example, within &amp;amp;lt;math&amp;amp;gt;S = \{1, 2, 5, 9, 10\}&amp;amp;lt;/math&amp;amp;gt; there is a subset that&lt;br /&gt;
adds up to &amp;amp;lt;math&amp;amp;gt;T=22&amp;amp;lt;/math&amp;amp;gt; but not &amp;amp;lt;math&amp;amp;gt;T=23&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Give a correct programming algorithm for knapsack that runs in &amp;amp;lt;math&amp;amp;gt;O(n T)&amp;amp;lt;/math&amp;amp;gt; time.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.9|(Solution 8.9)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-10. &lt;br /&gt;
The ''integer partition'' takes a set of positive&lt;br /&gt;
integers &amp;amp;lt;math&amp;amp;gt;S=s_1, \ldots, s_n&amp;amp;lt;/math&amp;amp;gt; and asks if there is a subset &amp;amp;lt;math&amp;amp;gt;I \in S&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
such that&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt; \sum_{i \in I} s_i= \sum_{ i \notin I} s_i &amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
Let &amp;amp;lt;math&amp;amp;gt;\sum_{i \in S} s_i = M&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Give an &amp;amp;lt;math&amp;amp;gt;O(nM)&amp;amp;lt;/math&amp;amp;gt; dynamic programming algorithm to solve the&lt;br /&gt;
integer partition problem.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-11. &lt;br /&gt;
Assume that there are &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; numbers (some possibly negative)&lt;br /&gt;
on a circle, and we wish to find the maximum contiguous sum&lt;br /&gt;
along an arc of the circle.&lt;br /&gt;
Give an efficient algorithm for solving this problem.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.11|(Solution 8.11)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-12. &lt;br /&gt;
A certain string processing language allows the programmer to break a&lt;br /&gt;
string into two pieces.&lt;br /&gt;
It&lt;br /&gt;
costs &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; units of time to break a string of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; characters into two&lt;br /&gt;
pieces, since this involves copying the old string.&lt;br /&gt;
A programmer wants to break a string into many pieces, and the&lt;br /&gt;
order in which the breaks are made can affect the total amount of time&lt;br /&gt;
used.&lt;br /&gt;
For example, suppose we wish to break a 20-character string after&lt;br /&gt;
characters 3, 8, and 10.&lt;br /&gt;
If the breaks are made in left-right order, then the first break&lt;br /&gt;
costs 20 units of time, the second break costs&lt;br /&gt;
17 units of time, and the third break costs 12 units of time,&lt;br /&gt;
for a total of 49 steps.&lt;br /&gt;
If the breaks are made in right-left order, the first break costs&lt;br /&gt;
20 units of time, the second break costs 10 units of time, and the third&lt;br /&gt;
break costs 8 units of time, for a total of only 38 steps.&lt;br /&gt;
Give a dynamic&lt;br /&gt;
programming algorithm that takes a list of character positions&lt;br /&gt;
after which to break and determines the cheapest break cost in &amp;amp;lt;math&amp;amp;gt;O(n^3)&amp;amp;lt;/math&amp;amp;gt; time.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-13. &lt;br /&gt;
Consider the following data compression technique.&lt;br /&gt;
We have a table of &amp;amp;lt;math&amp;amp;gt;m&amp;amp;lt;/math&amp;amp;gt; text strings, each at most &amp;amp;lt;math&amp;amp;gt;k&amp;amp;lt;/math&amp;amp;gt; in length.&lt;br /&gt;
We want to encode a data string &amp;amp;lt;math&amp;amp;gt;D&amp;amp;lt;/math&amp;amp;gt; of length &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; using as few text strings&lt;br /&gt;
as possible.&lt;br /&gt;
For example, if our table contains {\em(a,ba,abab,b)}&lt;br /&gt;
and the data string is ''bababbaababa'', the best way to encode it&lt;br /&gt;
is {\em(b,abab,ba,abab,a)}---a total of five code words.&lt;br /&gt;
Give an &amp;amp;lt;math&amp;amp;gt;O(nmk)&amp;amp;lt;/math&amp;amp;gt; algorithm to find the length of the best encoding.&lt;br /&gt;
You may assume that every string has at least one encoding in terms of the table.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.13|(Solution 8.13)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-14. &lt;br /&gt;
The traditional world chess championship is a match of 24 games.&lt;br /&gt;
The current champion retains the title in case the match is a tie.&lt;br /&gt;
Each game ends in a win, loss, or draw (tie) where wins count&lt;br /&gt;
as &amp;amp;lt;math&amp;amp;gt;1&amp;amp;lt;/math&amp;amp;gt;, losses as &amp;amp;lt;math&amp;amp;gt;0&amp;amp;lt;/math&amp;amp;gt;, and draws as &amp;amp;lt;math&amp;amp;gt;1/2&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
The players take turns playing white and black.&lt;br /&gt;
White has an advantage, because he moves first.&lt;br /&gt;
The champion plays white in the first game.&lt;br /&gt;
He has probabilities&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;w_{\mbox{w}}&amp;amp;lt;/math&amp;amp;gt;, &amp;amp;lt;math&amp;amp;gt;w_{\mbox{d}}&amp;amp;lt;/math&amp;amp;gt;, and &amp;amp;lt;math&amp;amp;gt;w_{\mbox{l}}&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
of winning, drawing, and losing playing white,&lt;br /&gt;
and has probabilities&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;b_{\mbox{w}}&amp;amp;lt;/math&amp;amp;gt;, &amp;amp;lt;math&amp;amp;gt;b_{\mbox{d}}&amp;amp;lt;/math&amp;amp;gt;, and &amp;amp;lt;math&amp;amp;gt;b_{\mbox{l}}&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
of winning, drawing, and losing playing black.&lt;br /&gt;
#Write a recurrence for the probability that the champion retains the title. Assume that there are &amp;amp;lt;math&amp;amp;gt;g&amp;amp;lt;/math&amp;amp;gt; games left to play in the match and that the champion needs to win &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt; games (which may end in a &amp;amp;lt;math&amp;amp;gt;1/2&amp;amp;lt;/math&amp;amp;gt;).&lt;br /&gt;
#Based on your recurrence, give a dynamic programming to calculate the champion's probability of retaining the title.&lt;br /&gt;
#Analyze its running time for an &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; game match.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-15. &lt;br /&gt;
Eggs break when dropped from great enough height.&lt;br /&gt;
Specifically, there must be a floor &amp;amp;lt;math&amp;amp;gt;f&amp;amp;lt;/math&amp;amp;gt; in any sufficiently tall building&lt;br /&gt;
such that&lt;br /&gt;
an egg dropped from the &amp;amp;lt;math&amp;amp;gt;f&amp;amp;lt;/math&amp;amp;gt;th floor breaks,&lt;br /&gt;
but one dropped from the &amp;amp;lt;math&amp;amp;gt;(f-1)&amp;amp;lt;/math&amp;amp;gt;st floor will not.&lt;br /&gt;
If the egg always breaks, then &amp;amp;lt;math&amp;amp;gt;f=1&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
If the egg never breaks, then &amp;amp;lt;math&amp;amp;gt;f=n+1&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
You seek to find the critical floor &amp;amp;lt;math&amp;amp;gt;f&amp;amp;lt;/math&amp;amp;gt; using an &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt;-story building.&lt;br /&gt;
The only operation you can perform is to drop an egg&lt;br /&gt;
off some floor and see what happens.&lt;br /&gt;
You start out with &amp;amp;lt;math&amp;amp;gt;k&amp;amp;lt;/math&amp;amp;gt; eggs, and seek to drop eggs as few times as possible.&lt;br /&gt;
Broken eggs cannot be reused.&lt;br /&gt;
Let &amp;amp;lt;math&amp;amp;gt;E(k,n)&amp;amp;lt;/math&amp;amp;gt; be the minimum number of egg droppings that will always&lt;br /&gt;
suffice.&lt;br /&gt;
#Show that &amp;amp;lt;math&amp;amp;gt;E(1,n)=n&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
#Show that &amp;amp;lt;math&amp;amp;gt;E(k,n)=\Theta(n^{\frac{1}{k}})&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
#Find a recurrence for &amp;amp;lt;math&amp;amp;gt;E(k,n)&amp;amp;lt;/math&amp;amp;gt;. What is the running time of the dynamic program to find &amp;amp;lt;math&amp;amp;gt;E(k,n)&amp;amp;lt;/math&amp;amp;gt;?&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.15|(Solution 8.15)]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Graph Problems'''&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-16. &lt;br /&gt;
Consider a city whose streets are defined by an &amp;amp;lt;math&amp;amp;gt;X \times Y&amp;amp;lt;/math&amp;amp;gt; grid.&lt;br /&gt;
We are interested in walking from the upper left-hand corner of the&lt;br /&gt;
grid to the lower right-hand corner.&lt;br /&gt;
Unfortunately, the city has bad neighborhoods, whose&lt;br /&gt;
intersections we do not want to walk in.&lt;br /&gt;
We are given an &amp;amp;lt;math&amp;amp;gt;X \times Y&amp;amp;lt;/math&amp;amp;gt; matrix ''BAD'', where ''BAD[i,j] = ''yes''''&lt;br /&gt;
if and only if the intersection between streets &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;j&amp;amp;lt;/math&amp;amp;gt; is&lt;br /&gt;
in a neighborhood to avoid.&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;&lt;br /&gt;
(a) Give an example of the contents of ''BAD'' such that there is no&lt;br /&gt;
path across the grid avoiding bad neighborhoods.&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;&lt;br /&gt;
(b) Give an &amp;amp;lt;math&amp;amp;gt;O( X Y )&amp;amp;lt;/math&amp;amp;gt; algorithm to find a path across the grid that&lt;br /&gt;
avoids bad neighborhoods.&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;&lt;br /&gt;
(c) Give an &amp;amp;lt;math&amp;amp;gt;O( X Y )&amp;amp;lt;/math&amp;amp;gt; algorithm to find the ''shortest'' path across&lt;br /&gt;
the grid that avoids bad neighborhoods.  You may assume that all blocks&lt;br /&gt;
are of equal length.&lt;br /&gt;
For partial credit, give an &amp;amp;lt;math&amp;amp;gt;O(X^2 Y^2)&amp;amp;lt;/math&amp;amp;gt; algorithm.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-17. &lt;br /&gt;
Consider the same situation as the previous problem.&lt;br /&gt;
We have a city whose streets are defined by an &amp;amp;lt;math&amp;amp;gt;X \times Y&amp;amp;lt;/math&amp;amp;gt; grid.&lt;br /&gt;
We are interested in walking from the upper left-hand corner of the&lt;br /&gt;
grid to the lower right-hand corner.&lt;br /&gt;
We are given an &amp;amp;lt;math&amp;amp;gt;X \times Y&amp;amp;lt;/math&amp;amp;gt; matrix ''BAD'', where ''BAD[i,j] = ''yes''''&lt;br /&gt;
if and only if the intersection between streets &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;j&amp;amp;lt;/math&amp;amp;gt; is somewhere&lt;br /&gt;
we want to avoid.&lt;br /&gt;
If there were no bad neighborhoods to contend with, the shortest&lt;br /&gt;
path across the grid would have length &amp;amp;lt;math&amp;amp;gt;(X-1) + (Y-1)&amp;amp;lt;/math&amp;amp;gt; blocks, and&lt;br /&gt;
indeed there would be many such paths across the grid.  Each path&lt;br /&gt;
would consist of only rightward and downward moves.&lt;br /&gt;
Give an algorithm that takes the array ''BAD'' and returns the ''number''&lt;br /&gt;
of safe paths of length &amp;amp;lt;math&amp;amp;gt;X+Y-2&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
For full credit, your algorithm must run in &amp;amp;lt;math&amp;amp;gt;O( X Y )&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.17|(Solution 8.17)]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Design Problems'''&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-18. &lt;br /&gt;
Consider the problem of storing &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; books on shelves in a library.&lt;br /&gt;
The order of the books is fixed by the cataloging system and so cannot&lt;br /&gt;
be rearranged.&lt;br /&gt;
Therefore, we&lt;br /&gt;
can speak of a book &amp;amp;lt;math&amp;amp;gt;b_i&amp;amp;lt;/math&amp;amp;gt;, where &amp;amp;lt;math&amp;amp;gt;1 \leq i \leq n&amp;amp;lt;/math&amp;amp;gt;, that has a&lt;br /&gt;
thickness &amp;amp;lt;math&amp;amp;gt;t_i&amp;amp;lt;/math&amp;amp;gt; and height &amp;amp;lt;math&amp;amp;gt;h_i&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
The length of each bookshelf at this library is &amp;amp;lt;math&amp;amp;gt;L&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Suppose all the books have the same height &amp;amp;lt;math&amp;amp;gt;h&amp;amp;lt;/math&amp;amp;gt; (i.e., &amp;amp;lt;math&amp;amp;gt;h = h_i = h_j&amp;amp;lt;/math&amp;amp;gt; for all&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;i, j&amp;amp;lt;/math&amp;amp;gt;) and the shelves are all separated by a distance of greater than&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;h&amp;amp;lt;/math&amp;amp;gt;, so any book fits on any shelf.&lt;br /&gt;
The greedy algorithm would fill the first shelf with as many books as we can&lt;br /&gt;
until we get the smallest &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt; such that &amp;amp;lt;math&amp;amp;gt;b_i&amp;amp;lt;/math&amp;amp;gt; does not fit, and then repeat&lt;br /&gt;
with subsequent shelves.&lt;br /&gt;
Show that the greedy algorithm always finds the optimal shelf&lt;br /&gt;
placement, and analyze its time complexity.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-19. &lt;br /&gt;
This is a generalization of the previous problem.&lt;br /&gt;
Now consider the case where the height of the books is not constant,&lt;br /&gt;
but we have the freedom to adjust the height of each shelf to that of the&lt;br /&gt;
tallest book on the shelf.   Thus the cost of a particular layout is the sum&lt;br /&gt;
of the heights of the largest book on each shelf.&lt;br /&gt;
#Give an example to show that the greedy algorithm of stuffing each shelf as full as possible does not always give the minimum overall height.&lt;br /&gt;
#Give an algorithm for this problem, and analyze its time complexity. Hint: use dynamic programming.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.19|(Solution 8.19)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-20. &lt;br /&gt;
We wish to compute the laziest way to dial given &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt;-digit number on a&lt;br /&gt;
standard push-button telephone using two fingers. We assume that the two&lt;br /&gt;
fingers start out on the * and \# keys, and that the effort required to&lt;br /&gt;
move a finger from one button to another is proportional to the Euclidean&lt;br /&gt;
distance between them. Design an algorithm that computes&lt;br /&gt;
the method of dialing that involves moving your fingers the&lt;br /&gt;
smallest amount of total distance, where &amp;amp;lt;math&amp;amp;gt;k&amp;amp;lt;/math&amp;amp;gt; is the number of distinct&lt;br /&gt;
keys on the keypad (&amp;amp;lt;math&amp;amp;gt;k=16&amp;amp;lt;/math&amp;amp;gt; for standard telephones).&lt;br /&gt;
Try to use &amp;amp;lt;math&amp;amp;gt;O(n k^3)&amp;amp;lt;/math&amp;amp;gt; time.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-21. &lt;br /&gt;
Given an array of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; real numbers, consider the problem of&lt;br /&gt;
finding the maximum sum in any&lt;br /&gt;
contiguous subvector of the input.&lt;br /&gt;
For example, in the array &amp;amp;lt;math&amp;amp;gt;\{31,-41,59,26,-53,58,97,-93,-23,84\}&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
the maximum is achieved by summing the third through seventh elements,&lt;br /&gt;
where &amp;amp;lt;math&amp;amp;gt;59+26+(-53)+58+97 = 187&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
When all numbers are positive, the entire array is the answer,&lt;br /&gt;
while when all numbers are negative, the empty array maximizes the total&lt;br /&gt;
at 0.&lt;br /&gt;
#Give a simple, clear, and correct &amp;amp;lt;math&amp;amp;gt;\Theta(n^2)&amp;amp;lt;/math&amp;amp;gt;-time algorithm to find the maximum contiguous subvector.&lt;br /&gt;
#Now give a &amp;amp;lt;math&amp;amp;gt;\Theta(n)&amp;amp;lt;/math&amp;amp;gt;-time dynamic programming algorithm for this problem. To get partial credit, you may instead give a ''correct'' &amp;amp;lt;math&amp;amp;gt;O(n \log n)&amp;amp;lt;/math&amp;amp;gt; divide-and-conquer algorithm.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.21|(Solution 8.21)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-22. &lt;br /&gt;
Consider the problem of examining a string&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;x = x_1 x_2 \ldots x_n&amp;amp;lt;/math&amp;amp;gt; from an alphabet of &amp;amp;lt;math&amp;amp;gt;k&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
symbols, and a multiplication table over this alphabet.&lt;br /&gt;
Decide&lt;br /&gt;
whether or not it is possible to parenthesize &amp;amp;lt;math&amp;amp;gt;x&amp;amp;lt;/math&amp;amp;gt; in such a way that&lt;br /&gt;
the value of the resulting expression is &amp;amp;lt;math&amp;amp;gt;a&amp;amp;lt;/math&amp;amp;gt;, where &amp;amp;lt;math&amp;amp;gt;a&amp;amp;lt;/math&amp;amp;gt; belongs to the&lt;br /&gt;
alphabet.&lt;br /&gt;
The multiplication table is neither commutative or associative, so the&lt;br /&gt;
order of multiplication matters.&lt;br /&gt;
\vspace{0.1in}&lt;br /&gt;
&amp;amp;lt;center&amp;amp;gt;&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;\begin{array}{c|ccc}&lt;br /&gt;
&amp;amp;amp;       a       &amp;amp;amp;       b       &amp;amp;amp;       c      \\&lt;br /&gt;
\hline&lt;br /&gt;
a       &amp;amp;amp;       a      &amp;amp;amp;       c      &amp;amp;amp;       c  \\&lt;br /&gt;
b       &amp;amp;amp;       a      &amp;amp;amp;       a      &amp;amp;amp;       b  \\&lt;br /&gt;
c       &amp;amp;amp;       c      &amp;amp;amp;       c      &amp;amp;amp;       c  \\&lt;br /&gt;
\end{array}&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
&amp;amp;lt;/center&amp;amp;gt;&lt;br /&gt;
For example, consider the above multiplication table and the string&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;bbbba&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Parenthesizing it &amp;amp;lt;math&amp;amp;gt;(b(bb))(ba)&amp;amp;lt;/math&amp;amp;gt; gives &amp;amp;lt;math&amp;amp;gt;a&amp;amp;lt;/math&amp;amp;gt;, but &amp;amp;lt;math&amp;amp;gt;((((bb)b)b)a)&amp;amp;lt;/math&amp;amp;gt; gives &amp;amp;lt;math&amp;amp;gt;c&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
Give an algorithm, with time polynomial in &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;k&amp;amp;lt;/math&amp;amp;gt;, to decide whether&lt;br /&gt;
such a parenthesization exists for a given string, multiplication table, and&lt;br /&gt;
goal element.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-23. &lt;br /&gt;
Let &amp;amp;lt;math&amp;amp;gt;\alpha&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;\beta&amp;amp;lt;/math&amp;amp;gt; be constants. Assume that it costs&lt;br /&gt;
&amp;amp;lt;math&amp;amp;gt;\alpha&amp;amp;lt;/math&amp;amp;gt; to go left in a tree, and &amp;amp;lt;math&amp;amp;gt;\beta&amp;amp;lt;/math&amp;amp;gt; to go right.&lt;br /&gt;
Devise an algorithm that builds a tree with optimal worst case cost,&lt;br /&gt;
given keys &amp;amp;lt;math&amp;amp;gt;k_1,\ldots,k_n&amp;amp;lt;/math&amp;amp;gt; and the probabilities that each will be&lt;br /&gt;
searched &amp;amp;lt;math&amp;amp;gt;p_1,\ldots,p_n&amp;amp;lt;/math&amp;amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.23|(Solution 8.23)]] &lt;br /&gt;
&lt;br /&gt;
'''Interview Problems'''&lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-24. &lt;br /&gt;
Given a set of coin denominators, find the minimum number of coins to&lt;br /&gt;
make a certain amount of change.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.24|(Solution 8.24)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-25. &lt;br /&gt;
You are given an array of &amp;amp;lt;math&amp;amp;gt;n&amp;amp;lt;/math&amp;amp;gt; numbers, each of which may be positive, negative,&lt;br /&gt;
or zero.&lt;br /&gt;
Give an efficient algorithm to identify the index positions &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt; and &amp;amp;lt;math&amp;amp;gt;j&amp;amp;lt;/math&amp;amp;gt;&lt;br /&gt;
to the maximum sum of the &amp;amp;lt;math&amp;amp;gt;i&amp;amp;lt;/math&amp;amp;gt;th through &amp;amp;lt;math&amp;amp;gt;j&amp;amp;lt;/math&amp;amp;gt;th numbers.&lt;br /&gt;
&lt;br /&gt;
[[TADM2E 8.25|(Solution 8.25)]] &lt;br /&gt;
&lt;br /&gt;
&amp;amp;lt;br&amp;amp;gt;8-26. &lt;br /&gt;
Observe that&lt;br /&gt;
when you cut a character out of a&lt;br /&gt;
magazine, the character on the reverse side of the page is also removed.&lt;br /&gt;
Give an&lt;br /&gt;
algorithm to determine whether you can generate a given string by pasting&lt;br /&gt;
cutouts from a given magazine.&lt;br /&gt;
Assume that you are given a function that&lt;br /&gt;
will identify the character and its position on the reverse side of the&lt;br /&gt;
page for any given character position.&lt;/div&gt;</summary>
		<author><name>Algowikiadmin</name></author>	</entry>

	</feed>