Difference between revisions of "IntroductionTADM2E"
(Recovering wiki) 
m (Protected "IntroductionTADM2E" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) 
(No difference)

Latest revision as of 18:42, 11 September 2014
Introduction to Algorithm Design
Finding Counterexamples
11.
Show that $ a + b $ can be less than $ \min(a,b) $.
12.
Show that $ a \times b $ can be less than $ \min(a,b) $.
13.
Design/draw a road network with two points $ a $ and $ b $ such that the
fastest route between $ a $ and $ b $ is not the shortest route.
14.
Design/draw a road network with two points $ a $ and $ b $ such that the
shortest route between $ a $ and $ b $ is not the route with the fewest turns.
15.
The knapsack problem
is as follows: given a set of integers $ S = \{s_1, s_2, \ldots, s_n\} $, and
a target number $ T $, find a subset of $ S $ which adds up
exactly to $ T $.
For example, there exists a subset within $ S = \{1, 2, 5, 9, 10\} $ that
adds up to $ T=22 $ but not $ T=23 $.
Find counterexamples to each of the following algorithms for the knapsack
problem.
That is, giving an $ S $ and $ T $ 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 $ S $ in the knapsack in left to right order if they fit, i.e. the firstfit algorithm.
 Put the elements of $ S $ in the knapsack from smallest to largest, i.e. the bestfit algorithm.
 Put the elements of $ S $ in the knapsack from largest to smallest.
16.
The set cover problem
is as follows: given a set of subsets $ S_1, ..., S_m $
of the universal set $ U = \{1,...,n\} $,
find the smallest subset of subsets $ T \subset S $
such that $ \cup_{t_i \in T} t_i = U $.
For example, there are the following subsets, $ S_1 = \{1, 3, 5\} $,
$ S_2 = \{2,4\} $, $ S_3 = \{1,4\} $, and $ S_4 = \{2,5\} $
The set cover would then be $ S_1 $ and $ S_2 $.
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
17.
Prove the correctness of the following recursive algorithm
to multiply two natural numbers, for all
integer constants $ c \geq 2 $.
function multiply($ y,z $) comment Return the product $ yz $. 1. if $ z=0 $ then return(0) else 2. return(multiply($ cy,\lfloor z/c \rfloor)+y \cdot (z\,\bmod\,c $))
18.
Prove the correctness of the following algorithm for evaluating a
polynomial. P(x) = $ a_nx^n + a_{n1}x^{n1} + \dots + a_1x + a_0 $
function horner($ A,x $) $ p = A_n $ for $ i $ from $ n1 $ to $ 0 $ $ p = p*x+A_i $ return $ p $
19.
Prove the correctness of the following sorting algorithm.
function bubblesort ($ A $ : list[$ 1 \dots n $]) var int $ i, j $ for $ i $ from $ n $ to $ 1 $ for $ j $ from $ 1 $ to $ i1 $ if ($ A[j] > A[j+1] $) swap the values of $ A[j] $ and $ A[j+1] $
Induction
110.
Prove that $ \sum_{i=1}^n i $=$ n(n+1)/2 $ for $ n \geq 0 $,
by induction.
111.
Prove that
$ \sum_{i=1}^n i^2 $=$ n(n+1)(2n+1)/6 $ for $ n \geq\ 0 $,
by induction.
112.
Prove
that $ \sum_{i=1}^n i^3 $=$ n^2(n+1)^2/4 $
for $ n \geq 0 $,
by induction.
113.
Prove that
$ \sum_{i=1}^n i(i+1)(i+2)=n(n+1)(n+2)(n+3)/4 $
114.
Prove by induction on $ n \geq 1 $ that for every $ a \neq 1 $,
$ \sum_{i=0}^n a^i =\frac{a^{n+1}1}{a1} $
}
115.
Prove by induction that for $ n \geq 1 $,
$ \sum_{i=1}^n \frac{1}{i(i+1)} = \frac{n}{n+1} $
116.
Prove by induction that $ n^3+2n $ is divisible by $ 3 $ for all $ n \geq 0 $.
}{
117.
Prove by induction that a tree with $ n $ vertices has exactly $ n1 $ edges.
118.
Prove by mathematical induction that the sum of the cubes of the first $ n $
positive integers is equal to the square of the sum of these integers, i.e.
$ \sum_{i=1}^n i^3 = ( \sum_{i=1}^n i )^2 $
Estimation
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
120.
How many words are there in this textbook?
121.
How many hours are one million seconds?
How many days?
Answer these questions by doing all arithmetic in your head.
122.
Estimate how many cities and towns there are in the United States.
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.
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?
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 $ n^2 $, and
 if you believe that the algorithm takes time roughly proportional to $ n\log n $?
Implementation Projects
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?
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
128.
Write a function to perform integer division without using either the
/ or * operators.
Find a fast way to do it.
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.
130.
How many piano tuners are there in the entire world?
131.
How many gas stations are there in the United States?
132.
How much does the ice in a hockey rink weigh?
133.
How many miles of road are there in the United States?
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?