my home assignment is to decipher a sentence based on a known and finite dictionary.
Example:
Dict – show,blow,while
then the code 12345 8291 came as input.
if we will check the possibilities the the only option is “while show”.
can some one give me a direction or a known algorithm that handle this problem.
pseudo code or java will be great.
thanks
You need to implement some kind of backtracking or other search technique. I’d suggest the following approach:
EDIT: In step 2, the difficult part is determining what letters (if any) can be assigned to the next cipher digit. Suppose we are keeping track of the decoded current word and we want to process the next cipher digit in the word. We have a global map of cipher digit assignments already made. The logic might be something like this (in Java-ish pseudocode):
If this returns an empty set, the current assignment (before the method is called) is incompatible with the dictionary and the search must backtrack. Otherwise, the search should pick one assignment at a time from the set and continue, backtracking as necessary.
Rather than trying each unassigned character and asking the dictionary whether it is compatible, it might be more efficient (but logically equivalent) to query the dictionary directly for the list of compatible next characters and intersect that with the unassigned character set.