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 40
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.
Importa
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 exp
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 si
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:3
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
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.
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 per
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
subs
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 per
University of Waterloo
CS 341 Algorithms
Fall 2014
Solutions to Midterm Examination
1. [25 marks] True-false: 5 marks each. No justication necessary. Just write T or F
and write clearly. If we cant te
import java.io.*;
import java.util.*;
class pencilcfw_
public static void main(String[] args) cfw_
trycfw_
/read in the numbers from std in
BufferedReader input = new BufferedReader(new
InputStreamRea
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 3
Distributed Tuesday, September 23 2014.
Due 5 PM, Tuesday, September 30 2014. Hand in to assignment boxes on the 4th oor of
MC, near MC
University of Waterloo
CS 341 Algorithms
Fall 2014
Problem Set 1
Distributed Tuesday, September 9 2014.
Due 5 PM, Tuesday, September 16 2014. Hand in to assignment boxes on the 4th oor of
MC, near MC
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
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
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 4
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 4
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 406
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
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
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 a
CS 341, Lecture 22
CS 341, Lecture 22, November 20 2014
At the end of today's class, we spent 10 minutes filling out the
course evaluation forms available at
evaluate.uwaterloo.ca.
3-CNF-SAT is NP-com
Lecture 3 Notes, CS 341
CS 341, Lecture 3, September 16 2014
Announcements: Problem Set 2 is now available on the course home page.
Reminder of course rules and etiquette:
On Piazza, check, before pos
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
mark
CS 341 Lecture 18
CS 341 Lecture 18, November 6 2014
Reading for this lecture: Sections 25.1 and 25.2 of CLRS.
Continuing with what we did last time.
Therefore, in O(n+1) steps (under the unit-cost mo
Greedy Algorithm
Greedy algorithm applies to a large class of problems. In general, the solution consists of a series of
smaller choices. Since these smaller choices may conflict each other, they need
Recursion
We studied reduction last class. It solves new problems Y by first reducing Y to X, and solve X instead. It
makes much sense if X already has a known algorithm.
We have also learned a progra
Analyzing Algorithms
We try answer the following questions
Model of computation
What does worst case mean?
Asymptotical complexity.
Model of Computation:
Model of computation should be both realistic
Linear Time Algorithm for Max Subarray
Given an array [1. . ], find a subarray [. . ] that maximizes = []. We can the value max sum.
There is a linear time algorithm that has some greedy flavor in it.
Saddleback Search
Let be a 2D sorted integer matrix. [, ] [, ] for < , and [, ] [ , ] for < .
Let be an integer. Find in .
We set (, ) to be the upper-right corner of the matrix in the figure. If [, ]