# Morse Code - Binary Tree

How is the Morse Code representation of a letter determined?

"E" = "." "T" = "-"

Why is it not alphabetic? As in let "A" = ".", "B" = "-", "C" =".-", etc.

I'm trying to develop an algorithm for a traversing Binary Tree filled with these letter.

My main aim is to search for a letter, like "A", but I don't know what conditions to use that determines when to branch to the right or left node.

-
Note that Morse code is ambiguous, if used with no spaces between the letters. Radio hobbyists are able to produce and detect short pauses between individual letters to recognize them. A naive algorithm, if given a spaceless sequence of dots and dashes, will be quickly confused. – bytebuster Nov 19 '12 at 0:56
Any naïve algorithm will, when faced with a spaceless sequence, output only "E" and "T" because those are the first matches found. – Michael Kjörling Nov 19 '12 at 9:26

A tree is suitable for decoding Morse code, that is converting from dots and dashes to letters. As long as you know where the breaks are between letters, this is entirely feasible.

To go the other way, from letters to dots and dashes, there's no need to use a tree. Finding a letter in such a tree would be annoying. Just make a simple lookup table:

``````a => ".-"
b => "-..."
c => "-.-."
``````
-

The representation of the letters is determined (roughly) by "the frequency of use of letters in the English language . . ., and the letters most commonly used were assigned the shorter sequences of dots and dashes." You could build a tree with traversing to the left means adding a '.' and traversing to the right means adding a '-' to the previous code. You may want to also look at Huffman coding as this is very similar.

-
I have the tree built, but I want to search for the letter "E" and get the String "." – Adegoke A Nov 18 '12 at 23:49
Sounds like a simple mapping function .. – bummi Nov 19 '12 at 0:27
If you have found the letter, then you look at the path you took from the root, each left traversal means a '.' and each right means a '-'. – Chewy Gumball Nov 19 '12 at 1:20
@AdegokeA: You're asking the same question as if you'd put "I've got an English to French dictionary, how can I use it to translate this French into English?" The tree you've got is a way of finding the letter if you have the morse code. You'll need a different structure to go the other way – Gareth Nov 19 '12 at 8:31