HW 2 Solution: CS 473: Fundamental Algorithms, Fall 2014
1. (30 pts.) I Want (One) More!
Suppose you are given a directed graph G = (V, E) with non-negative edge lengths; (e) is
the length of e E. You are interested in the shortest path distance between t
Homework 6 Solutions
1. Describe a data structure that supports the following operations:
SPLIT, CONCAT, and LOOKUP in O(log n) time (either worst-case, expected, or amortized).
NEWSTRING in O(1) worst-case and amortized time.
HW 7 Solution
CS 473: Fundamental Algorithms, Fall 2014
1. (40 pts.) Surfs up.
After selecting its new president, the Inter-Galactic Surng School (IGSS) decided to send
a few teams to the surng competition that happens every year in Kauai. It
Homework 2 Solutions
Rubric (for all dynamic programming problems): For a problem worth 10 points:
6 points for a correct recurrence, described either using mathematical notation
or as pseudocode for a recursive algorithm.
1 point for a clear Eng
CS 374 Fall 2015 Homework 4 Solutions
1. (a) Solution: General Idea: Use QUICKSELECT to quickly nd the top 1% and the bottom 70%,
and iterate over A to nd the sums of earnings.
Perform QUICKSELECT to nd the index i containing the (.70)n-ranked
Homework 9 Solutions
Rubric: The following standard rubric applies to all maximum ow reductions:
4 points for correct reduction
1 for vertices
1 for edges
1 for capacities
1 for remaining details
4 points for proof of correctness
2 points fo
Lecture 9: Randomized Algorithms [Fa12]
The rst nuts and bolts appeared in the middle 1400s. The bolts were just screws with straight sides
and a blunt end. The nuts were hand-made, and very crude. When a match was found between a
nut and a bol
Lecture 29: NP-Hard Problems [Fa12]
The wonderful thing about standards is that
there are so many of them to choose from.
Real Admiral Grace Murray Hopper
If a problem has no solution, it may not be a problem, but a fact
not to be solved, but
Lecture 5: Dynamic Programming [Fa12]
Those who cannot remember the past are doomed to repeat it.
George Santayana, The Life of Reason, Book I:
Introduction and Reason in Common Sense (1905)
The 1950s were not good years for mathematical resea
Lecture 15: Scapegoat and Splay Trees [Fa12]
Everything was balanced before the computers went off line. Try and adjust something, and
you unbalance something else. Try and adjust that, you unbalance two more and before you
know whats happened,
Lecture 19: Shortest Paths [Fa12]
Well, ya turn left by the re station in the village and take the old post road by
the reservoir and. . . no, that wont do.
Best to continue straight on by the tar road until you reach the schoolhouse and
Lecture 16: Disjoint Sets [Fa12]
E pluribus unum (Out of many, one)
Ofcial motto of the United States of America
John: Whos your daddy? Cmon, you know who your daddy is! Whos your daddy?
DArgo, tell him who his daddy is!"
DArgo: Im your daddy.
Lecture 17: Depth-First Search in Detail [Fa12]
Tsui Pe must have said once: I am withdrawing to write a book.
And another time: I am withdrawing to construct a labyrinth.
Every one imagined two works;
to no one did it occur that the book and t
Lecture 17: Basic Graph Properties [Fa12]
Obie looked at the seein eye dog. Then at the twenty-seven 8 by 10 color glossy pictures with
the circles and arrows and a paragraph on the back of each one. . . and then he looked at the
seein eye dog.
Homework 10 Solutions
Rubric: The following standard rubric applies to all NP-hardness proofs:
4 points for correct reduction
1 for reasonable choice of source problem
3 for actual reduction
The reduction must be in the correct direct
Midterm 2 Solutions
(a) The left spine of a binary tree is the path from the root to the leftmost node. For example, if the root
has no left child, the left spine contains only the root. What is the expected number of nodes in the
Midterm 1 Solutions
1. Each question on this page has one of the following ve answers:
(a) What is
B: (log n)
n3 + 3n2 5n + 1
4n2 2n +
D: (n log n)
E: (n2 )
(b) What is
(c) What is
Midterm 1 Questions Version A
This exam lasts 120 minutes.
Write your answers in the separate answer booklet.
Please return this question sheet and your cheat sheet with your answers.
1. Each of these ten questions has one of the followin
Lecture 1: Recursion [Fa 12]
The control of a large force is the same principle as the control of a few men:
it is merely a question of dividing up their numbers.
Sun Zi, The Art of War (c. 400 C.E.), translated by Lionel Giles (1910)
Lecture 7: Greedy Algorithms [Fa10]
The point is, ladies and gentleman, greed is good. Greed works, greed is right.
Greed claries, cuts through, and captures the essence of the evolutionary spirit.
Greed in all its forms, greed for life, money,
Lecture 10: Treaps and Skip Lists [Fa12]
I thought the following four [rules] would be enough, provided that I made a rm and constant
resolution not to fail even once in the observance of them. The rst was never to accept anything
as true if I
Lecture 12: Hash Tables [FaAZ12]
Calvin: There! I nished our secret code!
Hobbes: Lets see.
Calvin: I assigned each letter a totally random number, so the code will be hard to
crack. For letter A, you write 3,004,572,688. B is 28,731,569.
Lecture 14: Amortized Analysis [Fa12]
The goode workes that men don whil they ben in good lif al amortised by
Geoffrey Chaucer, The Persones [Parsons] Tale (c.1400)
I will gladly pay you Tuesday for a hamburger today.
Lecture 22: Max-Flow Algorithms [Fa12]
A process cannot be understood by stopping it. Understanding must move
with the ow of the process, must join it and ow with it.
The First Law of Mentat, in Frank Herberts Dune (1965)
Theres a difference b
Lecture 21: Maximum Flows and Minimum Cuts [Fa12]
Col. Hogan: One of these wires disconnects the fuse,
the other one res the bomb.
Which one would you cut, Shultz?
Sgt. Schultz: Dont ask me, this is a decision for an ofcer.
Col. Hogan: All righ
Lab 2 - September 2 - solutions
This lab gives practice at constructing DFAs.
1. Design the following DFAs assuming that the alphabet is cfw_0, 1.
(a) A DFA for cfw_w | |w| is odd.
(b) A DFA for cfw_w | every prex x of w has |#0 (x) #1 (x
Lab 3 - September 4 - Solutions
This lab gives practice at constructing NFAs and understanding their power and exibility.
1. Design an NFA for the set of strings that consist of 01 repeated one or more times, or 010 repeated
one or more t
Lab 1 August 28
This lab is about strings and regular expressions. Recall the denition and properties of the
concatenation operator between strings.
Lemma 1: Concatenating nothing does nothing: For every string w, we have w = w.
Lab 4 September 9
This lab covers the subset construction to convert an NFA to a DFA that accepts the same language
and also on how to use the power of NFAs to prove closure under some non-trivial operations.
1. Consider the NFA dened by