Florida International University
School of Computer and Information Sciences
Introduction to Machine Learning
CAP 5610
Professor Ruogu Fang
ASSIGNMENT 2
Name: Gregory Murad Reis
PantherID: 5488749
Mia
Problem 1:
Exercise 15.4-3
Give a memoized version of LCS-LENGTH that runs in O(mn) time.
Answer:
LCS-LENGTH(X, Y)
m <- length[X]
n <- length[Y]
for i <- 1 to m do
for j <- 1 to n do
c[i,j] <- -1
end
Problem 1-1
2.1-2
INSERTION-SORT(A) (non-increasing)
1. For j=2 to A.length
2. Key = A[j]
3. /insert A[j] into the sorted sequence A[1.j-1].
4. i=j-1
5. while i>0 and A[i] <key
6.
A[i]=A[j]
7.
i=i-1
8
Exercise 15.4-5
Give an O(n2)-time algorithm to find the longest monotonically increasing
subsequence of a sequence of n numbers.
Answer:
Let S[1]S[2]S[3].S[n] be the input sequence.
Let L[i] , 1<=i <
Problem 4Data Structures
1. Hash Table
(1) A hash table generalizes the simpler notion of an ordinary array. the
average time to search for an element in a hash table is O(1).When the
number of keys a
Florida International University
School of Computer and Information Sciences
Introduction to Algorithms
COT 5407
Professor: Ning Xie
Teaching Assistant: Kianoush Gholami
ASSIGNMENT 1
Name: Gregory Mur
Florida International University
School of Computer and Information Sciences
Introduction to Algorithms
COT 5407
Professor: Ning Xie
Teaching Assistant: Kianoush Gholami
ASSIGNMENT 2
Name: Gregory Mur
Florida International University
School of Computer and Information Sciences
Introduction to Algorithms
COT 5407
Professor: Ning Xie
Teaching Assistant: Kianoush Gholamiboroujeni
ASSIGNMENT 3
Name: Gr
Florida International University
School of Computer and Information Sciences
Introduction to Machine Learning
CAP 5610
Professor Ruogu Fang
ASSIGNMENT 1
Name: Gregory Murad Reis
PantherID: 5488749
Mia
Florida International University
School of Computer and Information Sciences
Introduction to Machine Learning
CAP 5610
Professor Ruogu Fang
ASSIGNMENT 3
Name: Gregory Murad Reis
PantherID: 5488749
Mia
Exercise 6.3.3
Answer
First, let's observe that the number of leaves in a heap is n/2. Let's prove it by inducton on h.
Base: h=0. The number of leaves is n/2=n/20+1.
Step: Let's assume it holds for n
Exercise
11.1-2
A bit vector is simply an array of bits (0s and 1s). A bit vector of length m
takes
much less space than an array of m pointers. Describe how to use a bit
vector
to represent a dynamic
Sorting
algorith
m
Worst
case
running
time
Average
case
Running
time
Best
Case
Running
time
Auxiliar
y space
stability
Insertio
n sort
O(n2)
O(n2)
O(n)
In-place
O(1)
Stable
Heap
sort
O(nlgn)
O(nlgn)
O
Exercise 22.3-5
To prove some properties on different types of edges:
(a) : Assume that edge (u, v) is a tree or forward edge. If (u, v) is a tree edge, then by
the definition of tree edge v is first