Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trees in java.util A set is an object that stores unique elements

Similar presentations


Presentation on theme: "Trees in java.util A set is an object that stores unique elements"— Presentation transcript:

1 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

2 Trees in java.util (continued)
Figure 3-32 Methods of the class TreeSet

3 Trees in java.util (continued)
Figure 3-32 Methods of the class TreeSet (continued)

4 Trees in java.util (continued)
Figure 3-32 Methods of the class TreeSet (continued)

5 Trees in java.util (continued)
Figure 3-32 Methods of the class TreeSet (continued)

6 Trees in java.util (continued)
Figure 3-32 Methods of the class TreeSet (continued)

7 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods

8 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

9 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

10 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

11 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

12 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

13 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

14 Trees in java.util (continued)
Figure 7-33 An example of application of the TreeSet methods (continued)

15 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

16 TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap

17 TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)

18 TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)

19 TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)

20 TreeMap (continued) Figure 7-34 (a) Methods in the interface Map.Entry; (b) methods of the class TreeMap (continued)

21 TreeMap (continued) Figure 7-35 An example of application of the TreeMap methods The class PersonByName is the same as in Figure 7-33.

22 TreeMap (continued) Figure 7-35 An example of application of the TreeMap methods (continued)

23 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

24 Tries (continued) Figure 7-36 A trie of some words composed of the five letters A, E, I, R, and P

25 Tries (continued) Figure 7-37 The trie in Figure 7.36 with all unused reference fields removed

26 Tries (continued) Figure 7-38 The trie from Figure 7.37 implemented as a binary tree

27 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

28 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)

29 Tries (continued) Figure 7-40 A fragment of the C-trie representation of the trie from Figure 7-36

30 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.

31 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries

32 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

33 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

34 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

35 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

36 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

37 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

38 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

39 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

40 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

41 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

42 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

43 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

44 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

45 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

46 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

47 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

48 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

49 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

50 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

51 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

52 Case Study: Spell Checker (continued)
Figure 7-42 Implementation of a spell checker using tries (continued)

53 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

54 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

55 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


Download ppt "Trees in java.util A set is an object that stores unique elements"

Similar presentations


Ads by Google