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
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
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
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 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
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
Is bumpy chiral? One picture of bumpy:
Small
Rhombicosadodecahedron
[On Big Bang Theory]
Pictures from:
Great
Rhombicosadodecahedron
[rhombi]
http:/upload.wikimedia.org/wikipedia/commons/3/31/Small_rhombicosidodecahedron.png
http:/gnu.ist.utl.pt/software/
Principle of Mathematical Induction
Let P (n) be a proposition (true or false statement) involving an integer
n and suppose that we are trying to prove the following statement.
n 0, P (n)
Mathematical induction is the following principle.
(
P (0) and
k 0,
37
cfw_ program part 6.1
find the largest and smallest number in a given list
,ther
,ents
, are
arooram minmaxcfw_input, output):
Le.o.ti.
canst
Irize
~
an
type
'iler
;8 of
:ode.
; the
18 of
, and
may.
.5
'ined
:ype.
In be
the
luare
i.n~
Hd a
!ctor
t.
a
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
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
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
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
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
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 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. Use the algorithm from last class to walk all
the faces for the embedding represented by this
rotation system.
2. Does it represent a planar embedding?
Recall: g= (2 n + m f)/2
0: 1 3 5
1: 0 2
2: 1 5 3
3: 0 2 4
4: 3 5
5: 0 4 2
Now available:
Project li
1
Sorting
The utility of sorting algorithms is well recognized. For many algorithms and applications
the most time-consuming portion is that spent on sorting, and so much effort has gone
into discovering fast sorting algorithms. In this chapter we explore
10/10/2016
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Implementation of red-black
trees
The Sedgewick book has a nice implementation of
red-black trees
Search implementation for red-black BSTs
Observation. Search is the same as for
10/31/2016
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
/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)
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
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 =
10/16/2016
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
11/20/2016
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 ve
9/28/2016
CSC 226
Algorithms and Data Structures: II
Fall 2016
Rich Little
1
Red-Black Trees
Balanced binary search tree
A different representation of 2-3 tree
Definition: Red-Black Tree
A red-black tree is a binary search tree where each
link/edge is eit
10/19/2016
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 fr