passing through the list from the
beginning to the end and then from the
end to the beginning until no exchanges
are needed. 11. Show the steps used by
the shaker sort to sort the list 3, 5, 1, 4, 6,
2. 12. Express the shaker sort in
pseudocode. 13. Show
associative, and commutative properties,
0 is an additive identity, and for every
nonzero a Zm, m a is an inverse of a
modulo m. 43. Show that Zm with
multiplication modulo m, where m 2 is
an integer, satisfies the closure,
associative, and commutativity
expansion with b = 16 tells us that
(2AE0B)16 = 2 164 + 10 163 + 14 162
+ 0 16 + 11 = 175627. Each
hexadecimal digit can be represented
using four bits. For instance, we see that
(1110 0101)2 = (E5)16 because (1110)2
= (E)16 and (0101)2 = (5)16. Bytes,
wh
job. [Hint: First show that for a schedule
to be optimal, jobs must be scheduled
with no idle time between them and so
that no job is scheduled before another
with an earlier deadline.] 41. Suppose
that we have a knapsack with total
capacity of W kg. We a
the preamble to Exercise 61 of Section 3.1,
always produces a male optimal and
female pessimal matching. 33. Define
what it means for a matching to be female
optimal and for a matching to be male
pessimal. 34. Show that when woman
do the proposing in the
sorting that at the j th step inserts the j th
element into the correct position in in the
list, when the first j 1 elements of the
list are already sorted The linear search
has O(n) worst case time complexity. The
binary search has O(log n) worst case
ti
corresponds to a block of four binary
digits, with these correspondences shown
in Table 1 without initial 0s shown. (We
leave it as Exercises 1316 to show that
this is the case.) This conversion is
illustrated in Example 7. EXAMPLE 7 Find
the octal and he
maximum and minimum of the pair of
elements being examined. b) Express the
algorithm described in part (a) in
pseudocode. c) How many comparisons of
elements of the sequence are carried out
by this algorithm? (Do not count
comparisons used to determine wh
integers. This procedure will now be
specified in detail. To add a and b, first
add their rightmost bits. This gives a0 +
b0 = c0 2 + s0, where s0 is the rightmost
bit in the binary expansion of a + b and c0
is the carry, which is either 0 or 1. Then
add
terms of finding a match for the first
character of the target and checking
successive characters for a match, and if
they do not all match, moving the start
location one character to the right.] b)
Express your algorithm in pseudocode. c)
Give a big-O es
cents using quarters, dimes, nickels, and
pennies hasO(n) complexity measured in
terms of comparisons needed. Exercises
37 and 38 deal with the problem of
scheduling the most talks possible given
the start and end times of n talks. 37. Find
the complexity
multiplication of integers. The operations
+m and m are called addition and
multiplication modulo m and when we
use these operations, we are said to be
doing arithmetic modulo m. EXAMPLE 7
Use the definition of addition and
multiplication in Zm to find 7
known as number theory. In this chapter
we will develop some of the important
concepts of number theory including
many of those used in computer science.
As we develop number theory, we will use
the proof methods developed in Chapter 1
to prove many theor
equal to some previous term. 30. Analyze
the worst-case time complexity of the
algorithm you devised in Exercise 32 of
Section 3.1 for finding all terms of a
sequence that are greater than the sum of
all previous terms. 31. Analyze the worstcase time comp
estimate how quickly processors will be
able to perform operations in the next
twenty years. 6. Develop a detailed list of
algorithmic paradigms and provide
examples using each of these paradigms.
7. Explain what the TuringAward is and
describe the criter
programming language may have one, or
possibly two, operators for modular
arithmetic, denoted by mod (in BASIC,
Maple, Mathematica, EXCEL, and SQL), %
(in C, C+, Java, and Python), rem (in Ada
and Lisp), or something else. Be careful
when using them, beca
no algorithm for solving this problem
using fewer operations. P1: 1 CH03-7T
Rosen-2311T MHIA017-Rosen-v5.cls May
13, 2011 10:24 3.3 Complexity of
Algorithms 231 a) Show that Algorithm 1
in Section 3.1 is an optimal algorithm
with respect to the number of
then checks for each pair of terms
whether their difference is in the
sequence. b) Give a big-O estimate for the
complexity of this algorithm. Is it more
efficient than the brute-force algorithm
from Exercise 29? Suppose we have s men
and s women each wit
busy. The teacher asked the students to
find the sum of the first 100 positive
integers. Gauss realized that this sum
could be found by forming 50 pairs, each
with the sum 101: 1 + 100, 2 + 99,., 50 +
51. This brilliance attracted the
sponsorship of patro
binary notation (with 2 as the base) when
carrying out arithmetic, and octal (base 8)
or hexadecimal (base 16) notation when
expressing characters, such as letters or
digits. In fact, we can use any integer
greater than 1 as the base when
expressing integ
job j for time tj without interruption. Each
job has a deadline dj . If we start job j at
time sj , it will be completed at time ej = sj
+ tj . The lateness of the job measures how
long it finishes after its deadline, that is,
the lateness of job j is max
prove or disprove that n3 is O(n2 + 18n +
107). 4. List these functions so that each
function is big-O of the next function in
the list: (log n)3, n3/1000000, n, 100n +
101, 3n, n!, 2nn2. 5. a) How can you
produce a big-O estimate for a function
that is t
= (a m c) +m (b m c). These properties
follow from the properties we have
developed for congruences and
remainders modulo m, together with the
properties of integers; we leave their
proofs as Exercises 4244. Note that we
have listed the property that ever
(mod m) to indicate that a is congruent to
b modulo m. We say that a b (mod m) is
a congruence and that m is its modulus
(plural moduli). If a and b are not
congruent modulo m, we write a b (mod
m). Although both notations a b (mod
m) and a mod m = b incl
left of 12345 in base 8. Hence, (12345)10
= (30071)8. P1: 1 CH04-7R Rosen2311T MHIA017-Rosen-v5.cls May 13,
2011 10:24 248 4 / Number Theory and
Cryptography EXAMPLE 5 Find the
hexadecimal expansion of (177130)10.
Solution: First divide 177130 by 16 to
ob
mod 11 c) (73 mod 23)2 mod 31 d) (212
mod 15)3 mod 22 33. Find each of these
values. a) (992 mod 32)3 mod 15 b) (34
mod 17)2 mod 11 c) (193 mod 23)2 mod
31 d) (893 mod 79)4 mod 26 34. Show
that if a b (mod m) and c d (mod m),
where a, b, c, d, and m are i
Suppose that a list contains integers that
are in order of largest to smallest and an
integer can appear repeatedly in this list.
Devise an algorithm that locates all
occurrences of an integer x in the list. b)
Estimate the number of comparisons
used. 5.
complexity: the amount of space in
computer memory required for an
algorithm to solve a problem worst-case
time complexity: the greatest amount of
time required for an algorithm to solve a
problem of a given size average-case time
complexity: the average
3.1) d) binary insertion sort (described in
the preamble to Exercise 47 in Section
3.1) An n n matrix is called upper
triangular if aij = 0 whenever i>j . 41.
From the definition of the matrix product,
describe an algorithm in English for
computing the pr
time does a 24-hour clock read a) 100
hours after it reads 2:00? b) 45 hours
before it reads 12:00? c) 168 hours after it
reads 19:00? 13. Suppose that a and b are
integers, a 4 (mod 13), and b 9 (mod
13). Find the integer c with 0 c 12
such that a) c 9a