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
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
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
1. We will assume that the running time of multiplying n-bit numbers is M(n).
According to problem 0.4 in Chapter 0, fib3 involves O (log n) arithmetic
operations (multiplications). Since we are working in arithmetic mod p, each
intermediate result will b
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
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,
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 >
Lab1 solutions:
1. sqrt(2n),n+10,n^2log(n),n^(2.5),10^n,100^n (=10^(2n)
2. One possibility is to take the sum of the array and 2^n(2^n-1)/2 - sum will
give the desire number But sum could overflow - You can take exclusive or of
all the numbers a
CSCI 2300 Intro. to Algorithm, Fall 2015
Homework Number 4 Solutions
Exercise 3.17 (DG)
Problem 3.22 (DG)
(a) If every vertices occurs innitely often in Inf(p), it means that there must existing a cycle
connecting the. Therefore, Inf(p) is a strongly conn
Lab 3 Fall 2015
This lab is to review parts of Chapter 2 of Das Gupta et al's text book. Please go to your lab, do the
problems to get your full credit for the lab.
You are welcome to try this problem ahead of time.
1. Please plot n, vs T(n), Q(n), X(n),Y
s
Name: pb._(+$11) A
CSCI-2300 Introduction to Algorithms
ScoreExam
Monday 2/24
1-PAGE (2-SIDED) CRIB SHEET ALLOWED; NO CALCULATOR
USE PSEUDO-CODE AND DO NOT WRITE C+ CODE
ANSWER ALL QUESTIONS; USE EXTRA PAPER AS NECESSARY
1.
[18 POINTS] Determine the run
oZF
Fall 2011, Second Test, Introduction to Algorithms
Name:
Section:
Email id:
7th November, 2011
This is an open books, open notes exam.
Calculator is allowed, Internet is not allowed.
Answer all six questions. Each Question is worth 10 points. Yo
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
Fall 2012, Test 1, Introduction to Algorithms
Name:
Section:
Email id:
29th September, 2014
Answer all Six questions. You have 90 minutes to complete the exam.
You can use a calculator You are allowed to use your text books and notes. 1i Recursion and Des
Fall 2009, Final Exam, Data Structures and
Algorithms
Name:
Section:
Email Id:
21st December, 2009 (Winter Solstice)
This is an open book, open notebook exam.
Answer all twelve questions. Each Question is worth 10 points.
You have 180 minutes
to complete
Spring 2016
CSCI 2300 Introduction to Algorithms
Homework 1
Due February 12
Instructions: To solve these problems, you are allowed to consult your classmates, as well as the class
textbook (Algorithms by Dasgupta, Papadimitriou, and Vazirani, which we wil
import timeit
import sys
def fib1(n):
if n = 0: return 0
if n = 1: return 1
if n = 2: return 1
f = [None]*(n+1)
f[1] = 1
f[2] = 1
for i in range(3,n+1):
f[i] = f[i-1]+f[i-2]
return f[n]
if _name_ = '_main_':
n = int(input('enter a number: ')
start = timei
import timeit
import sys
import array
def fib2(n):
if n = 0: return 0
if n = 1: return 1
if n = 2: return 1
f = [None]*(n+1)
f[1] = 1
f[2] = 1
for i in range(3,n+1):
f[i] = f[i-1]+f[i-2]
return f[n]
if _name_ = '_main_':
n = int(input('enter a number: ')