CS 315, Spring 2014

advertisement
CS 315, Spring 2014
Writing Project 03
You may work with ONE partner
Choice: Monday, March 31, at 4:00pm (3 pts)
Draft Due: Thursday, April 17, at 1:00pm (10 pts)
Final Due: Thursday, April 24, at at 1:00pm (20 pts)
You may choose ONE of the following topics to write-up. Upload which option you choose in Moodle
by 4:00pm Monday, 31.Mar.
Option A
Relations were covered in Section 8.1 of the MA 116, Discrete Structures text (Discrete Mathematics
with Applications, 4th Edition, Brooks/Cole Publishing Company, 2011, by Susanna Epp, ISBN-10: 0 495 - 39132 – 8). The notes posted online for this section are available at:
http://jcsites.juniata.edu/faculty/kruse/ma116/Notes/Epp4ed8.1.pdf
In Section 8.2, properties of relations are discussed, including transitivity. Finding the transitive closure
of a relation is also studied. The notes posted online for this section are available at:
http://jcsites.juniata.edu/faculty/kruse/ma116/Notes/Epp4ed8.2.pdf
Finding the transitive closure “by-hand” is typically done iteratively and heuristically, using the directed
graph representing the relation. Warshall’s algorithm can be applied for a more systematic approach to
determining the transitive closure of a relation,
http://people.math.gatech.edu/~spingarn/2602/warshall/warshall2.pdf
Sometimes, a graph is represented using an adjacency matrix. The notes posted online for the section in
the text discussing adjacency matrices are available at:
http://jcsites.juniata.edu/faculty/kruse/ma116/Notes/Epp4ed10.3.pdf
An explanation of Warshall’s Algorithm is given here:
http://jcsites.juniata.edu/faculty/kruse/ma116/Notes/Warshall.pdf
Implement Warshall’s algorithm, either in a compiled language (Java, C++) or interpreted language
(Maple). Analyze the asymptotic run-time of Warshall’s, and provide a narrative of your implementation
efforts. Step through your code’s execution, with a graphical example. Does the order of your loops
matter? That is, once your code is functioning, could you swap the nesting of your loops?
Option B
Read Section 4.1 in the textbook (the 3rd edition only, the maximum-subarray problem does not appear in
previous editions), and then read the Wikipedia entry on the maximum sub-array problem,
http://en.wikipedia.org/wiki/Maximum_subarray_problem
Please submit a write-up of at least one page, as well as source code (no Python, please) to find the
maximum-subarray in a given array. In your source, please provide a clear way to enter an array (editing
the source code is acceptable).
Your write-up should address the following:
 Describe the maximum-subarray problem
 When does it arise?
 Why is the maximum-subarray problem presented at this point in the textbook?

Why does the text present a more expensive algorithm for the maximum-subarray problem, if a
linear-time algorithm for it exists?
Give an overview of the algorithm presented in Section 4.1. Compare the linear-time algorithm presented
in E 4.1-5 to Kadane’s algorithm presented in Wikipedia. Do these describe basically the same algorithm,
or do they describe different algorithms? For your convenience, pseudo-code versions are provided
below You should work through some example arrays, including the one given below, with BOTH
algorithms, and include the tables in your write-up.
Array A:
−2
1
−3
4
−1
2
1
−5
4
In Moodle, please upload the MS Word document containing your write-up, as well as the source code
implementing a version of it.
Kadane’s
n = A.length
max_so_far = 0
max_ending_here = 0
for j=1 to n
max_ending_here = max(0, max_ending_here + A[j])
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
E 4.1-5
n = A.length
max.sum = -inf
ending.here.sum = -inf
for j=1 to n
ending-here-high = j
if ending-here-sum > 0
ending-here-sum = ending-here-sum + A[j]
else
ending-here-low = j
ending-here-sum = A[j]
if ending-here-sum > max-sum
max-sum = ending-here-sum
low = ending-here-low
high = ending-here-high
return (low, high, max-sum)
Download