CMSC351, Spring 2015
Homework 3
Due: Friday, February 27, 2015
1. Assume your machine has 64 bit words. Assume you can multiply two n word numbers in time
3n2 with a standard algorithm. Assume you can multiply two n word numbers in time 12nlg 3
with a fan

CMSC 351:Summer 2012
Clyde Kruskal
Information CMSC351
Asymptotic Notations.
(g(n) = cfw_f (n): there exist positive constants c1 , c2 , and n0 such that 0 c1 g(n) f (n) c2 g(n) for
all n n0 .
O(g(n) = cfw_f (n): there exist positive constants c and n0 su

9,
r. (15poinb) Usethe 'MNtsr Tho@) deliEd hcl* to solreMily the fonsinar@n
e
Bunias 2 tu 3p(nE of3: 4') = rr(,/3) + 4,2 + r,
srnprji. shd yaumrk.
"(r):5.
1f' i; ) "tt"' - .na
'
Cv Z
a.
" "-
(s,
c. ' i
,7
'
t
z l,\'-\
d,.L
\z)
L
^ -j (s'z6qi - - ln'
o)n
z

CMSC351
Homework 2
Due: Wed, February 26, 2014
Put your name and section number on your solution.
1. Assume your machine has 32 bit words. Assume you can multiply two n word numbers in time
2n2 with a standard algorithm. Assume you can multiply two n word

CMSC351
Homework 0
Put your name and section number on your solution.
Problem 1. Use mathematical induction to show the following:
(a)
n
i(i + 1) =
i=1
(b)
n(n + 1)(n + 2)
3
n
2i = 2n+1 1
i=0
Problem 2. See next page.
(a) Assume bx = a. What is x (in term

Fall 2012 Clyde Kruskal
CMSC 351
Solutions to Homework 2
Problem 1. Bubble sort:
(a) How many comparisons:
(71-1)
i,ii;iii Bubble sort always does n comparisons.
2
(b) Exchanges:
(i) Best case: The rsttwo elements (or any neighboring pair) are inve

CMSC 351:Summer 2013
Clyde Kruskal
Information CMSC351
Logarithms.
a = blogb a
logb a =
logc (ab) = logc a + logc b
1
logb (1/a) = logb a
logb a =
loga b
logc a
logc b
Stirlings Formula.
n!
n
e
n
logb an = n logb a
alogb n = nlogb a
2n
Recurrences Master

Summer 2009
Clyde Kruskal
CMSC 351: Practice Questions for Midterm Exam
These are practice problems for the upcoming midterm exam. You will be given a sheet
of notes for the exam. Also, go over your homework assignments. Warning: This does not
necessarily

Summer 2013
Clyde Kruskal
CMSC 351: Practice Questions for Midterm Exam
These are practice problems for the upcoming midterm exam. You will be given a sheet
of notes for the exam. Also, go over your homework assignments. Warning: This does not
necessarily

Fall 2012
Clyde Kruskal
CMSC 351: Practice Questions for Midterm Exam
These are practice problems for the upcoming midterm exam. You will be given a sheet
of notes for the exam. Also, go over your homework assignments. Warning: This does not
necessarily r

Fall 2010
Clyde Kruskal
CMSC 351: Extra Practice Questions for Midterm Exam
These are practice problems for the upcoming midterm exam. You will be given a sheet
of notes for the exam. Also, go over your homework assignments. Warning: This does not
necessa

Fall 2010
Clyde Kruskal
CMSC 351: Practice Midterm
This is a sample for the upcoming midterm exam so you can see the style of the questions. You
will be given a sheet of notes for the exam. Warning: This does not necessarily reect the length,
diculty, or

CMSC 351:Fall 2010
Clyde Kruskal
Information CMSC251
Asymptotic Notations.
(g(n) = cfw_f (n): there exist positive constants c1 , c2 , and n0 such that 0 c1 g(n) f (n) c2 g(n) for
all n n0 .
O(g(n) = cfw_f (n): there exist positive constants c and n0 such

4 ' k ' h 1~ m e 2 e 1 m h l ' 1 h e & & & m q@t@%'(6j6ujh6(F%3njd(6vS~ ywmwFw ! o 6ffqS S
' l m ' 1 1 2 l ' 1 l ~ h 4 m e 2 h 4 ' 2 4 4 2 m l ' m ' d@36(q @6x3@' # j%h6(fj(63#6qcfw_@(6 o 6 S`|fqS S ~ ijF(7Rj o nhfS %hijf u tfS p t7 Rp q S z 76 S 7

CMSC351
Homework 4
Due: Wed, March 26, 2014
Put your name and section number on your solution.
1. Consider an array of size eight with the numbers 80, 30, 40, 70, 10, 20, 60, 50. Assume you execute quicksort using the version of partition from CLRS. Note

CMSC 351:Spring 2014
Clyde Kruskal
Information CMSC351
Logarithms.
a = blogb a
logb a =
logc (ab) = logc a + logc b
1
logb (1/a) = logb a
logb a =
loga b
logc a
logc b
Stirlings Formula.
n!
n
e
n
logb an = n logb a
alogb n = nlogb a
2n
Recurrences Master

CMSC351
Homework 8
Due: Friday, May 2, 2014
Put your name and section number on your solution.
You may want to wait until Monday to do Problem (2).
1. In Dijkstras algorithm, at each iteration the nodes y in Q that are adjacent to the node x
being process

CMSC351
Homework 6
Due: Wed, April 16, 2014
Put your name and section number on your solution.
1. Assume that we are trying to nd the kth smallest number in a list of size n. Assume that
we use the selection algorithm where we pivot on a random element. M

CMSC351
Homework 7
Due: Wed, April 23, 2014
Put your name and section number on your solution.
1. For each pair of expressions (A, B) below, indicate whether A is O, o, , , or of B.
Note that zero, one or more of these relations may hold for a given pair;

Spring 2014
Clyde Kruskal
CMSC 351: Practice Questions for Midterm Exam
These are practice problems for the upcoming midterm exam. You will be given a sheet
of notes for the exam. Also, go over your homework assignments. Warning: This does not
necessarily

' 0 " 0 ' " 0 )%) g ) h!)# 0 e s V| cfw_ c H 0 ' 0 e ' x ' 0 n 0 ' 0 k )Eo&qmfU!)!E4)Xr bUiE1IF f " 0 0 0 ' k ' 0 n C!)E`) f#)E)#yr)oAU ' n 0 myt !w)Er!#v#E&`myt trhv k 0 ' n 0 ' " 0 ' " k 0 f " k 0 e ' C&# lp)h!)0 #q)%) G)#)Ep CbUiE1IF " n k 0 " ' s V

d Comment
Search.
Create
Amanda 445
Crowdtilt is hiring Campus Ambassadors at UMD!
UMD Flyer Board
View All
Create Flyer
Begin your startup career. Build your resume. Crowdfund epic parties,
tailgates, events, and fundraisers. Get paid cash!
Posted by Cro

CMSC351
Homework 2
Due: Wednesday, February 18, 2015
1. For this problem, assume that you have access to a procedure Merge(A, B, C, m, n), that
merges two sorted arrays A[1.m] and B[1.n] into a single sorted array C[1.m+n]. This
procedure runs in m + n 1

Binary Search Trees
1
Binary Search Trees
Binary search trees are binary trees that satises the search tree property
that left children are less than or equal to the parent and right children
are greater than the parent. Note that because root choice is a

Bubblesort
1
Algorithm
Bubble the largest value in the array to the top by a series of exchanges,
then recurse (so to say) on the subarray A[:-1].
1
3
for i in [n , 2]:
for j in [1 , i -1]:
if A [ j ] > A [ j +1]:
A [ j ] , A [ j +1] = A [ j +1] , A [ j ]

Closest Pair
1
Algorithm
Given a list of 2D points P , nd the pair with the minimum Euclidean
distance between them. We assume that the input is presorted by both x
and y coordinates, so P = (Px , Py ). Divide and conquer by splitting the
input points in

Counting Sort
For Counting Sort, the input is n integers in some known range [0, k 1].
1
3
5
7
9
def CountingSort :
C = [0]* k , B = [0] * n
for j in [1 , n ]:
C [ A [ j ] += 1
# C = distribution
for i in [1 , k ]:
C [ i ] = C [i -1] + C [ i ] # C = Cumul

Simple Divide and Conquer Algorithms
1
Counting Inversions
Inversion: a pair indices i, j such that i < j and A[i] > A[j]. Possible
to solve problem in O(n log n) time by using the Mergesort algorithm:
1
3
5
count_and_split ( A ) :
if n = 1: return A , 0