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,
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,
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
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
th
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
pess
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 c
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
il
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 al
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
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)
E
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
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 def
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 p
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
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.
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 Lis
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
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
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 +
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 i
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 af
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 ca
= (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 Exercise
(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). A
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 o
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
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 th
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
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
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