Exercises 21 : lower bounds on sorting, bucket sort,
independence (modified April 6 dropped 2 questions formerly Q3,Q4)
Questions
1. Give a lower bound on the best case scenario for any comparison-based sorting algorithm, as a
function of n. That is, you
Exercises 22 : data compression
Questions
1) One natural approach to finding an optimal prefix code, suggested in the lecture, is as follows:
given a sample space S and a probability function p(), partition S into two sets (events) whose
probabilities are
Exercises 20 : randomized select
Questions
1. Suppose you choose a pivot randomly for a list of size n. What is the probability that the
resulting two lists l1 and l2 will both have size at most 9 n /10 ?
2. In the proof of the linear time expected perfor
Exercises 16: closest pair of points
Questions
1. In the closest pair of points algorithm, one of the subproblems is to find the closest pair of
points with one point in the left half and one point in the right half. If we use brute force for
that problem
Exercises: shortest paths revisited (Bellman-Ford,
Floyd-Warshall)
Questions
1. In the lecture, we saw that we didt need to use O(n^2) space for Bellman Ford by keeping track
of the previous node in a shortest path. Could we apply similar idea to the prob
Exercises 17: Karatsuba multiplication, Master method
Questions
1. In Karatsuba multiplication, when you do the multiplication (x1 + x0)*(y1 + y0), the two values you
are multiplying might be n/2 + 1 digits each, rather than n/2 digits, since the addition
Exercises 19 : average case
Questions
1.
Here are a few questions about amortized analysis.
a) In Java, the ArrayList class is an implementation of a list class that uses an underlying array.
One nice property of a Java ArrayList is that the user doesnt n
Exercises 18 : quicksort and select (deterministic)
Questions
1. In the lecture, when I presented linear time selection algorithm, I partitioned the list into two
lists whose elements were less than the pivot (l1) and greater than or equal to the pivot (l
Exercises: subset sum and knapsack (modified
March 7)
Questions
1. Why is knapsack a more general problem than subset sum. (Give a formal answer.)
2. Consider an instance of subset sum in which w1 = 1, w2 = 4, w3 = 3, w4=6 and W = 8.
the table of opt(i, w
Exercises: Network Flows 1
Questions
1. On the left below is flow network (G,c) with s at the top left corner and t at the lower right. On
the right is a flow f. Verify for yourself that the flow satisfies the conservation conditions. Draw
the residual gr
Exercises: Bipartite Graphs
Questions
For all questions, assume we are talking about undirected graphs.
1) Suppose you have a connected graph and you do depth first search (DFS) from an arbitrarily chosen
vertex. This defines a DFS tree. There may be edge
Exercises: segmented least squares
Questions
1. In the lecture I claimed there were 2^cfw_N-1 ways to partition the sequence cfw_1, 2, , N into k
disjoint sequences (or segments) where, by definition, the segments contain consecutive
numbers (or a single
Exercises: interval scheduling [Last updated March 3]
Questions
1. Consider the greedy algorithm (#3, see lecture) for interval scheduling which picks the compatible
interval that finishes as soon as possible. We saw in class that this gives an optimal so
Exercises: Network Flows 2
Questions
1.
Consider a flow network G,
and a flow f, where I have written f(e)/ c(e) at each edge. (This is a notation that is commonly
used to show both the flow and capacities on a single graph).
Draw the residual graph G_f a
STUDENT NAME: \
STUDENT ID. NUMBER: \
FACULTY OF SCIENCE
FINAL EXAM
COMPUTER SCIENCE COMP-25] A
COURSE TITLE: DATA STRUCTURES AND ALGORITHMS
Examiner: Godfried T oussaint Date: December 7, 2004
Associate Examiner: Mike Hallet Time: 14:00 17:00
Instruction
Mid-Term Exam 1 Solutions
COMP 251 Algorithms and Data Structures
Tues. Feb. 4, 2014
Prof. Michael Langer
1)
a)
GRADING SCHEME: 2 points total. We have 0.5 for inserting the 45 at the correct place. This
makes the tree unbalanced. The first rotation gets
Mid-Term Exam 1
COMP 251 Algorithms and Data Structures
Tues. Feb. 4, 2014
Prof. Michael Langer
STUDENT NAME: _
ID: _
Instructions:
You may use a small number of pages of notes.
No electronic devices are allowed.
If your answer does not fit on a page, the
Mid-Term Exam 2
COMP 251 Algorithms and Data Structures
Tues. March 11, 2014
Prof. Michael Langer
LASTNAME: _
FIRSTNAME: _
Instructions:
You may use a small number of pages of notes.
No electronic devices are allowed.
If your answer does not fit on a page
package a2posted;
import java.util.ArrayList;
import java.util.HashMap;
/*
* Here is the solution code for Assignment 1 in COMP 251 Winter 2014.
*
* Written by Michael Langer
*
* This basic heap implementation is a modified version of Wayne and Sed
package a1solution;
import java.util.ArrayList;
import java.util.HashMap;
/*
* Here is the posted code for Assignment 1 in COMP 251 Winter 2014.
*
* Written by Michael Langer
*
* This basic heap implementation is a modified version of Wayne and Sed