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 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
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
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
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
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
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
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 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
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
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 tell them apart, no credit.
(a) Our O(n2 log n) algorithm
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
InputStreamReader(System.in); /read in input
String readLine = null;
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 4065.
Important: In all of the assignments of this cou
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
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 4065.
First, review the properties of logarithms, facto
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
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
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-complete
Next we will examine 3-CNF-SAT. This problem is n
Lecture 4 Notes, CS 341
CS 341, Lecture 4, September 18 2014
Announcements: The solutions to Problem Set 1 are now available, but
you will need a username and a password,
which we distributed in class
on Tuesday, September 16.
If you didn't get it, contac
Lecture 7 Notes, CS 341
CS 341, Lecture 7, September 30 2014
Reading: CLRS, section 4.2 (3rd edition) or
section 28.2 (2nd edition).
Faster matrix multiplication
Now we will encounter V. Strassen's 1969 algorithm
for matrix multiplication, in which two n
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 posting a question, for others who have
already asked the
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 model),
we can compute the total number of distinct walks
CS 341: Algorithms
Douglas R. Stinson
David R. Cheriton School of Computer Science
University of Waterloo
Winter, 2017
D.R. Stinson (SCS)
CS 341
Winter, 2017
1 / 198
1
Course Information
2
Introduction
3
Divide-and-Conquer Algorithms
4
Greedy Algorithms
5
CS341: Algorithms
Lecture 01: Merge Sort
Yao-Liang Yu
School of Computer Science
University of Waterloo
January 5, 2017
Y-L. Yu (UW)
Merge Sort
January 5, 2017
1 / 23
Plan for Today
1
Recap
2
More Examples
3
Merge Sort
Y-L. Yu (UW)
Merge Sort
January 5, 2
CS341: Algorithms
Lecture 04: Divide & Conquer I
Yao-Liang Yu
School of Computer Science
University of Waterloo
January 17, 2017
Y-L. Yu (UW)
DC: Geometry
January 17, 2017
1 / 18
Plan for Today
1
Recap
2
Maximal Element
3
Closest Pair
Y-L. Yu (UW)
DC: Geo
CS341: Algorithms
Lecture 10: Dynamic Programming
Yao-Liang Yu
School of Computer Science
University of Waterloo
Feb 07, 2017
Y-L. Yu (UW)
Dynamic Programming
Feb 07, 2017
1 / 42
Topics
1
Overview
2
Recursion or Not?
3
Segmented Least Squares
4
Matrix Mul