Heaps and Heapsort
6 May 2013
OSU CSE
1
Heaps
A heap is a binary tree of T that
satisfies two properties:
Global shape property: it is a complete
binary tree
Local ordering property: the label in each
node is smaller than or equal to the label in
ea
CSE2231
Homework 06
Ruiyang Chang
20170119
@Override
public final T dequeue() cfw_
assert this.length() > 0 : "Violation of: this /= <>";
/ TODO - fill in body
T x = this.entries.remove(this.entries.length() - 1);
return x;
Question 2:
package components.
Page 1 of 7
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 5 SOME SOLUTIONS
1. Give the running time of the following functions, using -notation. Show your
work.
function f1 (n)
s 0 ;
for i 4 to n 2 do
for j 5 to 3i !log 2 i# do s s + i j ;
Page 1 of 6!
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 6 SOME SOLUTIONS
1. Either prove or disprove the following:
Claim: For all n 2 , the Hamming cube H n is bipartite.
SOLUTION: Its true. Proof: Fix n 2 . Let ODDn be the set of
binary
Page 1 of 11
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 7 WITH SOME SOLUTIONS
1. Answer each question True or False, justifying each answer.
(a)
( f (n) (n ) and f (n) O (n ) ( f (n) (n ) or f (n) (n )
2
3
2
SOLUTION: False, consider the
Page 1 of 3
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 9 SOME SOLUTIONS
1.
Consider the digraph G = (V, E ) where
V = cfw_1, 2, , n and E = cfw_(i, i +1) : 1 i n 1 .
Let G * be the transitive closure of G. How many edges does G * have? D
Page 1 of 8
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 8 with some SOLUTIONS
1. Assume that there is an algorithm that multiplies two 5-by-5 matrices with 88
scalar multiplications and 1000 additions. Consider a recursive algorithm A
page 1 of 5
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 2 WITH SOLUTIONS
1. Let P(x) be the predicate x is a dragon.
Let Q(x) be the predicate x breathes fire.
Let R(x,y) be the predicate x and y are the same object.
Rewrite the
CSE 2231 Homework 10
public static int mod(int a, int b) cfw_
assert b > 0 : "Violation of: b > 0";
int result = a % b;
if (a < 0 & result != 0) cfw_
result = result + b;
return result;
Bucket
Integers Hashed
0
<0,90>
1
<>
2
<432,-788>
3
<>
4
<54,84,-6>
University of Washington, Tacoma: TCSS 342A, Autumn 2004 (Stepp)
Final Exam: Thursday, December 16, 2004
KEY
1. (20 points): Linked Lists
public void swapPairs() cfw_
Node node = myFront;
/ fix up front
if (myFront != null)
myFront = myFront.next;
while (
Hw#14 : Insertion Sort
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Inserts the given [email protected] T in the [email protected] Queue<T> sorted according to
* the given [email protected] Comparator<T> and maintains the
Project: NaturalNumber on String
Objectives
1. Familiarity with writing a kernel class for a new type and its kernel operations
(NaturalNumber layered on String).
2. Familiarity with developing and using specification-based test plans.
The Problem
The pro
Hw#12 : BinaryTree and Recursion 2
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Returns the [email protected] String prefix representation of the given
* [email protected] BinaryTree<T>.
*
* @param <T>
*
the type
Hw#7 : Implementation of Set on Queue
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Finds [email protected] x in [email protected] q and, if such exists, moves it to the front
* of [email protected] q.
*
* @param <T>
*
typ
Hw#23: Statement and Recursion II
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Pretty prints [email protected] this to the given stream [email protected] out indented
* [email protected] indent spaces.
*
* @param out
*
th
Hw#27: Recursive-Descent Parser Evaluation of Boolean Expressions
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Evaluates a Boolean expression and returns its value.
*
* @param tokens
*
the [email protected]
Hw#21: Statement and Recursion
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Reports the number of calls to primitive instructions (move, turnleft,
* turnright, infect, skip) in a given [email protected] St
page 1 of 6
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 3 WITH SOLUTIONS
1. Let 1, 2 , , n be distinct lines in the Euclidean plane, and let A be
the set of points formed by intersections of these lines.
Characterize A using set
Hw#24: Tokenizer
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Returns the first "word" (maximal length string of characters not in
* [email protected] SEPARATORS) or "separator string" (maximal length stri
Page 1 of 6
CSE 2321 Foundations I Spring, 2013 Prof. Supowit
Homework 10 WITH SOME SOLUTIONS
1.
2. Modify the BFS algorithm so as to compute, for each vertex v in the graph, not only
v.dist (the length of shortest path from the source vertex s to v), b
Hw#11 : BinaryTree and Recursion 1
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
/*
* Returns the size of the given [email protected] BinaryTree<T>.
*
* @param <T>
*
the type of the [email protected] BinaryTree node lab
Homework#5
1. Classes implementing this interface can implement that method returning an
exception, invalid parameter etc. For example, a valid implementation choice can be
to throw an UnsupportedOperationException. Pitfall since you dont know what it
doe
/*
* Computes [email protected] a mod [email protected] b as % should have been defined to work.
*
* @param a
*
the number being reduced
* @param b
*
the modulus
* @return the result of a mod b, which satisfies 0 <= [email protected] mod < b
* @requires b > 0
* @ensures <pre>
*
Homework #4
1. Since an average is adding how many numbers there are in this case, two numbers, the number
average will always be between the larger number or the smaller number. The average is the
intermediary point between in this case these two numbers