An n-ary tree is a tree in which each node has any number of son. One can use an n-ary tree to represent a dictionary and thus speed up the search. The root has as many son as possible first letters, then each son has as many son as possible second son letter, and so on. To represent such a tree, one solution is to attach two links to each node: a link to its first son and a link to its brother.
- Make sure you have the arbre resource. If necessary, see the Resources import webpage.
- The Dictionnaire class provides a constructor with no parameter. How many fields are needed to represent an instance of this class?
- The void ajouter(String) function adds a word in the dictionary. Add the word BU in the dictionary and check the evolution of memory diagram. What happened ?
- What happens if you add a new word starting with a different letter, such as AIR?
- What happens if you add an existing word again, as BU or AIR?
- To be sure you understand what is happening, add a third word beginning with another letter. Choose a short word to avoid cluttering the diagram. What is going on ?
- The function boolean contient(String mot) verify the ownership of a word to the dictionary. How many Node instances will be explored during the search of the word AIR?
- What happens now if we add a word that begins with a letter already registered, BOL for example?
- Carefully follow what happens if we add a new word as BON.
- After all these additions, does the membership test of the word AIR require as much or more exploration of nodes?