COMP 3711 Design and Analysis of Algorithms
Solutions to Assignment 3
1. Define c[i] to be the length of the longest increasing subsequence that ends at xi . Note
that the length of the longest increa
COMP3711: Design and Analysis of Algorithms
Tutorial 4
HKUST
Tutorial 4
COMP3711: Design and Analysis of Algorithms
Question 1
Recall the randomized selection algorithm. We pick a pivot
randomly, divi
COMP4331 Assignment 2
Ching-Heng, WANG
20152407 [email protected]
Q1.
.
b)
k=3
k= 4
Q2:
.
(a.) Structure
I W0 = 0
I1
x
W1
Output =
i
I2
y
Input unit
1if summation 0
0 if summation<0
Ii *Wi
W2
hidden unit
COMP3711: Design and Analysis of Algorithms
Tutorial 4
HKUST
Tutorial 4
COMP3711: Design and Analysis of Algorithms
Question 1
Recall the randomized selection algorithm. We pick a pivot
randomly, divi
COMP 3711 Design and Analysis of Algorithms
Fall 2015
Assignment 3
1. Give an O(n2 )-time dynamic programming algorithm to find the longest monotonically increasing subsequence of a sequence of n numb
COMP 3711 Design and Analysis of Algorithms
Fall 2015
Written Assignment 1
1. For each pair of expressions (A, B) below, indicate whether A is O, , or of B. Note
that zero, one, or more of these relat
Lecture 14: Introduction to Graphs
The Seven Bridges of Knigsberg
Q: Can you find a path to cross all seven bridges, each exactly once?
Q: (Reformulated as a graph problem) Can you find a path in the
Lecture 13: Dynamic Programming
over Intervals
1
Longest Palindromic Substring
Def: A palindrome is a string that reads the same backward or forward.
Ex:
radar, level, racecar, madam
A man, a plan, a
COMP3711H: Honors Design and Analysis of
Algorithms
Tutorial 3
HKUST
Tutorial 3
COMP3711H: Honors Design and Analysis of Algorithms
Question 1
Heapify
In class, we learned how to maintain a min-heap i
Lecture 10: Huffman Coding
Encoding
Frequency (in thousands)
Fixed-length codeword
Variable-length codeword
a
b
c
d
e
f
45
000
13
001
12
010
16
011
9
100
5
101
0
101
100
111 1101 1100
Encoding: Replac
Lecture 11: Dynamic Programming
First Example: Stairs Climbing
Problem: Suppose you can take 1 or 2 stairs with one step. How many
different ways can you climb stairs?
Solution: Let () be the number o
Lecture 12: 2D Dynamic Programming
The 0/1 Knapsack Problem
Input: A set of items, where item has weight and value , and a
knapsack with capacity .
Goal: Find 1 , , cfw_0,1 such that
maximized.
=1
an
Lecture 8: Sorting in Linear Time
Running time of sorting algorithms
Do you still remember what these statements mean?
Sorting algorithm A runs in ( log ) time.
Sorting algorithm A runs in ( log ) tim
Lecture 5: Randomized Algorithms
The Hiring Problem
Hire-Assistant():
0
for 1 to
interview candidate
if candidate is better than then
fire
hire candidate
Problem: Whats the number of hires?
Wor
Lecture 9: Greedy Algorithms
A greedy algorithm always makes the choice that looks best at
the moment and adds it to the current partial solution.
Greedy algorithms dont always yield optimal solutions
COMP 3711 Design and Analysis of Algorithms
Spring 2016
Written Assignment 1
1. For each pair of expressions (A, B) below, indicate whether A is O, , or of B. Note
that zero, one, or more of these rel
COMP 3711 Design and Analysis of Algorithms
Lecture 1: Introduction
1
So, where are we so far?
Advanced Topics:
Database, Networking, Graphics, AI, Data Mining, Machine Learning,
COMP 3111:
Software
Lecture 4: Integer and Matrix Multiplication
More complicated examples of divide-and-conquer
Integer Arithmetic
Add. Given two -bit integers and , compute + .
() time
Multiply. Given two -bit integers
COMP 3711 Design and Analysis of Algorithms
2015 Fall
Solutions to Assignment 2
1. (a) O(n log n)
(b) Build the heap: O(n). Call Extract-Min k times: O(k log n). Total time: O(n +
k log n).
(c) Build
COMP 3711 Design and Analysis of Algorithms
2015 Fall
Solutions to Assignment 1
1. (a) A = (B);
(b) A = O(B), A = (B), A = (B);
(c) A = O(B);
(d) A = O(B), A = (B), A = (B);
(e) A = (B).
2. (a) T (n)
All-Pairs Shortest Paths
Version of August 3, 2017
Version of August 3, 2017
All-Pairs Shortest Paths
1 / 26
Outline
Another example of dynamic programming
Will see two dierent dynamic programming for
Union Find
Version of August 3, 2017
Version of August 3, 2017
Union Find
1 / 14
Disjoint Set Union-Find
A disjoint set Union-Find data structure supports three operations
on collections of disjoint s
COMP3711H: Design and Analysis of Algorithms
Tutorial 1 Review of Asymptotic Notation
COMP3711H: Design and Analysis of Algorithms
Tutorial 1 Review of Asymptotic Notation
Tutorial 1 Review of Asympto
COMP 3711 Design and Analysis of Algorithms
Fall 2015
Written Assignment 1
1. For each pair of expressions (A, B) below, indicate whether A is O, , or of B. Note
that zero, one, or more of these relat
COMP 3711 Design and Analysis of Algorithms (Fall 2015)
Written Assignment 2
1. Smallest k numbers in sorted order
Given a set of n numbers, we wish to nd the k smallest numbers in sorted order using
COMP3711: Design and Analysis of Algorithms
Tutorial 1
COMP3711: Design and Analysis of Algorithms
Tutorial 1
Tutorial 1
COMP3711: Design and Analysis of Algorithms
1/9
COMP3711: Design and Analysis o
COMP3711: Design and Analysis of Algorithms
Tutorial 2
HKUST
Tutorial 2
COMP3711: Design and Analysis of Algorithms
Question 1
Give asymptotic upper bounds for T (n) by recursion tree
approach. Make y
COMP3711: Design and Analysis of Algorithms
Tutorial 3
HKUST
Tutorial 3
COMP3711: Design and Analysis of Algorithms
Question 1
Give asymptotic tight bounds for T (n) by master theorem.
(a)
T (1) = 1
T
COMP3711: Design and Analysis of Algorithms
Tutorial 3
HKUST
Tutorial 3
COMP3711: Design and Analysis of Algorithms
Question 1
Give asymptotic tight bounds for T (n) by master theorem.
(a)
T (1) = 1
T
Chain Matrix Multiplication
Version of August 3, 2017
Version of August 3, 2017
Chain Matrix Multiplication
1 / 27
Outline
Outline
Review of matrix multiplication.
The chain matrix multiplication prob
Longest Common Subsequences and Substrings
Version August 3, 2017
Version August 3, 2017
Longest Common Subsequences and Substrings
1 / 16
Longest Common Subsequence
Given two sequences X = (x1 , x2 ,
Breadth-First Search
Version of August 3, 2017
Version of August 3, 2017
Breadth-First Search
1/9
Representations of Graphs: Adjacency List
V : set of vertices, E : set of edges.
(We will sometimes al
Into to Dynamic Programming
Version of August 3, , 2017
Dynamic Programming (DP) bears similarities to Divide and Conquer (D&C)
Both partition a problem into smaller subproblems
=> build solution of
Introduction to Graph Algorithms
Version of August 3, 2017
Version of August 3, 2017
Introduction to Graph Algorithms
1/1
Graphs
Extremely useful tool in modeling problems
Consist of:
Vertices
Edges
D