University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 2
Distributed Tuesday, September 16 2014.
Due 5 PM, Tuesday, September 23 2014. Hand in to assignment boxes on the 4th oor of
MC.
Important: In all of the assignments of this course, when you
University of Waterloo
CS 341 Algorithms
Fall 2014
Solutions to Problem Set 6
1. [10 marks] (a) The problem of maximizing an arithmetic expression. Here you are
given an unparenthesized arithmetic expression where each number in the expression
is a non-ne
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 8
Distributed Tuesday, November 4 2014.
Due 5 PM, Tuesday, November 11 2014. Hand in to assignment boxes on the 4th oor of
MC, near MC 4065.
1. [10 marks] Given a connected graph G = (V, E) wi
Name:
Student number:
Section you attend:
University of Waterloo
CS 341 Algorithms
Fall 2014
Midterm Examination
October 21 2014
Aids allowed: one 8.5 by 11 piece of paper with anything on it (both sides). No
computers, calculators, cell phones, or other
CS 341, Winter 2015
Andrew Arnold, Timothy Chan, Doug Stinson
Midterm Examination
Last Name:
First Name:
Signature:
ID number:
Check the section in which you wish to pick up your exam:
Section 1 (8:30, Chan)
Section 3 (8:30, Arnold)
Section 2 (11:30, C
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 8
1. [10 marks] Given a connected graph G = (V, E) with weights on the edges, how would
you eciently compute a maximum spanning tree that is, the spanning tree with
the largest total weight of
CS341
Assignment 4
Fall 2012
SOLUTIONS
Due date: Thurs. Nov. 15, at 5:00 pm on Tues. Nov. 13 by 5:00 pm to get bonus 5 marks.
The assignment will be marked out of 70. Maximum mark 75 for early birds.
Problem 1 [3 + 3 + 4 = 10 marks] The warm-up questions
CS 341 Lecture 15
CS 341 Lecture 15, October 28 2014
Reading for this lecture:
Review properties of graphs, Section B.4 of CLRS.
Review properties of heaps, Chapter 6 of CLRS.
Study representation of graphs, Section 22.1 of CLRS.
Study minimum-spanning tr
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 9
Distributed Tuesday, November 11 2014.
Due 5 PM, Tuesday, November 18 2014. Hand in to assignment boxes on the 4th oor of
MC, near MC 4065.
1. [10 marks] You are given a directed graph G = (
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 10
Distributed Tuesday, November 18 2014.
Due 5 PM, Thursday, November 27 2014. NOTE: DIFFERENT DAY! Hand in to assignment boxes on the 4th oor of MC, near MC 4065.
1. [10 marks] Let A be an N
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 7
Distributed Tuesday, October 28 2014.
Due 5 PM, Tuesday, November 4 2014. Hand in to assignment boxes on the 4th oor of
MC, near MC 4065.
1. [10 marks] Consider the following problem: given
University of Waterloo
CS 341 Algorithms
Fall 2014
Solutions to Problem Set 5
1. [10 marks] The theme of this question is invent or augment a data structure. Explain
how to support the following three operations on a given length-n character string S,
so
University of Waterloo
CS 341 Algorithms
Fall 2014
Solutions to Problem Set 7
1. [10 marks] Consider the following problem: given an unsorted array L[1.n] of integers
and a positive integer k n, nd the k smallest integers in L. The result need not be
sort
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 6
Distributed Tuesday, October 14 2014.
Due 5 PM, Tuesday, October 28 2014. Hand in to assignment boxes on the 4th oor of MC,
near MC 4065. NOTE: You have two weeks to complete this assignment
University of Waterloo
CS 341 Algorithms
Fall 2014
Solutions to Problem Set 3
1. [10 marks] A point (x, y) in the plane dominates a point (x , y ) if both x > x and
y > y . A point P on a list of points L is an exterior point if no point of L dominates it
University of Waterloo
CS 341 Algorithms
Fall 2014
Solutions to Problem Set 1
1. [10 marks] True or false (no need to justify). You can assume m, n are real numbers
2. Recall that lg denotes base-2 logarithm.
2
2
(a) (mn)(ln m)(ln n) = n(ln m) m(ln n)
2
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 5
Distributed Tuesday, October 7 2014.
Due 5 PM, Tuesday, October 14 2014. Hand in to assignment boxes
on the 4th oor of MC, near MC 4065.
1. [10 marks] The theme of this question is preproces
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 4
Distributed Tuesday, September 30 2014.
Due 5PM, Tuesday, October 6 2014. You will submit this assignment entirely electronically
using the submit command described below.
1. [10 marks] Writ
Lecture 14 Notes, CS 341
CS 341, Lecture 14, October 23 2014
Midterm statistics: low score 39%, high score 95%. Median was 74%.
If you have a complaint about how your midterm was marked, find the
marker by initials (TA or instructor) and contact
them firs
Lecture 6 Notes, CS 341
CS 341, Lecture 6, September 25 2014
Reading: CLRS, sections 4.1, 4.3, and 4.4.
Multiplying large numbers
One of the most fundamental problems you can imagine is multiplication.
Computers all over the world are multiplying
billions
CS 341 Lecture 16
CS 341 Lecture 16, October 30 2014
Reading for this lecture: CLRS, sections 23.2, 24.1, 24.3.
Prim's algorithm can be described briefly as follows: it is a greedy
algorithm where, at each step, we choose a previously
unconnected vertex t
Lecture 8 Notes, CS 341
CS 341, Lecture 8, October 2 2014
Reading: CLRS, Chapter 16.
Algorithm Design Paradigm #5: Invent (or augment) a data structure
This one is quite similar to preprocessing.
We already saw an example of this in Lecture 1, when we des
Lecture 5 Notes, CS 341
CS 341, Lecture 5, September 23 2014
Reading for this lecture: CLRS, Sections 3.2, 2.3.1.
Paradigm #3: Recursion
You already know a lot about recursion from your first courses on programming. We will see much more about
recursion w
import java.io.*;
import java.util.*;
import java.lang.Math.*; /need the max(int,int) fn
class karatcfw_
/class that stores and sign and digits of a number
/having a sign is paramount to have when performing
the Karatsuba method
public static class IntDig
CS 341, Lecture 23
CS 341, Lecture 23, November 25 2014
VERTEX-COVER is NP-complete
Next, we consider the VERTEX-COVER problem. We say a graph G = (V,E)
has a vertex cover of size k if there is a
subset V' of V of
size k such
that for all edges (u,v) in E
import java.io.*;
import java.util.*;
import java.lang.Math.*; /need the max(int,int) fn
class karatcfw_
/class that stores and sign and digits of a number
/having a sign is paramount to have when performing the Karatsuba
method
public static class IntDig