can be an aesthetic experience, much like
writing poetry or composing music.
Knuth pays $2.56 for the first person to
find each error in his books and $0.32 for
significant suggestions. If you send him a
letter with an error (you will need to use
regular
12 cents, the greedy algorithm using
quarters, 12-cent coins, dimes, nickels,
and pennies would not always produce
change using the fewest coins possible.
57. Use Algorithm 7 to schedule the
largest number of talks in a lecture hall
from a proposed set of
we could add talks in order of shortest
time, we could add talks in order of
earliest finish time, or we could use some
other criterion. We now consider these
possible criteria. Suppose we add the talk
that starts earliest among the talks
compatible with
profound influence on the development of
computer science, which he began writing
as a graduate student in 1962, focusing on
compilers. In common jargon, Knuth,
referring to The Art of Computer
Programming, has come to mean the
reference that answers all
the functions f and g for sufficiently large
numbers in the domains of these
functions. However, it is acceptable to
write f (x) O(g(x) because O(g(x)
represents the set of functions that are
O(g(x). When f (x) is O(g(x), and h(x) is
a function that has l
It follows that C = 3 and k = 2 are also
witnesses to the relation f (x) is O(x2). 4x
2 x 2 x 2 + 2x + 1 1 2 4 3 2 1 The part of
the graph of f(x) = x 2 + 2x + 1 that
satisfies f(x) < 4x 2 is shown in blue. x 2 +
2x +1 1 FIGURE 1 The Function x2 + 2x +
1
of the Growth of Functions Commonly
Used in Big-O Estimates. P1: 1 CH03-7T
Rosen-2311T MHIA017-Rosen-v5.cls May
13, 2011 10:24 212 3 / Algorithms
USEFUL BIG-O ESTIMATES INVOLVING
LOGARITHMS, POWERS, AND
EXPONENTIAL FUNCTIONS We now give
some useful facts
attended lectures presented by the
famous number theorist Dirichlet. He
received his doctorate under the German
number theorist Kummer in 1862; his
thesis was on group theory. Bachmann
was a professor at Breslau and later at
Mnster. After he retired from
the suitors who have proposed to this
suitee in this round or previous rounds.
The proposal of this highest ranking
suitor remains pending and is rejected in
a later round if a more appealing suitor
proposes in that round. The series of
rounds ends when e
three-volume exposition on number
theory as well as other books on number
theory and mathematical analysis. P1: 1
CH03-7T Rosen-2311T MHIA017-Rosenv5.cls May 13, 2011 10:24 208 3 /
Algorithms f (x) k g(x) Cg(x) f (x) < Cg(x)
for x > k The part of the grap
integers is nondecreasing if each term of
the list is at least as large as the preceding
term.) 31. Devise an algorithm that finds
the first term of a sequence of integers
that equals some previous term in the
sequence. 32. Devise an algorithm that
finds
estimate and the fact that 3n is O(n),
Theorem 3 gives the estimate that 3n
log(n!) is O(n2 log n). Next, the product
(n2 + 3) log n will be estimated. Because
(n2 + 3) < 2n2 when n > 2, it follows that
n2 + 3 is O(n2). Thus, from Theorem 3 it
follows tha
C2|g(x)| whenever x>k. The existence of
the constants C1, C2, and k tells us that f
(x) is (g(x) and that f (x) is O(g(x),
respectively. Usually, when big-Theta
notation is used, the function g(x)in
(g(x)is a relatively simple reference
function, such as
term of the sequence remains. When this
is done, a comparison is made to see
whether this term equals x. Sorting
Ordering the elements of a list is a
problem that occurs in many contexts. For
example, to produce a telephone directory
it is necessary to al
product of two functions, suppose that
f1(x) is O(g1(x) and f2(x) is O(g2(x).
From the definition of big-O notation,
there are constants C1, C2, k1, and k2
such that |f1(x)| C1|g1(x)| when x>k1,
and |f2(x)| C2|g2(x)| P1: 1 CH03-7T
Rosen-2311T MHIA017-Rose
to add to the pile of change without
exceeding n cents. For example, to make
change for 67 cents, we first select a
quarter (leaving 42 cents). We next select
a second quarter (leaving 17 cents),
followed by a dime (leaving 7 cents),
followed by a nickel
words that could be formed from the
letters in Zieglers Giant Bar. This won a
television set for his school and a candy
bar for everyone in his class. Knuth had a
difficult time choosing physics over music
as his major at the Case Institute of
Technology.
linear and binary search algorithms to
find an element in a sequence of n
elements. We will also estimate the
number of comparisons used by the P1: 1
CH03-7T Rosen-2311T MHIA017-Rosenv5.cls May 13, 2011 10:24 3.2 The Growth
of Functions 205 bubble sort an
polynomial. Theorem 1 does this. It shows
that the leading term of a polynomial
dominates its growth by asserting that a
polynomial of degree n or less is O(xn).
THEOREM 1 Let f (x) = anxn + an1xn1
+ a1x + a0, where a0, a1,.,an1, an are
real numbers. Then
inequality n < 2n, we quickly can conclude
that n is O(2n) by taking k = C = 1 as
witnesses. Note that because the
logarithm function is increasing, taking
logarithms (base 2) of both sides of this
inequality shows that log n < n. It follows
that log n is
7), which can be established directly by
turning the inequality around. P1: 1
CH03-7T Rosen-2311T MHIA017-Rosenv5.cls May 13, 2011 10:24 3.2 The Growth
of Functions 215 Often, it is important to
know the order of growth of a function in
terms of some rela
theory. The big-O symbol is sometimes
called a Landau symbol after the German
mathematician Edmund Landau, who
used this notation throughout his work.
The use of big-O notation in computer
science was popularized by Donald Knuth,
who also introduced the b
both an upper and are the Greek
uppercase letters omega and theta,
respectively. and a lower bound on the
size of a function f (x), relative to a
reference function g(x), we use bigTheta
(big-) notation. Both big-Omega and bigTheta notation were introduce
element among the remaining elements is
found and put into the second position.
This procedure is repeated until the
entire list has been sorted. 41. Sort these
lists using the selection sort. a) 3, 5, 4, 1, 2
b) 5, 4, 3, 2, 1 c) 1, 2, 3, 4, 5 42. Write t
amount of fiber. Surprisingly, one of the
simplest approaches often leads to a
solution of an optimization problem. This
approach selects the best choice at each
step, instead of considering all sequences
of steps that may lead to an optimal
solution. Alg
That is, we will show there are unsolvable
problems. The problem we will study is
the halting problem. It asks whether there
is a procedure that does this: It takes as
input a computer program and input to
the program and determines whether the
program wi
sorting algorithms. A surprisingly large
number of sorting algorithms have been
devised using distinct strategies, with
new ones introduced regularly. In his
fundamental work, The Art of Computer
Programming, Donald Knuth devotes
close to 400 pages to sor
Example 6 big-O estimates will be
developed for the factorial function and
its logarithm. These estimates will be
important in the analysis of the number of
steps used in sorting procedures.
EXAMPLE 6 Give big-O estimates for the
factorial function and th
of people of opposite genders to form
couples is stable if we cannot find a man
m and a woman w who are not assigned
to each other such that m prefers w over
his assigned partner and w prefers m to
her assigned partner. 60. Suppose we
have three men m1, m