-1

I was given the following assignment, which I don't fully understand:

Write a program to implement a “Decimal Search Tree”, a popular tool used for searching in Libraries, police stations, Traffic control, …..

A Decimal search tree is a tree where each node has 10 children, one for each digit. The tree is built from the file of random 3-digit numbers generated from the first program. Obviously, the depth of the tree would be 4 levels. Then provide the following capabilities for the user:

List all numbers in the tree

Search for a certain number in the tree

Search for all numbers beginning with certain digits( e.g. “45*”)

Add a certain new number

Delete a certain number

Can anybody explain to me what this means? I know what a binary search tree is, but can't understand what is meant here.

Community
  • 1
  • 1

1 Answers1

2

This looks like a special version of the trie data structure. A trie is a type of tree for storing strings (or, in this case, numbers). It works by breaking apart the numbers one digit at a time.

Each node in a trie has a total of 10 child pointers, one for each digit. To look up a number in a trie, you read the first digit, then follow the pointer labeled by that digit. Then, you look up the second digit, then follow the pointer labeled by that digit. Repeating this process, you will eventually arrive at a node in the trie corresponding to that number. Each node in the trie stores a boolean value indicating whether or not that node marks the end of a word. Consequently, you can check whether the number you searched for exists in the trie by checking whether the node you've arrived at has this bit set.

For more information, I recommend checking out the Wikipedia article. It should have a lot of useful information!

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065