Chapter_3_Homework_Solution

# Chapter_3_Homework_Solution - Chapter 3 Homework Solution...

This preview shows pages 1–3. Sign up to view the full content.

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 one-to-one. procedure  _  ( :func t ion ,    ⋯      ⋯  : integers) for   to    

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
else  _   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.

{[ snackBarMessage ]}

### Page1 / 7

Chapter_3_Homework_Solution - Chapter 3 Homework Solution...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online