CSCI 255 Fall 2013
Introduction to Algorithms and Discrete Structures
Archived Class
Charles Cusack
Computer Science
Hope College



CSCI 125
CSCI 255
MATH 341


All Homework

Comments for all assignments

  • 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).
  • 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.

Homework 1

The following problems are from pages 27-30 of ADM.

Homework 2

The following problems are from Chapter 1 of IDMA on pages 11-12.

Homework 3

Problems are from Chapter 2 of IDMA on pages 31-34.

Homework 4

Problems are from Chapter 3 of IDMA on pages 69-74.

Homework 5

Problems are from Chapter 3 of IDMA on pages 69-74.

Homework 6

Problems are from Chapter 3 of IDMA on pages 69-74.

Homework 7

Problems are from Chapter 4 of IDMA on pages 93-95.

Homework 8

The following problems are from pages 57-64 of ADM.
2-16Use the definition of Big-O notation or the limit theorem.
2-18Express your answer by placing them one per line, except for two or more functions with the same growth rate should be placed on the same line.
2-22No proof necessary for this one.

Homework 9

The following problems are from pages 57-64 of ADM.
2-28aDon't forget to show enough work to justify your answer!

Homework 10

The following problems are from pages 162-163 of IDMA
418The context for this problem is in section 6.4.
419Can you say induction?

Homework 11

The following problems are from pages 162-163 of IDMA
Problem A (below)
Problem A:
Solve the following recurrence relations. If you can provide an exact formula, do so. Otherwise, give a tight bound (not just an upper bound). Make sure you show all of your work.

  1. T(n) = 2 T(n/2) + n3, T(1)=1
  2. T(n) = T(n - 1) + n, T(1)=1

Homework 12

The following problems are from pages 195-197 of IDMA.
516Questions 1 and 4 are pretty straightforward. Question 3 includes the possibility of taking however many courses you want, as long as the requirement is met.
517.1-3The setup for the problem is on page 195. See page 196 for questions 1-3. Question 1 can be done by generalizing the idea in the setup.
526Don't use induction. It's actually easier than that. But be careful. If you think about it correctly, at some point in your proof you will consider multiple cases/possibilities.

Homework 13

For this assignment you will implement a simple algorithm and answer a few questions about it.

  1. Write a Java method int choose(int n, int k) that computes the binomial coefficient: .
    • You can assume that n and k are both non-negative.
    • You may not use any Java libraries to assist you.
    • Your implementation should be as efficient as possible.
    • Make sure you test your method on several inputs. In particular, you should be able to quickly and correctly compute choose(8,4), choose(15,7), and choose(100,5). Each of these is a little harder to get correct than the previous one for reasons I will let you discover/think about.
    • You can check your answers at WolframAlpha using a search like "8 choose 4".
    • Print out your code and hand it in at the beginning of class. (You only need to print the method, not the surrounding class, etc. It is O.K. if you print the whole class as long as your entire choose method is all together on one page.)
  2. No matter how good your method is, it will not be able to compute choose(100,7). Why not?
  3. Your method will also very likely not be able to compute choose(100,6) correctly, but for a slightly different reason. What it is?

Homework 14

The following problems are from pages 193-197 of IDMA.
504.2Don't do it the hard way!
509You really don't want to do this one the hard way.
536The technique you used in the previous 2 problems (assuming you did them the easiest way) can be used here. This one is actually really easy if you use the correct tool.

Homework 15

The following problems are from pages 98-102 of ADM.
3-20Assume you do not know the length of the list. Your algorithm should be as efficient as possible. If a list has an even number of elements, return either of the middle two elements.Algorithm Rubric
3-26Treat the input as an array of characters, and do not use any special methods (e.g. split) to help your process the string since that would obscure how long the algorithm is taking. Give your answer in paragraph form, pseudocode, or code. If you use paragraph form, make sure your description is clear and contains all of the necessary details. If you use pseudocode or code, you also need to include a description of what your algorithm is doing.Algorithm Rubric

Homework 16

The following problems are from pages 139-144 of ADM.
4-12Prove that your algorithm has the specified complexity. Also, see the heading right above the problem. It may give you a hint about how you might want to approach the problem.Algorithm Rubric
4-18You should be able to do this in place (i.e. with a constant amount of extra memory). Prove that your algorithm has the specified complexity.Algorithm Rubric
4-28This one is really not that hard if you use some of your math skills.Computational Problem Rubric
4-32You are not limited to 20 questions. They just use that as a setup for the problem. For both parts, specify exactly how many questions are necessary as a function of n (not just a bound).Algorithm Rubric

