CSCI 385 Fall 2013
Advanced Data Structures and Algorithms
Archived Class
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook
Homework

Policies
College
    Policies
Advice

Notes
Programs
Tutorials

CSCI 125
CSCI 255
MATH 131 (01 and 02)
Others

Admin

Homework 9

Comments

  • Most problems are found in one of the following:
    1. ADM: The Algorithm Design Manual
    2. IDMA: An Introduction to Discrete Mathematics and Algorithms
  • For full credit, provide context for each problem, show all calculations, and justify all answers by providing enough comments to explain your reasoning.
  • You will lose a significant amount of credit if you do not provide context, calculations, and justifications for a problem.
  • Numbers and/or algebra by themselves are not enough. A correct answer with no justification will be worth no more than half credit, and sometimes much less than that.
  • Precision is very important. You cannot skip steps, make guesses, or use flawed logic. Any of these things can lead to incorrect answers.
  • Homework assignments must be very neatly written or typeset (e.g. using Word or OpenOffice).
  • NEW! If you want to learn LaTeX, see the LaTeX section of Writing Notes for a sample LaTeX document. The machines in the lab have TexWorks installed. You may have to ask around to figure out how to compile a file the first time.
  • You must indicate any assistance/collaboration you had on an assignment as specified on the Policies page.
  • NEW! If a problem asks for an algorithm, you should give the most efficient algorithm you can find to ensure full credit. You should also specify the complexity of the algorithm with justification, whether or not the problem asks for it.

Details

Write the following programs

  1. Write a program that tries to determine whether or not using the formula to compute the nth Fibonacci number works properly on a computer. Your goal is to identify the smallest number for which it does not work properly.

    You can start by using the iterative algorithm from the Recursive Functions example. Then implement a method that computes the nth Fibonacci number using the closed form expression we developed in class. You can find the formula here: Fibonacci number (Wikipedia). Do not use an approximation in your algorithm. Instead, compute it using the appropriate Java functions (e.g. Math.sqrt).

    The easiest way to proceed is probably to compute the first 15 or so with each method and compare them. Your program should output 3 values per line: n, and the two values of f(n) as computed by your two methods. If they differ at any point, you have succeeded. If they don't, try some larger values. You might want to replace the ints with longs in the original code so you can compute slightly larger values (I think you can compute up to the 16th or 17th with 32 bits).

    Print out your code along with the output of running both versions on data from 1 to 15 or so (at least until you find if/when the two methods differ).

  2. Implement an algorithm called CountShortestPaths that counts the number of shortests paths between two vertices in an unweighted graph.

    Use the Algoraph Plugin (which should already be installed on the lab machines) and upload your algorithm so you can test it on some graphs. Your algorithm should extend BreadthFirstSearchSkeletonAlgorithm. Ignore the stuff this used to say about implementing countShortestPaths and runAlgorithm. You should not do either of these. Instead, everything you implement should be in the 4 process methods and in initializeMoreData. The getResult method should return just the number of paths from the first vertex in the graph to the last one. BFS will automatically run starting at the first vertex.

    I will look at your algorithms in Algoraph so all you need to do is make sure your algorithm is uploaded.