Professional Documents
Culture Documents
Problem Set #1
Due: Wed, Feb 4th
Suppose list a has n elements and is sorted. Using () notation, what is the best case
running time as function of n? Using () notation, what is the worst case running
time as function of n?
4. Modify the find function from problem 4 by changing the 5th line from m =
(x+y)/2 to m = (2*x+y)/3; now answer the same questions given in problem 3.
5. Consider this sorting algorithm, written in Python:
def bsort(a):
swapped = True
while swapped:
swapped = False
Problem Set #2
Due: 1pm, Feb 18th, 2015
What is the median of the list? Run your program and show the
output.
Run your program 1000 times on the word list and compute
statistics on the number of recursive calls you make for each
run: what is the min, the max, and the average number of
calls?
1. Text problem 3.8. (If using on-line book, ignore part (c))
2. Suppose you are trying to buy a digraph from a salesman Joe. You tell Joe that your
graph cannot have any odd-length cycles, and must be strongly-connected. Joe says he
has just the thing, and he shows you just three edges of it: (a, b), (b, c) and (a, c).
Explain why Joe must be lying. (Note: there might be a LOT more edges and a LOT
more vertices, but you have to base your answer on just the three edges you can see.)
3. Text problem 3.21.
4. Text problem 3.24. Justify the correctness and running time of your algorithm.
(Note that it says dag and not digraph. If we ask the same problem about a digraph,
there is no known polynomial-time algorithm!)
5. A chain of words is a list of words where the i-th word is the (i-1)st word with one
extra character and some mixing of letters. For example, AN, TAN, RANT, TRAIN,
RETINA, NASTIER is a chain of length 6. Find the longest chain you can in
our wordlist.
In order to do this, first build a dag. The dag will consist of a node for each word (you
might want to collapse words into a single node when it makes sense to), and an edge
from word x to word y if y can follow x in a chain. Then run DFS from each source
node in the dag and keep track of the maximum depth you reach. Print out an example
chain that has maximum length (there will be a TON... just give one chain).
Please hand in your source code along with the longest chain your code found.
CSCI 5454 - Algorithms - Spring 2015
Problem Set #6
Problem Set #7
Due: Never