Math 382: Homework 5
Due: Friday, March 29, 2013.
1. In class we examined binary heaps implemented using an array. These have at most two children
beneath each heap node. Describe how the heap code would change if we used ternary heaps, trees
whose nodes
3. For the binary operations on polynomials below I name the polynomials p1 and p2 (instead of p and q ) for a certain clarity. In my runtime analysis I assume that p and p1 have
n terms and that p2 has m terms.
(a)
EVAL :
The code below gives my implemen
Math 382: Homework 4
Due: Monday, March 4th
Scala due: Monday, March 11th
1. Write pseudocode for a linked list implementation of a polynomial class Poly, one whose terms
have integer coefcients. It should have these operations:
p.EVAL (v : Int) : Int ev
Math 382: Solution to Homework 3
1. If you examine the following code, and let n be used for the size of the array A[i.j ]
T WO -T HIRDS -S ORT(A, i, j )
1 if A[i] > A[j ]
2
swap A[i] with A[j ]
3 if j i > 1
4
k := (j i + 1)/3
5
T WO -T HIRDS -S ORT(A, i,
hw3.txt
Fri Feb 15 09:43:20 2013
1
-MATH
382
Homework 3
Due 2/20/13
-Reading: Ch. 7 of CLRS
Exercises:
1. Consider the following sorting algorithm:
TWO-THIRDS-SORT(A,p,r):
-1 if A[p] > A[r] then
2
exchange A[p] with A[r]
3 if p - r <= 1 then return
4
k :=
Math 382: Solution to Homework 2
1. Here is the set of orderings for the given functions where I use f < g to mean f = o(g )
and f = g to mean f = (g ). This is not standard notation, but convenient.
1 = 2 = n1/ lg n < lg(lg n) < lg n = lg (lg n) < 2lg
n
hw2.txt
Fri Feb 15 09:43:44 2013
1
-MATH
382
Homework
2
Due: 2/13/13
-Reading: Ch. 3 of CLRS
Exercises:
1. In Scala write an "iterative" version of merge sort, that
mimics the activity of the following pseudocode:
ITERATIVE-MERGE-SORT(A):
-n := A.length
i
-MATH
382
Homework 1
Due:2/6/13
-Reading: Ch. 1 & 2 of CLRS
Exercises:
1. Using the example Scala code lec1_2.scala as a starting point,
write two sorting procedures in Scala:
a. Bubble Sort: See Problem 2-2 on page 40 of CLRS for a description.
b. Select
/
/ class Stack
/
/ Defines a Stack that holds integers.
/
/ The stack is of fixed capacity: it holds at most the number
/ of elements passed to the constructor. For example, to
/ build a Stack that can hold 100 integer values, you would
/ write code like
/
/ class Queue
/
/ Defines a Queue that holds integers.
/
/ The queue is of fixed capacity: it holds at most the number
/ of elements passed to the constructor. For example, to
/ build a Queue that can hold 100 integer values, you would
/ write code like
-MATH
382
HOMEWORK 6
-Written assignment:
1. Problem 12-2 in CLRS on radix trees
2. Problem 13.2-4 in CLRS on transforming trees by rotations
3. BONUS: Problem 13.2-5 in CLRS on right-rotation reachability
Programming assignment:
I've provided (on a link