Assignment 07
Contents:
Overview
Topic: Algorithms
Related Reading: See Lectures 16 & 17.
Due: 8pm Thursday, 21 March 2002
Internet Requirements
You will only need an internet connection at the time of submission.
Practice Problems
Problems to be Submitted (20 points)
- (4 points)
Consider the following sorted list of numbers:
1 |
2 |
9 |
11 |
12 |
13 |
15 |
21 |
23 |
24 |
29 |
34 |
35 |
41 |
43 |
- What sequence of 'middle' values in considered when running the
binary search algorithm (Figure 4.14 of [Br]) with target 6?
- What sequence of 'middle' values in considered when running the
binary search algorithm (Figure 4.14 of [Br]) with target 12?
- What sequence of 'middle' values in considered when running the
binary search algorithm (Figure 4.14 of [Br]) with target 19?
- What sequence of 'middle' values in considered when running the
binary search algorithm (Figure 4.14 of [Br]) with target 41?
- (4 points)
Suppose the insertion sort as presented in Figure 4.11
(p. 194 [Br]) was applied to the list
Frank
Bob
Carol
George
Alice
Elaine
Describe the organization of the list at the end of each execution of
the body of the outer while structure.
(please see solution to the first practice
problem as an example)
- (4 points)
Consider the selection sort, exactly as presented in the solution
given on p. 572, for Question 5 of Section 4.4, when
applied to the list:
Frank
Bob
Carol
George
Alice
Elaine
Describe the organization of the list at the end of each execution of
the body of the outer while structure.
- (4 points)
In lecture, we demonstrated the execution of the MergeSort routine
on a sample list. Specifically, we showed the order of the
characters after each activation of the procedure MergeLists
completes.
Please give a similar presentation when MergeSort is executed on the
following initial list of characters:
H O M E W O R K
- (4 points)
Chapter Review Problem 23 (p. 220 [Br])
Overall, please place your answers to all of these questions in a
single document to be submitted.
Extra Credit (2 points)
Read Chapter Review Problem 29 (p. 221 [Br]) which discusses
a puzzle called the Tower of Hanoi. For notation, we will assume that
the three pegs are named A, B, and C, and that the rings are numbered
1, 2, 3, and so on, starting with the smallest ring being 1.
The recursive solution to the problem can be expressed with the
following pseudocode:
procedure Transfer(numRings, startPeg, endPeg, tempPeg)
if (numRings > 0)
then
[
Apply Transfer(numRings-1, startPeg, tempPeg, endPeg)
]
Move single Ring #numRings from startPeg to endPeg
[
Apply Transfer(numRings-1, tempPeg, endPeg, startPeg)
]
Your job is to trace through the various activations of this recursive
algorithm when it is intially called as Transfer(4,A,C,B).
To demonstrate your understanding, your submission should include the
ordered list of single moves which take place during the process.
For example, if we called Transfer(2,A,C,B) the process is:
Move ring #1 from A to B
Move ring #2 from A to C
Move ring #1 from B to C
comp150 Class Page
mhg@cs.luc.edu
Last modified: 25 March 2002