CSc 220: Algorithms
Homework 11 Solutions
Problem 1: In class we saw that multiplying two n-bit numbers can be done in O(n2 ). What about long
division? Show an algorithm that on input integers a, b where a is n-bit long and b < a, computes a mod b
in O(n
CSc 220: Algorithms
Homework 10 Solutions
Problem 1: Given a polynomial P (x) of degree n and a value a, show how to divide P (x) by (x a) in
(n) time. In other words you must compute polynomial Q(X) of degree n 1 and value r such that
P (x) = Q(x) (x
a)
CSc 220: Algorithms
Homework 9 Solutions
Problem 1: In class we saw how to compute all-pairs shortest paths in a graph G by computing W n1
where W is the (weighted) adjacency matrix and W k is defined as W . . . W (k times) where is the
row-by-column matr
CSc 220: Algorithms
Homework 5 Solutions
Problem 1: We saw in class that given a binary search tree with n elements, we can output the elements
in sorted order using a O(n) in-order tree walk. Use this fact and the (nlogn) lower bound on the number
of com
COL351: Analysis and Design of Algorithms
Ragesh Jaiswal, CSE, IITD
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Divide and Conquer
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Divide and Conquer
Fast Fourier
CSc 220: Algorithms
Homework 1 Solutions
Problem 1: Assume that k, are constants with k 1 and 0 < < 1. Also log denotes the logarithm in
base 2, and ln the natural logarithm in base e. State which among A = O(B), A = (B) and A = (B) is
correct for each pa
CSc 220: Algorithms
Homework 7 Solutions
Problem 1: Given an undirected graph G = (V, E) you want to color the nodes Green and Yellow in
such a way that two nodes connected by an edge must have a different color. Use BFS to show how to
determine if such a
CSL 356: Analysis and Design of Algorithms (CSE, IIT Delhi, Semester I, 2011-12)
Major Exam
Name:
Entry number:
Always try to give algorithm with best possible running time. The points that you
obtain will depend on the running time of your algorithm. Fo
COL351: Analysis and Design of Algorithms
Ragesh Jaiswal, CSE, IITD
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Divide and Conquer
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Divide and Conquer
Median findin
CSE202: Design and Analysis of Algorithms (CSE, UCSD, Fall-2015)
Take-home Final
Name:
ID number:
Always try to give algorithm with best possible running time. The points that you obtain will depend
on the running time of your algorithm. For example, a s
COL351: Analysis and Design of Algorithms (Practice questions for Minor-I)
Instructor: Ragesh Jaiswal
1. Prove or disprove:
In any strongly connected undirected graph G = (V, E) with at least one vertex,
there is a vertex v such that if v and its edges a
CSL 356: Analysis and Design of Algorithms (CSE, IIT Delhi, Semester I, 2012-13)
Major Exam
Name:
Entry number:
Always try to give algorithm with best possible running time. The points that you
obtain will depend on the running time of your algorithm. Fo
CSc 220: Algorithms
Programming Assignment Solution
A Toeplitz matrix is an nn matrix A = (aij ) such that aij = ai1,j1 for i = 2, 3, . . . , n and j = 2, 3, . . . , n
(in other words, entries remain constant along each diagonal of the matrix).
Give an al
CSc 220: Algorithms
Homework 2 Solutions
Problem 1: Given a set A of n distinct integers we want to find the median of A, i.e. the element a A
such that
|cfw_x A : x a| |cfw_x A : x > a| 1
(the above is a fancy way to state that a is the element such that
CSc 220: Algorithms
Homework 3 Solutions
Problem 1: On input an array A of n elements, each of which is an integer in [0.n2 ], describe a simple
method for sorting A in O(n) time.
Solution: The idea is to write a number in [0.n2 ] in n-ary notation. In ot
COL351: Analysis and Design of Algorithms
Ragesh Jaiswal, CSE, IITD
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Divide and Conquer
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Divide and Conquer
Closest pair
CSc 220: Algorithms
Homework 6 Solutions
Problem 1: Suppose you have one machine and a set of n jobs a1 , a2 , ., an to process on that machine.
Each job aj has a processing time tj , a profit pj and a deadline dj . The machine can process only one job
at
COL351: Analysis and Design of Algorithms
Ragesh Jaiswal, CSE, IITD
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Computational Intractability: NP and NP-complete
Ragesh Jaiswal, CSE, IITD
COL351: Analysis and Design of Algorithms
Co
CSc 220: Algorithms
Homework 4 Solutions
Problem 1: Consider a binary heap of n elements stored in an array. Write an algorithm that deletes an
element at index k where 1 k n. The operation should maintain the heap order. Discuss the worst case
performanc
CSc 220: Algorithms
Homework 8 Solutions
Problem 1: A min-max spanning tree of an undirected weighted graph G, is a spanning tree T for G that
minimizes the weight of the heaviest edget in T . In other words: define maxw(T ) = maxe2T [w(e)] (rather
than t
Tutorial Sheet 5
August 24, 26 and 27
1. A drawer contains a dozen brown socks and a dozen black socks, all unmatched. A man takes socks out at random in
the dark.
(a) How many socks must he take out to be sure that he has at least two socks of the same c
Tutorial Sheet 3
Aug 10, 12, 13
1. Write the numbers 1,2,.,2n on a blackboard, where n is an odd integer. Pick any two of the numbers, j and k, write
|j - k| on the board and erase j and k. Continue this process until only one integer is written on the bo
Tutorial Sheet 6
Sept 6,8,9
1. Show that if a and b are both positive integers, then (2a 1) mod (2b 1) = 2a
mod b
1.
2. Use the above to show that if a and b are positive integers, then gcd(2a 1, 2b 1) = 2gcd(a,b) 1. [Hint: Show that
the remainders obtai
Solutions to Sheet 8
1
Let Ai , 1 i 3, be the set of sequences in which didgit i does not appear. Then we are interested in |(A1 A2 A3 )|.
Now |Ai | = 9n , |Ai Aj | = 8n and |A1 A2 A3 | = 7n . Hence |(A1 A2 A3 )| = 3 9n 3 8n + 7n and so |(A1 A2 A3 )| =
10