Java Reference
In-Depth Information
104
105 /**
106
Returns the index of the right child.
107 @param index
the index of a node in this heap
108 @return
the index of the right child of the given node
109 */
110
private static int
getRightChildIndex(
int
index)
111 {
112
return
2
* index +
2
;
113 }
114
115
private int
[] a;
116 }
755
756
S
ELF
C
HECK
17.
Which algorithm requires less storage, heapsort or merge sort?
18.
Why are the computations of the left child index and the right child
index in the
HeapSorter
different than in
MinHeap
?
CHAPTER SUMMARY
1. A set is an unordered collection of distinct elements. Elements can be added,
located, and removed.
2. Sets don't have duplicates. Adding a duplicate of an element that is already
present is silently ignored.
3. The
HashSet
and
TreeSet
classes both implement the
Set
interface.
4.
An iterator visits all elements in a set.
5. A set iterator does not visit the elements in the order in which you inserted
them. The set implementation rearranges the elements so that it can locate them
quickly.
6. You cannot add an element to a set at an iterator position.
7. A map keeps associations between key and value objects.