CSE 3101: Design and Analysis of Algorithms
Assignment 4 - solutions
Note: This document provides solution sketches. It omits some details (e.g. showing that the Master
Theorem is applicable) that you must supply in tests and exams.
1. Problems that compl
COSC 3101: Design and Analysis of Algorithms
Assignment 3 - solutions
Problems:
1. A certain string processing language allows the programmer to break a string into two pieces. Since
this involves copying the old string, it costs n units of time to break
CSE 3101: Design and Analysis of Algorithms
Assignment 5b Solutions
Harder problems on Dynamic Programming
Note: This document provides solution sketches. It omits some details (e.g. some correctness proofs) that
you must supply in tests and exams.
Proble
CSE 3101 test 5
Summer 2010
July 20, 2010
Instructor: S. Datta
1. (10 points) A subsequence is a palindrome if it is the same whether read left to right or right to left. In this
problem, you are required to devise an algorithm that takes a sequence x[1,
COSC 3101: Design and Analysis of Algorithms
Assignment 3 (Released July 1, 2004)
Due date: July 16, 2004
Notes:
Feel free to refer to, and use any facts from the textbook.
In this course, assignments are meant to be done individually. Treat them like t
CSE 3101: Design and Analysis of Algorithms
Assignment on greedy algorithms - solutions
Note: This document provides solution sketches. It omits some details (e.g. some correctness proofs) that
you must supply in tests and exams.
1. Problem 470 of PoA.
So
CSE 3101: Design and Analysis of Algorithms
Assignment on graph algorithms - 2
1. The Strongly-connected-components (SCC) algorithm in the book uses two DFS calls and a graph
transposition. Here is an alternative algorithm suggested by a student that does
CSE 3101: Design and Analysis of Algorithms
Assignment on graph algorithms - solutions
Note: This document provides solution sketches. It omits some details (e.g. some correctness proofs) that
you must supply in tests and exams.
1. Do problem 22-1 (page 5
CSE 3101: Design and Analysis of Algorithms
Assignment on DP part 1 - solutions
Note: This document provides solution sketches. It omits some details (e.g. some correctness proofs) that
you must supply in tests and exams.
1. Problem 15.4-5 on page 356 in
CSE 3101: Design and Analysis of Algorithms
Assignment 1
Problems:
1. (5 points) Prove that the following algorithm for exponentiation is correct.
power(y, z )
1 / return y z where y R, z N
2 x1
3 while z > 0
4 do if odd(z )
5
then x x y
6
z z /2
7
y y2
8
CSE 3101 test 1
Summer 2010
May 18, 2010
Instructor: S. Datta
1. (5 points) Show that for every real constant a where a > 0,
(n + a)2 = (n2 ).
Hint: One way to prove () is to prove O() and () separately.
Solution:
Proof of O():
(n + a)2
(2n)2 for n > a
=
CSE 3101 test 2
Summer 2010
June 1, 2010
Instructor: S. Datta
1. (3 points) Prove or provide a counterexample. If f (n) = (g (n) then 2f (n) = (2g(n) ).
Solution: A counterexample is f (n) = n, g (n) = 2n. To show that f (n) = (g (n), we use the fact that
CSE 3101: Design and Analysis of Algorithms
Assignment 3 - solutions
Problems:
1. Compute the exact sum
n
n
(i j )2
i=1 j =1
Solution: One way to do this is to expand the expression. So
n
n
n
(i j )2
n
(i2 + j 2 2ij )
=
i=1 j =1
i=1 j =1
n
n
=
n
n
i2 +
=
COSC 3101A Midterm Exam part II
Summer 2003
June 11, 2003
Instructor: S. Datta
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Che
COSC 3101 Midterm Exam
Summer 2004
June 11, 2004
Instructors: S. Datta, T. Ji
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Chec
COSC 3101A Final Exam
Summer 2003
August 11, 2003
Instructor: S. Datta
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Check that
COSC 3101B: Design and Analysis of Algorithms
Exercise 4
Note: These questions are straightforward and I am really pressed for time. So I have provided hints
rather than solutions.
1. Draw a decision tree to nd the median of three numbers a, b, c. The dep
COSC 3101A: Design and Analysis of Algorithms
Exercise 3 solutions
Problems: For each of the following, answer yes or no, AND give VERY brief reasons/intuitions for
your answer.
1. For what constants a is the following true?
n
2n + 3 2 = O(an )
Solution:
COSC 3101B: Design and Analysis of Algorithms
Exercise 2 solutions
Problems: For each of the following, answer yes or no, AND give VERY brief reasons/intuitions for
your answer.
1. Suppose
n
k 3 = (f (n)
S=
k=1
what is f (n)?
Solution: Use the approximati
COSC 3101B: Design and Analysis of Algorithms
Exercise 1
Notes:
This is a 5-minute exercise.
Do not write proofs for any of your answers.
Problems: For each of the following, answer yes or no, and give VERY brief reasons/intuitions for
your answer.
1. I
COSC 3101A: Design and Analysis of Algorithms
Assignment 2 (Released May 28, 2003)
Due date: June 9, in class
Notes:
Feel free to refer to, and use any facts from the textbook.
In this course, assignments are meant to be done individually. Review the co
COSC 3101A: Design and Analysis of Algorithms
Assignment 1 (Released May 12, 2004)
Due date: May 26, 4pm
Notes:
Feel free to refer to, and use any facts from, Section 3.2 in the book.
In this course, assignments are meant to be done individually. Review
COSC 3101A Midterm Exam part I
Summer 2003
June 9, 2003
Instructor: S. Datta
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Check
COSC 3101A Final Exam
Summer 2003
August 11, 2003
Instructor: S. Datta
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Check that
COSC 3101A Midterm Exam part II
Summer 2003
June 11, 2003
Instructor: S. Datta
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Che
COSC 3101A Midterm Exam part I
Summer 2003
June 9, 2003
Instructor: S. Datta
Name (LAST, FIRST):
Student number:
Instructions:
1. If you have not done so, put away all books, papers, cell phones and pagers. Write your name and student
number NOW!
2. Check
COSC 3101B Midterm Exam Solutions
Note: I have skipped the steps needed to check that the Master Theorem can be applied. You are required
to write those steps in the exam.
1. (12 points) Warm-up questions:
n
n+1
(a) (2 points) Prove that 22 = o(22
n+1
Sol
COSC 3101A: Design and Analysis of Algorithms
Exercise 3 solutions
Problems: For each of the following, answer yes or no, AND give VERY brief reasons/intuitions for
your answer.
1. Given the recurrence T (1) = 1 and for n > 1, T (n) = 2T (n/2) + n/ lg n,
COSC 3101B: Design and Analysis of Algorithms
Exercise 2 solutions
Problems: For each of the following, answer yes or no, AND give VERY brief reasons/intuitions for
your answer.
1. Suppose
n
k 3 = (f (n)
S=
k=1
what is f (n)?
Solution: Use the thumbrule t
COSC 3101B: Design and Analysis of Algorithms
Exercise 1
Notes:
This is a 5-minute exercise.
Do not write proofs for any of your answers.
Problems: For each of the following, answer yes or no, AND give brief reasons/intuitions for your answer.
1. If f (