Programming beauty-3.2-phone number corresponding to English Words

Source: Internet
Author: User

1. Brief Introduction

Phone number disks can be used to enter letters. For example, if you use 2, you can enter A, B, and C. If you use 3, you can enter D, E, F, and so on.
For the number 5869872, You can output all the letters that it represents in sequence. Such as jtmwtpa and jtmwtb ······
1) design the program and try to find a meaningful word from these combinations to express a phone number. For example, the word "computer" is used to describe the number 26678837.
2) can a number be represented by a word? What is the fastest way?

2. Ideas

Because both tasks need to determine whether a letter combination is a word, a word list must be saved in advance.
Method 1: perform in-depth priority search on the number directly. The space is basically useless, that is, the time is too large. Assume that the word list contains n characters, numbers are k characters, and a key is three characters (in fact, not all numbers correspond to the same number). This is a 3 ^ K character sequence. Each time a sequence is found, it also needs to be searched in the word list, O (N). This does not calculate the specific time for matching each character sequence with words. In short, the time complexity is very high.
Method 2: Change the space time. There are two specific ideas.
One is to map each number to a number, find the string corresponding to each number, and then find the word according to the word list, in fact, the task in method 1 is completed offline. In this case, there is a problem that generally there are 11 mobile phones (each assuming can be 0-9). This is 10 ^ 11, with GB numbers, the complexity of each number can be imagined by using method 1.
The other method is to use words. In fact, the number of English words is limited, and the number of commonly used words is several thousand. the GRE test is tens of thousands. Suppose there are 0.1 million words, we can find the number corresponding to each word, which is also 0.1 million. For these 0.1 million words, you can use Lucene to create an index or a dictionary tree. For the index, each number is mounted with a subscript of the corresponding word in the word list. For the dictionary tree, each number node hangs the subscript of the corresponding word in the word list.
In this way, a number is used to determine whether the number exists in the index and dictionary tree. The complexity is basically a constant level. If the number is found, the corresponding word can be found in the word list, find a word. If no number is found, it indicates that no corresponding word exists.

3. Reference

The beauty of programming, section 3.2, telephone numbers correspond to English Words

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.