Category Archives: Homework

Heaps and Heaps Sort

October 6th, 2015

Heaps and Heap Sort

Screen Shot 2015-10-08 at 1.14.31 PM

Homework:
1. Draw the max-heap that results from adding the following integers (34 45 3 87 65 32 1 12 17).
2. Starting with the resulting tree from Exercise 11.1, draw the tree that results from performing a removeMin operation.
3. Starting with an empty minheap, draw the heap after each of the following operations:
addElement(40);
addElement(25):
removeMin();
addElement(10);
removeMin();
addElement(5);
addElement(1);
removeMin();
addElement(45);
addElement(50);

Iterator and ReverseArrayIterator

September 30th, 2014

Classwork:
Visit the Classroom Salon
1. How does an iterator compare to a for each construct?
2. What must a collection implement to an iterable collection?
3. What methods must the Iterator class include? Elaborate your answer.
4. What mechanism does java use to enable/enforce the implementation of these methods?
5. Why are Iterators generic?
6. How is the ReverseArrayIterator implemented?
7. What is an iterator?
8. What is the implementation of the Iterator interface?
9. How is the ReverseArrayIterator implemented?
10. Why are the methods implemented in a nested class within client classes?
11. What two cases should throw exceptions to conform to the Iterator specification?
12. Why aren’t these two exceptions implemented?
13. Is it necessary to import Iterable? Iterator?

Homework:
Write a stack client Parentheses.java that reads in a text stream from standard input and uses a stack to determine whether its parentheses are properly balanced. For example, your program should print true for [()]{}{[()()]()} and false for [(]).

Spanning Trees

May 26th, 2015

Screen Shot 2015-05-25 at 10.13.16 PM

Screen Shot 2015-05-25 at 10.13.26 PM

Definition:

Given an undirected edge-weighted graph, a spanning tree of a graph is a connected subgraph with no cycles that includes all the vertices. A minimum spanning tree (MST) of an edge-weighted graph is a spanning tree whose weight (the sum of the weights of its edges) is no larger than the weight of any other spanning tree.

Reading assignment:
Assumptions, Underlying principles, Proposition(Cut property), Proposition (Greedy MST algorithm), and Edge-weighted graph data type.

Homework:
1. How would you find a maximum spanning tree of an edge-weighted graph?
2. Minimum bottleneck spanning tree. A minimum bottleneck spanning tree of a weighted graph G is a spanning tree of G such that minimizes the maximum weight of any edge in the spanning tree. Design an algorithm to find a minimum bottleneck spanning tree.