COMP 251 Autumn 2013 Homework 2 Solutions
Gheorghe Comanici and Prakash Panangaden
1. The students are either committed or uncommitted at any stage while a hospital either is available
or full. The algorithm is like the stable matching algorithm:
While th
Homework 1: Solutions
COMP 251 Autumn 2012
Instructor:Prakash Panangaden
1. Give an algorithm to nd the largest and the smallest number in an unordered set of n numbers. What
is the running time of your algorithm? I want an answer in the form k n + o(n) w
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
Computer Science COMP-251B
Midterm, Feb 17, 2005, 14:35-15:55.
O P E N B O O K S / O P E N N O T E S
1)
Let
T(n) =
1
T(
if n=1
n/5
) + T(
n/4
) + T(
n/3
) + O(n)
if n>1
Prove by constructive induction that T(n) is O(n).
2)
Explain how to make quick-sort r
Lecture 02017/01/05
Ofce Hours Tues/Thu 1-2pm
40% for 5 assignments, 15% for midterm, 45% for nal exam
Midterm March 9 (one crib sheet permitted, 2 pages), during class time ADAMS AUD
End of class April 11
Final exam April 21 2:00 PM
Lecture 12017/01/10
*
COMP-251B
Data Structures and Algorithms
Faculty of Science
Final Examination
Computer Science 308-251B
Data Structures and Algorithms
Examiner: Prof. Claude Crpeau
Associate Examiner: Prof. Patrick Hayden
Date: April 30, 2010
Time: 09:00 12:00
INSTRUCTIO
Computer Science COMP-251B
Midterm, Feb 18, 2010, 14:35-15:55.
O P E N B O O K S / O P E N N O T E S
1)
Let
T(n) =
1
if n=1
3T( n / 4 ) + T( n / 8 ) + O(n)
if n>1
Prove by induction that T(n) is O(n).
2) from Exercises 7.4-5
The running time of quicksort
Comp 251: Assignment 1
Answers must be returned online by February 4th (11:59pm), 2015.
Your solution must be returned electronically on MyCourse.
The only format accepted for written answers is PDF. PDF files must open on SOCS computers.
The solution
Comp 251: Assignment 2
Answers must be returned online by February 20th (11:59pm), 2015.
Your solution must be returned electronically on MyCourse.
The only format accepted for written answers is PDF. PDF files must open on SOCS computers.
Any additiona
Comp 251: Assignment 3
Instructor: Jrme Waldisphl
Due on March 18th at 11h59
Your solution must be returned electronically on MyCourse.
The only format accepted for written answers is PDF. PDF files must open on SOCS computers. Any additional files (e.g
Exercises: Dijkstras algorithm
Questions
1. In breadth first search, each vertex has a visited field which is set to true before the vertex is
put in the queue. What happens if BFS instead sets the visited field to true when the vertex is
removed from the
COMP 251A 2014, Assignment 4
Due Thursday December 4th 2014
[10%]
[15%]
[15%]
!
[20%] Problems 26-1: Escape problem
An n n grid is an undirected graph consisting of n rows and n columns of vertices, as
shown in Figure 26.11. We denote the vertex in the it
[20%]
COMP 251A 2014, Assignment 1
Due Monday September 29th 2014
1. Read Chapter 1. Solve Exercise 4.
!
!
[10%] 2. Read Chapter 2.
Prove that if
limn f(n)/g(n) = 0
then f(n) is O(g(n) but g(n) is not O(f(n).
3.Solve Exercises 1-3-5-6.
[15%]
Computer Science COMP-251B
Midterm, Feb 14, 2008, 14:35-15:55.
O P E N B O O K S / O P E N N O T E S
1)
Let
T(n) =
1
T(
if n=1
n/6
) + 2T(
n/3
) + O(n)
if n>1
Prove by constructive induction that T(n) is O(n).
2) Exercises 9.3-5
Suppose that you have a bl
Computer Science COMP-251B
Midterm, Feb 16, 2011, 16:05-17:25.
O P E N B O O K S / O P E N N O T E S
1)
a) Write a recursive algorithm such that the related time recurrence cannot be
solved with the Master Theorem.
b) Write two recurrences such that their
COMP-251B
Data Structures and Algorithms
Faculty of Science Final Examination
Computer Science 308-251B Data Structures and Algorithms
Examiner: Prof. Claude Crpeau Associate Examiner: Lecturer Martin Courchesne
Date: April 20, 2005 Time: 14:00 17:00
INST
COMP-251B
Data Structures and Algorithms
Faculty of Science
Final Examination
Computer Science COMP-251B
Data Structures and Algorithms
Examiner: Prof. Claude Crpeau
Associate Examiner: Prof. Clark Verbrugge
Date: April 18, 2011
Time: 14:00 17:00
INSTRUCT
COMP-251B
Data Structures and Algorithms
Faculty of Science
Final Examination
Computer Science COMP-251A
Data Structures and Algorithms
Examiner: Prof. Claude Crpeau
Date: Dec. 15, 2014
Associate Prof. Prakash Panangaden
Examiner:
Time: 9:00 12:00
INSTRUC
COMP 251A 2014, assignment 3
Due Wednesday Nov 12th 2014
[10%]
!
Note : It turns out that different domains for the xis yield very different solutions. So
lets explore that in details. You may choose one of two versions of this question as listed
below. I
Data
Structure
Time Complexity
Access
Array
Stack
Queue
SinglyLinked
List
DoublyLinked
List
Hash
Table
Binary
Search
Tree
RedBlack
Tree
AVL Tree
Average
Search Insertion Deletion
N/A
Sorting
Algorithm
Worst
Search Insertion Deletion
O(n)
O(n)
O(n)
O(n)
O(
COMP 251 2016, Assignment 4, due
Monday December 5th 2016 23:59
1. Maximum Deadline
[10%]
[10%]
[5%]
[5%]
[10%]
2. Critical edges
3. Blood Bank
[10%]
[10%]
10
4. Escape Problem (26-1)
An n n grid is an undirected graph consisting of n rows and n columns
COMP 251 Fall 2016, HW-3
Due Wednesday Nov 16th 2016, 23:59:59
[10%]
1) RBT-Sorting.
The input is a sequence of n integers with many duplications, such that the number
of distinct integers in the sequence is O(log n). Design a sorting algorithm (based
on
COMP 251 2016, Assignment 1
Due Wednesday September 28th 2016
[20%]
1. Read Chapter 1. Solve Exercise 4.
!
!
GS Men-optimal
Initialize each person to be free.
while (some man is free and hasn't proposed to every woman)
cfw_
Choose such a man m
w = 1st wo
Exercises for lecture 3: Hashing [last updated Jan. 22]
Questions
1. With quadratic probing and m = 16, where does the first collision occur?
2. Based on the simple scheme of user names and hashed passwords that I gave in class and your
own experiences wi
COMP 251 2016, Assignment 1
2. Either prove the following statement or exhibit a counter-example.
The solutions produced by both algorithms are equal
if and only if
this is the only solution to the input instance.
Two things have to be proved here:
A) (th
Exercises 1
COMP 423
Jan. 2008
1. Is it possible to construct a prefix code with six symbols that have codeword lengths i =
cfw_5 , 3 , 4 , 2 , 1 , 4. If so, then construct one. If not, then why not?
2. Consider an alphabet with three symbols where
p(A1 )
Comp 251: Algorithms and Data Structures
Assignment 3: Solutions
1. Money Changing.
(a) Let f (n) denote the fewest number of coins needed to add up to a total
value of n cents. Then we have the following recurrence:
f (n) = 1 + min f (n di )
1ik
To see t
import java.io.*;
import java.util.*;
class Edgecfw_
public int[] nodes = new int[2]; /*The nodes connected by the edge*/
public Integer weight; /*Integer so we can use Comparator*/
Edge(int i, int j, int w)cfw_
this.nodes[0] = i;
this.nodes[1] = j;
this