Homework 17

The following problems are from pages 184-189 of ADM.
A few general comments: Part of learning a topic is learning to use the vocabulary. Here are a few examples.

  1. Graphs have vertices/nodes and edges, not elements.
  2. For BFS/DFS, the terms discovered and processed are technically defined, so use those instead of explored, found, visited, seen, etc. which do not have clearly defined meanings.
  3. You can reach the end of a linked list, but you can't reach the end of a tree.
5-1Show your work. In particular, details about the BFS/DFS tree should be given (e.g. parent pointers or the tree drawn on the graph) along with any relevant numbers (e.g. distances and/or timestamps). Essentially, show enough to demonstrate that you actually followed the algorithms. Most of you seem to have ignored these comments. Please include all of the details asked for. Although the book's BFS algorithm does not explicitly compute distances, the version in the lecture notes does, so follow that version if necessary.Computational Problem Rubric
5-3This problem is talking about acyclic graphs, not rooted trees. For the induction step, assume it is true for any tree with n nodes. Then consider a tree with n+1 nodes. How do you get a tree with n nodes from a tree with n+1 nodes so that you can apply the inductive hypothesis? Hint: consider a leaf. You cannot just start with a tree with n nodes and add a leaf to it. The induction step needs to show that it is true for any tree with n+1 nodes, so you need to start with an arbitrary tree with n+1 nodes. Also, when you apply the inductive step, you need to prove that there is exactly one path between every pair of nodes. You need to argue it is true of the (n+1)th node with any other node, but also that it is still true of any pair of nodes not including the (n+1)th.Proof Rubric
5-9Assume the only operators are +, -, /, and *. The easiest way to think about it is to implement it as Eval(node root), where root is the root of the binary tree. It is actually pretty straightforward if you use recursion. You should give your solution as pseudo-code and deal explicitly with the 4 possible operators.Algorithm Rubric
5-21Explain the idea behind your algorithm and justify its complexity. If you use BFS, specify what additional data you need to keep track of and what to do in one or more of the "process" methods of BFS. You will implement this algorithm for Homework 9. Feel free to do so now as a way of testing your algorithm. Your answer can be as simple as something like "For each node keep track of X. Initialize the values to Y. In processXYZ, do Q..."Algorithm Rubric

Homework 18

The following problems are from pages 184-189 of ADM
5-2Note: Your book may have a typo. There should be edge (H,F) and not edge (F,H). Use an algorithm (or a modification of one) from the book. Specify what algorithm you are using and show enough work to demonstrate that you actually followed the algorithm.Computational Problem Rubric
5-15Don't forget to give the complexity of your algorithm. The last part of the question is asking you to identify another graph problem that is equivalent to this one. In other words, your answer should be something like "this is equivalent to the Travelling Salesman problem".Algorithm Rubric
5-26Part (a) is not too hard. Part (b) may require some more thought.Algorithm Rubric

Homework 19

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. 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.

Homework 20

The following problems are from pages 227 of ADM
6-6See the new Algorithm Rubric

Homework 21

Pick one: 8-10, 8-16c, 8-17, 8-25

Problem A: Problem 8-10 suggests giving an algorithm that runs in O(nM) time. Is that a polynomial-time algorithm with respect to the size of the input? Explain. (Hint: The input consists of n integers, so let's use n as the size of the input. Now you just need to think about what M can be.)

Note: When giving a dynamic programming algorithm, give a recursive formula and specify how the values will be computed to yield an efficient algorithm.

Homework 22

  • Complete the Data Structures and Algorithms Catalog. That document tells you just about everything you need to know.
  • Submit a PDF or docx file using Webhandin using assignment 255-HW22 (Use your 1Hope username/password).
  • The purpose of this assignment is to help you review all of the data structures and algorithms you have learned about from this and previous classes (primarily CSCI 235). In addition, the "catalog" component of the assignment should help you organize the algorithms in a way that makes sense to you.
  • Grades will be based primarily on completeness and correctness (but see below).
  • Note: This will be graded by spot checking parts of it and looking at more detail at other parts. I am telling you this because if the final exam is open book/notes, I want to make sure that you know that you are responsible to know whether or not all of the details in your catalog are correct.
  • Note #2: Submit this by Thursday if you want comments for Friday. Otherwise the deadline is being extended to the final exam period (Tuesday at 12:30). I will not be assigning a grade if you submit it Thursday so make sure you resubmit it before the exam if you make changes.