Chapter 3 Homework Solution
The Fundamentals: Algorithms, the Integers, and Matrices
Section 3.1 Algorithms
10.
We assume that if the input
,t
h
e
n
, since otherwise
is not
defined. In our procedure, we let
and compute
in the obvious way. Then
if
is negative, we replace the answer by its reciprocal.
procedure
(
: real number,
: integer)
for
to
ㆍ
if
then
18
.Th
isiss
im
i
la
rtoExce
rc
ise17
.
procedure
(
⋯
: integers)
min
location
for
to
if
min
≥
then
begin
min
location
end
{
location
is the location of the last occurrence of the smallest element in
the list }
24.
This is similar to Exercise 23. We let the array
keep track of which
elements of the codomain
have already been found to be images of elements of
the domain
. When we find an element that has already been hit being hit again,
we conclude that the function is not onetoone.
procedure
_
(
:func
t
ion
,
⋯
⋯
: integers)
for
to
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Documentelse
_
false
34. There are five passes through the list. After one pass the list reads 2, 3, 1
,5
,
4, 6, since the 6 is compared and moved at each stage. During the next pass, the
2 and the 3 are not interchanged, but the 3 and the 1 are, as are the 5 and the 4,
yielding 2, 1, 3, 4, 5, 6. On the third pass, the 2 and the 1 are interchanged,
yielding 1, 2, 3, 4, 5, 6. There are two more passes, but no further interchanges
are made, since the list is now in order.
38. We start with 6, 2, 3, 1, 5, 4. The first step inserts 2 correctly into the sorted
l
i
s
t6
,p
roduc
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 HERSH
 Calculus, Matrices, Integers, Greatest common divisor, Divisor, divisors

Click to edit the document details