Trees in java.util A set is an object that stores unique elements In Java, two implementations are available: The class HashSet implements the set with a hash table and a hash function The class TreeSet, which keeps elements of a set in a sorted order
Trees in java.util (continued) Figure 3-32 Methods of the class TreeSet
Trees in java.util (continued) Figure 3-32 Methods of the class TreeSet (continued)
Trees in java.util (continued) Figure 3-32 Methods of the class TreeSet (continued)
Trees in java.util (continued) Figure 3-32 Methods of the class TreeSet (continued)
Trees in java.util (continued) Figure 3-32 Methods of the class TreeSet (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
Trees in java.util (continued) Figure 7-33 An example of application of the TreeSet methods (continued)
TreeMap Maps are tables that can be indexed with any type of data Maps use keys that are used as indexes and elements (values) to be accessed through the keys Keys in maps are unique in that one key is associated with one value only Tree maps implement maps store pairs (key, value) called entries that can be operated on by methods specified in the interface Map.Entry
TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap
TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)
TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)
TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)
TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)
TreeMap (continued) Figure 7-35 An example of application of the TreeMap methods. The class PersonByName is the same as in Figure 7-33.
TreeMap (continued) Figure 7-35 An example of application of the TreeMap methods (continued)
Tries A tree that uses parts of the key to navigate the search is called a trie Each key is a sequence of characters; a trie is organized around these characters rather than entire keys
Tries (continued) Figure 7-36 A trie of some words composed of the five letters A, E, I, R, and P
Tries (continued) Figure 7-37 The trie in Figure 7.36 with all unused reference fields removed
Tries (continued) Figure 7-38 The trie from Figure 7.37 implemented as a binary tree
Tries (continued) Figure 7-39 A part of a trie (a) before and (b) after compression using the compressTrie() algorithm and (c) after compressing it in an optimal way
Tries (continued) Figure 7-39 A part of a trie (a) before and (b) after compression using the compressTrie() algorithm and (c) after compressing it in an optimal way (continued)
Tries (continued) Figure 7-40 A fragment of the C-trie representation of the trie from Figure 7-36
Case Study: Spell Checker Figure 7-41 An implementation of a trie that uses pseudoflexible arrays. The trie has the same words as the trie in Figure 7-36.
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Case Study: Spell Checker (continued) Figure 7-42 Implementation of a spell checker using tries (continued)
Summary B+-trees are commonly used in the implementation of indexes in today’s relational databases Seek time depends on the mechanical movement of the disk head to position the head at the correct track of the disk Latency is the time required to position the head above the correct block and is equal to the time needed to make one-half of a revolution
Summary (continued) In a B*-tree, all nodes except the root are required to be at least two-thirds full, not just half full as in a B-tree A simple prefix B+-tree is a B+-tree in which the chosen separators are the shortest prefixes that allow us to distinguish two neighboring index keys A set is an object that stores unique elements. Maps are tables that can be indexed with any type of data
Summary (continued) The bit-tree is based on the concept of a distinction bit (D-bit) A variant of B-trees, 2–4 trees, is useful in processing information in memory A tree that uses parts of the key to navigate the search is called a trie