1. (8 points) Goal: Practice analysis of algorithms. Consider the algorithm represented by the
following program fragment; assume that x and n are non-negative.
l1 BAR(int x, int n)
l2 cfw_
l3
int sum=0;
l4
if x>10 then cfw_
l5
for(inti=1; i<=n2; i+) cfw_
Homework 2
Due Date: February 23th, 9 PM
Homework should be submitted using WolfWare Submit Admin in PDF, or plain
text. To avoid reduced marks, please submit word/latex-formated PDF file, NOT
scanned writing in pdf format. Scanned writing is hard to read
Homework 3
Due date: Friday, October 30 submit by 11:00 PM
1. Purpose: reinforce your understanding of the matrix-chain multiplication problem,
memorization, and recursion.
a) (4 points) Please implement a recursive, dynamic programming, and a memoized
ve
Homework 3
Branch T. Archer, III
Due date: Friday, October 30 submit by 11:00 PM
1. Purpose: reinforce your understanding of the matrix-chain multiplication problem,
memorization, and recursion.
a) (4 points) Please implement a recursive, dynamic programm
Name: Bowen Jiang UnityID: bjiang6
Homework 2
Due Date: February 23th, 9 PM
Homework should be submitted using WolfWare Submit Admin in PDF, or plain text.
To avoid reduced marks, please submit word/latex-formated PDF file, NOT
scanned writing in pdf form
NP-Completeness
Outline of Topics
Problems for which no polynomial time solutions
are known
Optimization problems vs. decision problems.
The classes P, NP, and NP-Complete
Polynomial time reductions
The satisfiablity problem
NP-Completeness proofs
Notes o
CSC 505 Design and Analysis of Algorithms
Recommended Exercises on N P -completeness
Sketch of Solutions
0. Show if L P then L P .
If L P then there is a polynomial-time decider, A, for L. Modify algorithm A to get algorithm A0 so
that A0 does the same A,
5. Disjoint sets of elements in the range 1.64 are represented as trees by the parent array
p[1.64] and the rank array rank[164] with the initial values p[i] = i for 1 i 64 and
rank[i] = 0 for 1 i 64 (Make sure you implement the procedures as they are wri
CSC 505 - Design and Analysis of Algorithms - Spring 2006
Homework 3 - Solutions
1.
MEMOIZED-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] := infinity
return(LOOKUP-LENGTH(X,Y,m,n)
LOOKUP-LENGTH(X,Y,i,j)
if c
Initial Fibonacci heap
min
18
7
26
24
17
46
30
23
21
38
39
41
52
35
Q7 a First do a FIB-HEAP-DECREASE-KEY to decrease the key of the node with key 35 to the value 16.
1) Since 16 is smaller than it parent 26 it is cut off and made an unmarked root
min
16
CS 5114
Solutions to Homework Assignment 1
Jamal A. Khan
January 27, 2017
[20] 1. CLRS Problem 3-2. For those of you using LATEX, Figure 1 gives the table to
fill in.
#
A
B
1.
k
lg n
n
2.
nk
cn
O
o
yes yes
no
no
no
yes yes
no
no
no
n
nsin n
no
no
no
no
no
How to use data mining for water management
Supervisor
Astrid Fischer
Project duration
6 Months
E-mail
a.fischer@tudelft.nl
MSc/BSc student
MSc
Research field
Water treatment technologies, modelling, data analysis, data mining
Subject title
How to use dat
Quicksort algorithm
Average case analysis
After today, you should be able to
implement quicksort
derive the average case runtime of
quick sort and similar algorithms
http:/upload.wikimedia.org/wikipedia/commons/thumb/8/84/Partition_example.svg/200px-Parti
License key Activation
1) Install the software onto your machine by running the exe file. Once installed you need to open the .exe file
up and select Register. Another screen will appear where you need to select Register Online as shown
below.
REGISTRATIO
3
What to Measure
One accurate measurement is worth a thousand expert opinions.
Rear Admiral Grace Murray Hopper. USNR
The performance metric of interest in most algorithm research projects is that old
devil, time how long must I wait for my output to app
Problem 2:
For this problem, the plots I have are from an older semester in which
the heapsort plots are not separate from the others.
Ascending:
Descending:
1
Ones:
2
Zeros and Ones:
3
Randomized:
4
5
L: language over
A decider for L: is an algorithm A,
A : cfw_0, 1
such that A(x) = 1 if and only if x L.
If A is a decider for L,
A decides L in time T (n)
if T (n) is the maximum time required by A to
compute A(x) over all x with |x| = n.
Notes on Intro
CSC 505 - Design and Analysis of Algorithms - Fall 2008
Homework 5: Sorting and Order Statistics
Due Tuesday, September 23
For this assignment, there are five problems. Some of them involve programming and plotting. Students
will be divided into teams by
CSC 505 - Design and Analysis of Algorithms - Fall 2008
Homework 6: Dynamic Programming, Advanced Data Structures, Graphs
Due Thursday, October 16
For this assignment, there are 8 problems. Students will be divided into teams by the instructor. Each
team
Last Name,
First Name
CSC 505 - Design and Analysis of Algorithms - Fall 2008
Homework 4 - Worksheet
Due Thursday, September 11
Instructions
Write all answers on this worksheet. Write your name on each page, since pages will be separated for
grading.
Fi
Solution of Problem 5
1. Evaluate:
7 n + 3 7 n 1 + 32 7 n 2 + . + 3n
Answer:
Solution 1:
a1 (1 q N )
It is a geometric series, so sum of N terms is
,
1 q
N is number of terms, a1 is the first term and q is radio.
In this question,
a1 = 7 n
N = n +1
And
q=
Problem 3:
Define a nn matrix M = (mij) for n0 by
mij = 1
2
-1
0
if i = j = 1, else
if i = j, else
if | i-j| = 1, else
otherwise;
(a) Find the inverse of M
(b) Find the determinant of M
(c) Find M2
Here is the original matrix M and det(M):
M=
1
-1
0
0
.
.
Problem 4) Let Ai = cfw_i, i + 1, i + 2, . . ..
Note: More exact notation which aids in proofs would be defining Ai =
cfw_n N|n i
S
1. Find
Ai
i=1
Answer:
S
Ai = A1
i=1
Proof: Lemma 1:
S
Ai = N. By the defnition of the sets,
i=1
S
Ai
i=1
N, since each Ai
4 (a) Do a depth-first search and find the vertex whose finishing time
is the largest. Call it x. If G has a supersource, x must be a
supersource. If x is not a supersource, G has none. Now do a dfs
from x to see if every vertex is in the tree rooted at x
1. (8 points) Goal: Practice analysis of algorithms. Consider the algorithm represented by the following
program fragment; assume that x and n are non-negative.
l1 BAR(int x, int n)
l2 cfw_
l3
int sum=0;
l4
if x>10 then cfw_
l5
for(inti=1; i<=n2; i+) cfw_
CSC 505 - Design and Analysis of Algorithms - Fall 2008
Homework 7 - Solutions
1. (for directed graphs)
DFS-VISIT(u)
1)
color(u) GRAY ;
2)
d[u] time time + 1;
3)
for each v ADJ[u] do
4)
if color[v] = W HIT E then
5)
[v] u;
6)
output(tree edge, u, v);
7)
D
4. I computed two finishing times, F T 1 and F T 2, the first if line 2 of DF S V ISIT (u) is left in and the
second if it is deleted.
vertex :
FT1 :
FT2 :
q
16
8
r
20
10
s
7
3
t
15
7
u
19
9
v
6
2
w
5
1
x
12
5
y
14
6
z
11
4
Final forest:
r
u
q
y
x
s
z
w
t
CSC 505 - Design and Analysis of Algorithms - Spring 2006
Homework 4 - Sketch of Solutions
1. a. The d array contains this information at the end of the BFS, so for each vertex u 2 V [G] print (u; d[u]).
b. After line 8 add: \CYCLE FALSE."
After line 17 a
CSC 505-002 - Design and Analysis of Algorithms - Spring 2006
Homework 1 - Sketch of Solutions
1.
a. yes to o, O
b. yes to o, O
c. no to all
d. yes to ,
e. yes to , O,
f. yes to , O,
2.
a. false: f (n) = n, g(n) = n2
b. false: f (n) = n, g(n) = n2
c. t