Sound To Morse Code Converter Java
I'm trying to convert Morse code into text. I have two text files to use with this problem. MorseCode.txt: I have a file that i read off that contains the letters and. Gta San Andreas Ultimate Mod 2011 Lancer there.
• Tell us some more • Upload in Progress • Upload failed. Please upload a file larger than 100x100 pixels • We are experiencing some problems, please try again.
• You can only upload files of type PNG, JPG, or JPEG. • You can only upload files of type 3GP, 3GPP, MP4, MOV, AVI, MPG, MPEG, or RM.
• You can only upload photos smaller than 5 MB. • You can only upload videos smaller than 600MB. • You can only upload a photo (png, jpg, jpeg) or a video (3gp, 3gpp, mp4, mov, avi, mpg, mpeg, rm). • You can only upload a photo or a video. • Video should be smaller than 600mb/5 minutes • Photo should be smaller than 5mb •.
One thing that catches my eye is how you have two arrays of chars/strings mapped to each other through related index locations. I did this myself back in the day, and it quickly became a nightmare to maintain. In your case, you should create a instead. I would expect your code to look like: HashMap charToCodeMap = new HashMap(); charToCodeMap.put('a', '.-'); // Initialize here. Now, instead of iterating through both lists for every character, you can just get the character you need to translate and call, for example, String codeForA = charToCodeMap.get('a'). This will (theoretically) reduce the time needed to run your code drastically, as map access is $O(1) $ (unless there are hash collisions), while iterating through a list is $O(n) $. However, as Klitos Kyriacou noted in the comments, the actual performance and theoretical performance are not necessarily the same.
Although the use of a Map makes the code clearer, I doubt it would make it faster. The time complexities that you quote are correct, but they don't tell the whole story. These are only useful when thinking about scalability.
For this small collection of letters and numbers, I would expect an array to be much faster than a HashMap, since the data is held in contiguous memory which is going to be in the processor's L1 cache; whereas a HashMap would have to box & unbox between char and Character and use indirection. Don't assume better performance unless you measure. – Aug 18 '16 at 16:52.