Difference between revisions of "IntroductionTADM2E"
(Recovering wiki) 
(No difference)

Revision as of 18:13, 11 September 2014
Introduction to Algorithm Design
Finding Counterexamples
<br>11. Show that <math>a + b</math> can be less than <math>\min(a,b)</math>.
<br>12. Show that <math>a \times b</math> can be less than <math>\min(a,b)</math>.
<br>13. Design/draw a road network with two points <math>a</math> and <math>b</math> such that the fastest route between <math>a</math> and <math>b</math> is not the shortest route.
<br>14. Design/draw a road network with two points <math>a</math> and <math>b</math> such that the shortest route between <math>a</math> and <math>b</math> is not the route with the fewest turns.
<br>15. The knapsack problem is as follows: given a set of integers <math>S = \{s_1, s_2, \ldots, s_n\}</math>, and a target number <math>T</math>, find a subset of <math>S</math> which adds up exactly to <math>T</math>. For example, there exists a subset within <math>S = \{1, 2, 5, 9, 10\}</math> that adds up to <math>T=22</math> but not <math>T=23</math>. Find counterexamples to each of the following algorithms for the knapsack problem. That is, giving an <math>S</math> and <math>T</math> such that the subset is selected using the algorithm does not leave the knapsack completely full, even though such a solution exists.
 Put the elements of <math>S</math> in the knapsack in left to right order if they fit, i.e. the firstfit algorithm.
 Put the elements of <math>S</math> in the knapsack from smallest to largest, i.e. the bestfit algorithm.
 Put the elements of <math>S</math> in the knapsack from largest to smallest.
<br>16. The set cover problem is as follows: given a set of subsets <math> S_1, ..., S_m</math> of the universal set <math>U = \{1,...,n\}</math>, find the smallest subset of subsets <math>T \subset S</math> such that <math>\cup_{t_i \in T} t_i = U</math>. For example, there are the following subsets, <math>S_1 = \{1, 3, 5\}</math>, <math>S_2 = \{2,4\}</math>, <math>S_3 = \{1,4\}</math>, and <math>S_4 = \{2,5\}</math> The set cover would then be <math>S_1</math> and <math>S_2</math>. Find a counterexample for the following algorithm: Select the largest subset for the cover, and then delete all its elements from the universal set. Repeat by adding the subset containing the largest number of uncovered elements until all are covered.
Proofs of Correctness
<br>17. Prove the correctness of the following recursive algorithm to multiply two natural numbers, for all integer constants <math>c \geq 2</math>.
function multiply(<math>y,z</math>) comment Return the product <math>yz</math>. 1. if <math>z=0</math> then return(0) else 2. return(multiply(<math>cy,\lfloor z/c \rfloor)+y \cdot (z\,\bmod\,c</math>))
<br>18. Prove the correctness of the following algorithm for evaluating a polynomial. P(x) = <math>a_nx^n + a_{n1}x^{n1} + \dots + a_1x + a_0</math>
function horner(<math>A,x</math>) <math>p = A_n</math> for <math>i</math> from <math>n1</math> to <math>0</math> <math>p = p*x+A_i</math> return <math>p</math>
<br>19. Prove the correctness of the following sorting algorithm.
function bubblesort (<math>A</math> : list[<math>1 \dots n</math>]) var int <math>i, j</math> for <math>i</math> from <math>n</math> to <math>1</math> for <math>j</math> from <math>1</math> to <math>i1</math> if (<math>A[j] > A[j+1]</math>) swap the values of <math>A[j]</math> and <math>A[j+1]</math>
Induction
<br>110. Prove that <math>\sum_{i=1}^n i</math>=<math>n(n+1)/2</math> for <math>n \geq 0</math>, by induction.
<br>111. Prove that <math>\sum_{i=1}^n i^2</math>=<math>n(n+1)(2n+1)/6</math> for <math>n \geq\ 0</math>, by induction.
<br>112. Prove that <math>\sum_{i=1}^n i^3</math>=<math>n^2(n+1)^2/4</math> for <math>n \geq 0</math>, by induction.
<br>113. Prove that <math> \sum_{i=1}^n i(i+1)(i+2)=n(n+1)(n+2)(n+3)/4 </math>
<br>114. Prove by induction on <math>n \geq 1</math> that for every <math>a \neq 1</math>, <math> \sum_{i=0}^n a^i =\frac{a^{n+1}1}{a1}</math> }
<br>115. Prove by induction that for <math>n \geq 1</math>, <math> \sum_{i=1}^n \frac{1}{i(i+1)} = \frac{n}{n+1} </math>
<br>116. Prove by induction that <math>n^3+2n</math> is divisible by <math>3</math> for all <math>n \geq 0</math>. }{
<br>117. Prove by induction that a tree with <math>n</math> vertices has exactly <math>n1</math> edges.
<br>118. Prove by mathematical induction that the sum of the cubes of the first <math>n</math> positive integers is equal to the square of the sum of these integers, i.e. <math> \sum_{i=1}^n i^3 = ( \sum_{i=1}^n i )^2 </math>
Estimation
<br>119. Do all the books you own total at least one million pages? How many total pages are stored in your school library? Schaffer, chapter 2 problem 2.21
<br>120.
How many words are there in this textbook?
<br>121. How many hours are one million seconds? How many days? Answer these questions by doing all arithmetic in your head.
<br>122. Estimate how many cities and towns there are in the United States.
<br>123. Estimate how many cubic miles of water flow out of the mouth of the Mississippi River each day. Do not look up any supplemental facts. Describe all assumptions you made in arriving at your answer.
<br>124. Is disk drive access time normally measured in milliseconds (thousandths of a second) or microseconds (millionths of a second)? Does your RAM memory access a word in more or less than a microsecond? How many instructions can your CPU execute in one year if the machine is left running all the time?
<br>125. A sorting algorithm takes 1 second to sort 1,000 items on your local machine. How long will it take to sort 10,000 items ...
 if you believe that the algorithm takes time proportional to <math>n^2</math>, and
 if you believe that the algorithm takes time roughly proportional to <math>n\log n</math>?
Implementation Projects
<br>126. Implement the two TSP heuristics of tsprobot. Which of them gives betterquality solutions in practice? Can you devise a heuristic that works better than both of them?
<br>127. Describe how to test whether a given set of tickets establishes sufficient coverage in the Lotto problem of lotto. Write a program to find good ticket sets.
Interview Problems
<br>128. Write a function to perform integer division without using either the <tt>/</tt> or <tt>*</tt> operators. Find a fast way to do it.
<br>129. There are 25 horses. At most, 5 horses can race together at a time. You must determine the fastest, second fastest, and third fastest horses. Find the minimum number of races in which this can be done.
<br>130. How many piano tuners are there in the entire world?
<br>131. How many gas stations are there in the United States?
<br>132. How much does the ice in a hockey rink weigh?
<br>133. How many miles of road are there in the United States?
<br>134. On average, how many times would you have to flip open the Manhattan phone book at random in order to find a specific name?