Big Java Chapter 15
Map
A map keeps associations between key and value objects Mathematically speaking, a map is a function from one set, the key set, to another collection, the value collection
Nodes
A node is an object that stores an element and references to the neighboring nodes. Each node in a linked list is connected to the neighboring nodes.
Priority Queue
A priority queue collects elements, each of which has a priority.
Set Iterator
A set iterator does not visit the elements in the order in which they were inserted An element cannot be added to a set at an iterator position A set element can be removed at an iterator position
adding an element to a set
Adding an element has no effect if the element is already in the set
Linked List Efficiency
Adding and removing elements in the middle of a linked list is efficient. Visiting the elements of a linked list in sequential order is efficient. Random access is not efficient.
Stack
Allows insertion and removal of elements only at one end Traditionally called the top of the stack New items are added to the top of the stack Items are removed at the top of the stack Called last in, first out or LIFO order
Which is more efficient, a set or a list?
Because a set does not track the order of the elements, it can arrange the elements so that the operations of finding, adding, and removing elements become more efficient.
Priority Queue Removal
Elements are retrieved according to their priority. Priority 1 denotes the most urgent priority Each removal extracts the minimum element
Key
Every key in a map has a unique value (no duplicates) A value may be associated with several keys
List Iterator
Gives access to elements inside a linked list Encapsulates a position anywhere inside the linked list
Hashing
Hashing can be used to find elements in a data structure quickly without making a linear search
how to declare a linkedlist
List<String> aList = new LinkedList<String>()
how to declare a list iterator
ListIterator<String> aIterator = employeeNames.listIterator();
When you insert or remove a node....
Only the neighboring node references need to be updated
How to declare a queue
Queue<Car> q = new LinkedList<Car>();
how to declare a priority queue
Queue<WorkOrder> q = new PriorityQueue<WorkOrder>();
Queue
Queues store items in a first in, first out or FIFO fashion Items are removed in the same order in which they have been added
how to declare a set
Set<Integer> hints = new HashSet<Integer>(ints);
how to declare a stack
Stack<Homework> aStack = new Stack<Homework>();
Set
The Set interface has the same methods as the Collection Interface. A Set does not allow duplicates Two implementations of Set Very fast at add, remove and contains operations A Set implementation arranges elements so that it can locate them quickly.
iterator.next();
The next method moves the iterator:next throws a NoSuchElementException if you are already past the end of the list The next method returns the element that the iterator is passing:
List Interface
What does the ArrayList class implement?
Collection
When you need to organize multiple objects in your program, you can place them into a...
When to use a linkedlist
You are concerned about the efficiency of inserting or removing elements. O(1) You rarely need element access in random order. O(n)
List
a collection that remembers the order of its elements
Set
a collection without an order
Linked List
a data structure used for collecting a sequence of objects that allows efficient addition and removal of elements in the middle of the sequence.
Priority Queue
an unordered collection that has an efficient operation for removing the element with the highest priority.
HashSet Order
arbitrary order
hash function
computes an integer value (called the hash code) from an object
iterator.hasNext();
hasNext returns true if there is a next element:
Map
manages associations between keys and values
iterator.hasPrevious/previous
moves it backwards
Removal Stack
pop
Addition Stack
push
Stack
remembers the order of its elements, but it does not allow you to insert elements in every position. You can add and remove elements only at the top
TreeSet Order
sorted order by Comparable/Comparator
Queue
you add items to one end (the tail) and remove them from the other end (the head