Dynamic Programming for the
Ruler Folding Problem
Lecture 23, part b
Monday, October 26
Ruler Folding Problem
[Hopcroft, Joseph, Whitesides], robotics context, 1981
input: integer lengths l1, ln of the links in a carpenters
ruler & a max desired folding l
import java.util.*;
import java.io.*;
public class RedBlackBST<Key extends Comparable<Key>cfw_
private Node root;
private static final boolean RED = true;
private static final boolean BLACK = false;
private class Node
cfw_
Key key;
Node left, right;
int N
Finding a Longest
Common Subsequence
Terminology
A string = 1 2 is a sequence of characters (or symbols from an
alphabet)
A substring = 1 2 of a string = 1 2 is a string with
1 = , 2 = +1 , , = +1
A subsequence = 1 2 of a string = 1 2 is a string with
1 =
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Shortest Paths
in edge-weighted graphs
Communication Speeds in a
Computer Network
Find fastest way to route a data packet between two computers
6
1
4
56 Kbps
56 Kbps 56 Kbps
1 Gbps
3
5
100
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Prims Algorithm
Cut property
Initialize tree with single chosen vertex
Grow tree by finding lightest edge not yet in tree and
expanding the tree, and connect it to tree; repeat
until all v
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
5.3 S UBSTRING S EARCH
introduction
brute force
Knuth-Morris-Pratt
Boyer-Moore
Rabin-Karp
http: /al g s4 . cs . pr in c e to n . ed u
5.3 S UBSTRING S EARCH
introduction
brute force
Knuth-Morris-Pratt
Network Flow
Network Flow (Definitions)
A flow network is an edge-weighted, directed graph with positive
edge weights, called capacities (capacities of non-existing edges
are zero)
An st-flow network is a flow network that has two identified vertices,
nam
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Pseudocode: Kruskals
Algorithm
Algorithm KruskalMSTNaive(G = (V,E)
1. sort edges in E according to weight
2. Initialize ET as empty set
3. pick lightest edge e in E; remove e from E
4. If
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Abstract Meaning of the Term Graph
A graph G = (V, E) is a set V of vertices (nodes) and
a collection E of pairs from V, called edges (arcs).
Graph Example:
V A, B, C , D
A
C
B
D
A, B, A
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Quick-find [eager approach]
Data structure.
if and only if
Integer array id[] of length .
Interpretation: id[p] is the id of the component containing p.
id[]
0
1
2
3
4
5
6
7
8
9
0
1
1
8
8
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Kruskals algorithm requires an efficient way of
testing whether an edge creates a cycle with the
edges already selected.
The union-find
helps do this.
data structure
Union-find (or disjoin
Statistics 255 Section A01
Midterm 3 Version 1
November 26th, 2010
Last Name, First Name: gmagtrtrz cfw_:2 N :73
Student Number:
Instructor: Dr. Louis Deaett
r
IHIS TEST HAS 8 PAGES INCLUDING THIS SHEET.
Instructions:
Write your name and student n
Statistics 255 Section A01
Midterm 2 Version 1
October 29th, 2010
Last Name, First Name: QC) LA? i Q N 5
Student Number:
Instructor: Dr. Louis Deaett
THIS TEST HAS 8 PAGES INCLUDING THIS SHEET.
Instructions:
0 Write your name and student number (excluding
Statistics 255 Section A01
Midterm 1 Version 1
October lst, 2010
SOLuT\ONS
Last Name, First Name:
Student Number:
Instructor: Dr. Louis Deaett
THIS TEST HAS 8 PAGES INCLUDING THIS SHEET.
Instructions:
0 Write your name and student number on this page and
UNIVERSITY OF VICTORIA
EXAMINATIONS APRIL 2016
COMPUTER SCIENCE 226 (A01/A02, CRN 20723/20724)
NAME: I.M. Solution
INSTRUCTOR: Frank Ruskey
.
REG. NO.
SECTION: A01/A02
DURATION: 3 Hours
TO BE ANSWERED ON THE PAPER
STUDENTS MUST COUNT THE NUMBER OF PAGES I
UNIVERSITY OF VICTORIA
MIDTERM EXAM JUNE 2016
COMPUTER SCIENCE 226 (A01/A02)
NAME: I.M Solution
INSTRUCTOR: Frank Ruskey
.
STUDENT NO. V314159265358
SECTION: A01/A02
DURATION: 75 minutes.
TO BE ANSWERED ON THE EXAM PAPER
STUDENTS MUST COUNT THE NUMBER OF
CSC 226 FALL 2016
ALGORITHMS AND DATA STRUCTURES II
ASSIGNMENT 1 - WRITTEN
UNIVERSITY OF VICTORIA
1. Consider the insertion of items with the following keys (in the given order) into an initially empty
AVL tree: 30, 40, 24, 58, 48, 26, 11, 13, 17. Draw th
CSC 226 FALL 2016
ALGORITHMS AND DATA STRUCTURES II
ASSIGNMENT 4 - WRITTEN
UNIVERSITY OF VICTORIA
1. Write a pseudocode description of the printLCS() algorithm, which prints the longest common
subsequence of two strings and . Your algorithm takes as input
1. a) Sum of edges from cut S to cut T: (From vertex a) 9 + 15 + 4 = 28 (From vertex f) 10 + 6 = 16
(From vertex s) 15 + 5 = 20, making a total of 28 + 16 + 20 = 64
b) Sum of edges from cut S to cut T: (From vertex s) 15 + 10 = 25 (From vertex c) 4 + 8 =
1. At least 500 calories, at least 20 mg. of vitamin C, and at least 300 mg. of calcium.
Food
Milk
Mangoes
Orange Juice
Bananas
Cost per 100g
(In cents)
24
67
31
17
Vit C per 100g
0mg
28mg
50mg
8mg
Calcium per 100g
130mg
10mg
11mg
0mg
Calories per 100g
50
/Brandon Macleod
/V00830599
public class MinMax cfw_
public static int counter = 0;
public static Pair mmA(int lb, int ub, int[] a) cfw_
int min, max, mid;
Pair p1;
Pair p2;
if (ub = lb) cfw_ /if n = 1
return new Pair(a[lb], a[ub]);
else if (ub = lb + 1)
Reading input values from input.txt.
Reading graph 1
Graph 1: Minimum weight of a 0-1 path is 15531
Reading graph 2
Graph 2: Minimum weight of a 0-1 path is 8066
Reading graph 3
Graph 3: Minimum weight of a 0-1 path is 7166
Reading graph 4
Graph 4: Minimu
Lab 3: About
Assignments
Zhuoli XIao
Code
From Last Lab
private static int quickSelect(int left,int right, int[] array, int k)cfw_
if (left>=right)cfw_
return array[left];
int p=pickRandomPivot(left,right);
int eIndex=partition(left,right,array,p);
if (k
Lab 10: Final
Review
Zhuoli Xiao
Topics After Midterm
Minimum Spanning Tree
Union-Find and Quick Union-Find
Prim and Boruvka
Single Path Shortest Path
All Pairs Shortest Path
Longest Common Subsequence
Pattern Matching
Graph
Vertex vs. Edge
Directed vs. U
Lab 7: MST and
Heap
Zhuoli Xiao
MST
A minimum spanning tree (MST) or minimum
weight spanning tree is a subset of the edges of a
connected, edge-weighted undirected graph that
connects all the vertices together, without any
cycles and with the minimum poss
Implementation of BFS
In this lab, we will implement BFS together. There is a lot of applications of BFS.
For example, in course slides, BFS is used to compute a spanning tree of a given
graph. In our implementation, we will extend BFS a little bit more,
Lab 8 : Exercise
on Finding Paths
Zhuoli Xiao
Use Dijkstra to find distances from node A to all the
other edges.(E1.)
Use Bell-Fordman to find distances from node A to all
the other edges.(E1.)
What about directed graph?(E3)
Use Bell-Fordman
How to model
CSC 226 FALL 2016
ALGORITHMS AND DATA STRUCTURES II
ASSIGNMENT 1 - PROGRAM
UNIVERSITY OF VICTORIA
1 Programming Assignment
The assignment is to design and implement the LinearSelect algorithm and compare it to the QuickSelect
algorithm. The problem is def