Fall 2014, Final Exam7 Introduction to Algorithms
Name:
Section:
Email id:
11th December, 2014
This is an open book, open notebook exam.
Answer all ten questions. Each Question is worth 10 points. You have 180 minutes to
complete the exam.
Happy Holidays
CSCI2300 - Algorithms Homework 1
Emmett Hitz - Section 2
February 12, 2015
1
1
Show that, if c is a positive real number,
then g(n) = 1 + c + c2 + + cn is:
Partial sum of a geometric series where n = 1 is
1cn+1
1c
(a) (1) if c < 1.
1 > 1 cn+1 > 1 c
1
1c >
Question 1:
Paths in graphs:
(a) (15pnts) Professor F. Lake suggests the following algorithm for finding the shortest
path from node 5 to node t in a directed graph with some negative edges: add a large
constant to each edge weight so that all the weights
CSCI 2300 Intro. to Algorithm, Fall 2015
Lab Number 7 Solutions
5.32
We simply proceed by a greedy strategy, by sorting the customers in the increasing order of
service times and servicing them in this order. The running time is O(n log n). To prove the
c
CSCI 2300 Lab 5, Fall 2015, 10/14/15
This lab is about graphs and algorithms. You are welcome to start working on the lab ahead of
time.
1. Do exercise 3.24 (DG) - pseudocode will suffice. (Hint: Find the longest path from the
source vertex - Bigger Hint:
1.
2.
The following graph is a counter-example. The shortest path from A to C is A-B, B-C.
However, according to the Professor, if we add +4, shortest path becomes A-C, which
is incorrect.
-2
-3
-2
1. 3.17
2. 3.22
3. 4.4
4. 4.8
The following graph is a counter-example. The shortest path from A to C is A-B, B-C.
However, according to the Professor, if we
CSCI2300 - Homework 3
Emmett Hitz - Section 4
March 14, 2015
1
1
1.1
A binary tree is full if all of its vertices have either zero or two
children. Let Bn denote the number of full binary trees with n
vertices.
By drawing out all full binary trees with 3,
import collections
def strongly_connected_components_path(vertices, edges):
identified = set()
stack = []
index = cfw_
boundaries = []
def dfs(v):
index[v] = len(stack)
stack.append(v)
boundaries.append(index[v])
for w in edges[v]:
if w not in index:
for
d(cu) du d(u + 1:) the (in 115(ou d1: via
1 = c1 2 . 3. u 11,
p A T E p Identity laws dz it it dz d '1! db dz 1" '11-
V F = 4 dfu) = 11.11" dz: 5 dfufu] = 1:13;) 11(3) 6 Me) = ggmdl
P P ' da tie: at: 93 :1: dz
v T a T Domination laws dos) = "i dun") = ii
Q1.
Let multiplications take O(n^2) time for two n-bit numbers.
Notice at that step i we multiply 2^2^i with itself. Each of these numbers takes O(2i) bits to store.
Therefore the cost of each multiplication is O(22i)
Total time is: sum_cfw_i=1^n 22i = 22
Q1
Q2
Q3
Q4
5.9 (a) False, consider the case where the heaviest edge is a bridge (is the only edge connecting two
connected components of G.
Q5.
Q6.
Q7.
Q8
Q2.2 Consider .
First, , since taking log on both sides, we see , which is always true
Second , since taking log on both sides, we get
() = + = 1 + , which is also always true.
Q2.4
Clearly c) is the best option.
Q2.5
Q2.16
Q2.19
Q2.22
Q2.25
CSCI 2300 Lab 8 Fall 2015, 11/11/15
This lab is about Dynamic Programming
1. Write a program to compute the length of longest nondecreasing
subsequence in a given array of integers. The following is the way we
formulated to compute the length at position
Question 2:
1. T (n) = T (n 1) + 1
T (n) = T (n k) + k
Set k = n
O(n)
2. Q(n) = Q(n 1) + n
Q(n) = Q(n k) + nk
Set k = n
O(n 2 )
3.R(n) = 2R(n 1) + 1
O(2n )
4. X (n) = 2 X ( n ) + 1
2
O(n)
5. Y (N ) = 2 Y ( n ) + n, Y (0) = 0
2
O(n l og n)
6. Z (n) = Z (sq