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 ;
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
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
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
1.
/*
* Smooths a given [email protected] Sequence<Integer>.
*
* @param s1
*
the sequence to smooth
* @param s2
*
the resulting sequence
*
* @requires |s1| >= 1
* @ensures <pre>
* |smooth| = |s1| - 1 and
* for all i, j: integer, a, b: string of integer
*
where (s
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
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
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#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
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]
Consider the following contract specification for the static method
smooth.
1
2
3
4
5 /*
* No informal description here for obvious reasons.
6 *
7 * @replaces s2
8 * @requires |s1| >= 1
9 * @ensures <pre>
* |s2| = |s1| - 1 and
1 * for all i, j: integer, a
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#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
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#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
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
Hw#30: Waiting Line Family Interface Design
Student name: Mingfeng Han
Professor Paolo Bucci
TA: Adam Wheeler and Isaac Post
Section: 11:30AM
package components.waitingline;
/*
* [email protected] QueueKernel enhanced with secondary methods.
*
* @param <String>
*
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
Context-Free Grammars
24 October 2013
OSU CSE
1
BL Compiler Structure
Tokenizer
string of
characters
(source code)
Parser
string of
tokens
(words)
Code
Generator
abstract
program
string of
integers
(object code)
The parser is arguably the most
interesting
Implementing an Iterator
27 June 2013
OSU CSE
1
Loose Ends
In implementing several kernel interfaces
so far, you have been given code in the
skeletons for the iterator method
The code for this method is stylized and
sometimes easy to adapt to a new
s
Using Statement and Program
23 October 2013
OSU CSE
1
Statement and Program
The Statement and Program
component families for the BL language
are similar to what a Java compiler uses to
represent a Java program
Consider refactoring of Java or BL
programs
Tree
4 March 2014
OSU CSE
1
Tree
The Tree component family allows you to
manipulate values modeled as
mathematical trees with any label type T
(i.e., tree of T)
4 March 2014
OSU CSE
2
Interfaces and Classes
Standard
Iterable
extends
extends
TreeKernel
ex
CSE2231
Homework 08
Ruiyang Chang
20170126
private static <T> void moveToFront(Queue<T> q, T x) cfw_
assert q != null : "Violation of: q is not null";
T var;
int length = q.length();
for (int i = 0; i < length; i+) cfw_
var = q.dequeue();
if (var.equals(x
CSE2231
Homework 05
Ruiyang Chang
20170118
Statement
List<Integer> list
= new SomeListImplementation<>();
list.add(7);
list.add(-12);
list.add(3);
int x = list.size();
x = list.get(1);
x = list.remove(0);
x = list.remove(1);
x = list.size();
4. You may ha
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.
CSE2231
Homework 03
Ruiyang Chang
20170113
1. Provide an argument justifying the following claim: The average (as defined here) of two Java ints i and j is
representable as an int, regardless of the lower and upper bounds on the value of an int.
According