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
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
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
1. Recurrences: 12 points
Give a tight asymptotic bound for the following recurrences. No justication necessary.
A(n) = A(
n) + 1 for n > 9 and A(n) = 1 for 1 n 9.
O(log log n)
B(n) = 3B(n/2) + 4B(n/4) + n2 for n 2 and B(n) = 1 for 0 n < 2.
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.
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
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
Homework 5 solutions
1. Suppose we can insert or delete an element into a hash table in O(1) time. In order to ensure that our hash
table is always big enough, without wasting a lot of memory, we will use the following global rebuilding
Headbanging 2 (September 1112)
A subsequence is anything obtained from a sequence by deleting a subset of elements; the elements
of the subsequence need not be contiguous in the original sequence. For example, the strings I, PRO,
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 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 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 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 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 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 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 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 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)
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
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
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
Lecture 23: Applications of Maximum Flow [Fa12]
For a long time it puzzled me how something so expensive, so leading edge,
could be so useless, and then it occurred to me that a computer is a stupid
machine with the ability to do incredibly sma
CS 374 Fall 2015 Homework 3 Solutions
i. Solution: The language cfw_1 is an innite fooling set. For any non-negative integers
i = j, the strings 1i and 1 j are distinguished by the sufx 01i 0: 1i 01i 0 matches the form
00 10 x x where x = 1i 0. On
Lab 5 September 11
Prove that each of the following languages is not regular.
1. cfw_02n 1n | n 0
Solution: The language (00) is an innite fooling set. For any non-negative integers i = j, the
strings 02i and 02 j are distingushed by th
Lab 6 September 16 Solutions Revised 20150919
Give context-free grammars for each of the following languages. For each grammar, describe in English
the language for each non-terminal, and in the examples above. As usual, we wont get to al