Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Computer Algorithms

# Computer Algorithms

Ratings:
(0)
|Views: 232|Likes:

Published by: Programmer on Apr 24, 2012

### Availability:

Read on Scribd mobile: iPhone, iPad and Android.
See more
See less

12/18/2012

pdf

text

original

Computer Algorithms, Third Edition,Solutions to Selected Exercises
Sara BaaseAllen Van GelderFebruary 25, 2000

ii
I
NTRODUCTION
This manual contains solutions for the selected exercises in
Computer Algorithms: Introduction to Design and Analy-sis
, third edition, by Sara Baase and Allen Van Gelder.Solutions manuals are intended primarily for instructors, but it is a fact that instructors sometimes put copies incampus libraries or on their web pages for use by students. For instructors who prefer to have students work onproblems without access to solutions, we have chosen not to include all the exercises from the text in this manual. Theincluded exercises are listed in the table of contents. Roughly every other exercise is solved.Some of the solutions were written speciﬁcally for this manual; others are adapted from solutions sets handed outto students in classes we taught (written by ourselves, teaching assistants, and students).Thusthere is some inconsistencyin the style andamountofdetail in the solutions. Somemay seem to be addressedto instructors and some to students. We decided not to change these inconsistencies, in part because the manual will beread by instructors and students. In some cases there is more detail, explanation, or justiﬁcation than a student mightbe expected to supply on a homework assignment.Many of the solutions use the same pseudocode conventions used in the text, such as:1. Block delimiters (

” and “

”) are omitted. Block boundaries are indicated by indentation.2. The keyword
static
is omitted from method (function and procedure) declarations. All methods declared inthe solutions are
static
.3. Class name qualiﬁers are omitted from method (function and procedure) calls. For example,
x = cons(z,x)
might be written when the Java syntax requires
x = IntList.cons(z, x)
.4. Keywords to control visibility,
public
,
private
, and
protected
, are omitted.5. Mathematical relational operators

,”

,” and “

are usually written, instead of their keyboard versions.Relational operators are used on types where the meaning is clear, such as
String
, even though this would beinvalid syntax in Java.We thank Chuck Sanders for writing most of the solutions for Chapter 2 and for contributing many solutions inChapter 14. We thank Luo Hong, a graduate student at UC Santa Cruz, for assisting with several solutions in Chapters9, 10, 11, and 13.In a few cases the solutions given in this manual are affected by corrections and clariﬁcations to the text. Thesecases are indicated at the beginning of each affected solution. The up-to-date information on corrections and clariﬁca-tions, along with other supplementary materials for students, can be found at these Internet sites:
ftp://ftp.aw.com/cseng/authors/baasehttp://www-rohan.sdsu.edu/faculty/baasehttp://www.cse.ucsc.edu/personnel/faculty/avg.html
c
-
Copyright 2000 Sara Baase and Allen Van Gelder. All rights reserved.Permission is granted for college and university instructors to make a reasonable number of copies, free of charge,as needed to plan and administer their courses. Instructors are expected to exercise reasonable precautions againstfurther, unauthorized copies, whether on paper, electronic, or other media.Permission is also granted for Addison-Wesley-Longman editorial, marketing, and sales staff to provide copiesfree of charge to instructors and prospective instructors, and to make copies for their own use.Other copies, whetherpaper, electronic, or othermedia, are prohibitedwithout priorwritten consentof the authors.

List of Solved Exercises
1 Analyzing Algorithms and Problems: Principles and Examples 1
1.1 . . . . . . . 11.2 . . . . . . . 21.4 . . . . . . . 21.6 . . . . . . . 21.8 . . . . . . . 31.10 . . . . . . 31.12 . . . . . . 31.13 . . . . . . 31.15 . . . . . . 41.18 . . . . . . 41.20 . . . . . . 41.22 . . . . . . 41.23 . . . . . . 41.25 . . . . . . 51.28 . . . . . . 51.31 . . . . . . 61.33 . . . . . . 61.35 . . . . . . 61.37 . . . . . . 61.39 . . . . . . 61.42 . . . . . . 71.44 . . . . . . 71.46 . . . . . . 71.47 . . . . . . 71.48 . . . . . . 71.50 . . . . . . 8
2 Data Abstraction and Basic Data Structures 9
2.2 . . . . . . . 92.4 . . . . . . . 92.6 . . . . . . . 92.8 . . . . . . . 92.10 . . . . . . 112.12 . . . . . . 112.14 . . . . . . 122.16 . . . . . . 132.18 . . . . . . 14
3 Recursion and Induction 17
3.2 . . . . . . . 173.4 . . . . . . . 173.6 . . . . . . . 173.8 . . . . . . . 183.10 . . . . . . 183.12 . . . . . . 18
4 Sorting 19
4.2 . . . . . . . 194.4 . . . . . . . 194.6 . . . . . . . 194.9 . . . . . . . 194.11 . . . . . . 194.13 . . . . . . 204.15 . . . . . . 204.17 . . . . . . 204.19 . . . . . . 214.21 . . . . . . 214.23 . . . . . . 214.25 . . . . . . 224.26 . . . . . . 224.27 . . . . . . 234.29 . . . . . . 234.31 . . . . . . 234.34 . . . . . . 244.35 . . . . . . 244.37 . . . . . . 244.40 . . . . . . 244.42 . . . . . . 244.44 . . . . . . 254.45 . . . . . . 254.46 . . . . . . 254.48 . . . . . . 254.49 . . . . . . 254.51 . . . . . . 264.53 . . . . . . 264.55 . . . . . . 274.57 . . . . . . 274.59 . . . . . . 284.61 . . . . . . 284.63 . . . . . . 294.65 . . . . . . 29
5 Selection and Adversary Arguments 31
5.2 . . . . . . . 315.4 . . . . . . . 325.6 . . . . . . . 325.8 . . . . . . . 335.10 . . . . . . 345.12 . . . . . . 345.14 . . . . . . 345.16 . . . . . . 345.19 . . . . . . 355.21 . . . . . . 355.22 . . . . . . 365.24 . . . . . . 37
6 Dynamic Sets and Searching 39
6.1 . . . . . . . 396.2 . . . . . . . 396.4 . . . . . . . 406.6 . . . . . . . 406.8 . . . . . . . 416.10 . . . . . . 416.12 . . . . . . 416.14 . . . . . . 436.16 . . . . . . 456.18 . . . . . . 456.20 . . . . . . 456.22 . . . . . . 466.24 . . . . . . 476.26 . . . . . . 476.28 . . . . . . 476.30 . . . . . . 476.32 . . . . . . 486.34 . . . . . . 496.36 . . . . . . 496.37 . . . . . . 496.40 . . . . . . 50

## Activity (4)

You've already reviewed this. Edit your review.