CS 415, Section 001 | Sonoma State University | Fall, 2022 |
Algorithm Analysis
|
||
Instructor: Henry M. Walker
Lecturer, Sonoma State University |
Although much of this course is well developed, some details can be
expected to evolve as the semester progresses.
Any changes in course details will be announced promptly during class.
The Halting Problem is said to be "unsolvable".
A company believes there would be a strong market for a software package that would take the specifications of a problem and the code for a program as input and would prove whether the program meets its specifications in all cases. That is, the software package would prove whether or not a program always meets its specifications.
Although the prospect of such software package might capture one's imagination, such can package cannot be successfully produced. Explain why an error-free version of this software is impossible to develop.
Consider the concepts of a NP-Hard problem and an NP-Complete problem.
Suppose a loop is to start at a value start
and
finish at (or near) a value end
in
about n+1
iterations, with
iterations increasing by a
value increment = (end-start)/n
each
time.
Two loop structures are proposed:
// approach 1 increment = (end - start)/n; for (i = 0; i <= n; i++){ value = start + i * increment; /* processing for value */ }
// approach 2 value = start; increment = (end - start)/n; while (value <= end) { /* processing for value */ value += increment; }
Although the first approach requires somewhat more arithmetic within the loop than the second, it likely will provide better accuracy. Identify two distinct reasons why the first approach should be preferred over the second.
Suppose y = f(x)
is a function that decreases
from x=a
to x=b
, on the interval
[a, b]
, with a<b
.
Throughout this interval, assume f(x)>0
, and
assume the Trapezoidal Rule were to be used to approximate the
area under y = f(x)
on the interval
[a, b]
.
start
and go
toward end
or begin at end
and go
toward start
, or is either order fine? Explain.
Pages 438-440 of the textbook describe how to use a Branch-and-Bound algorithm to find an approximate solution to the Traveling Salesperson Problem, and pages 444-448 describe a "Twice-around-the-tree" algorithm that uses a different approach to approximate another solution.
Apply each of these algorithms to find approximate solutions to the Traveling Salesperson Problem for each of the following graphs.
Suppose we are given a continuous function f, and we want to approximate a value r where f(r)=0. (Jargon: r is called a root of the function f.)
This section considers two approximation methods for finding the roots of functions, the bisection method and Newton's Method.
Work with these numeric methods requires you to graph functions, so that you have a visual representation of a function's graph. For this purpose, you can use any graphing software that you like. One option is Graph a function from desmos.com.
x^4
.
The following question is based on the Reading on the Bisection Method.
Write a program that uses the Bisection Method to approximate a root of a function.
double f (double x)
for which the program is to find a root.
double find_root (double a, double b, double accuracy)
which works as follows:
Consult Levitin's textbook, Section 11.4 for details on Newton's Method, including the main formula.
Use the program newtons-method.c to apply Newton's method to solve the following.
Find the cube root of n by solving the equation f(x) = 0 where f(x) = x3 - n. In particular, use the program with this function (and its derivative) to find the cube root of 15.
created May 2, 2022 revised May 3, 2022 revised May 7, 2022 revised July 22, 2022 |
|
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |