Interview question: I will give you a text file containing 0.1 billion QQ numbers. please use a program to sort it in ascending order !.. Interview question: I will give you a text file containing 0.1 billion QQ numbers. please use a program to sort it in ascending order !.. Could you please explain your ideas! There are other problems: for example, the running mechanism of Memcache. what are its advantages and disadvantages! There is a 100-piece product in stock that requires flash sales. the number of flash sales in the flash sales process far exceeds the inventory. how do you deal with the interview question: give you a text file, it stores 0.1 billion QQ numbers. please use a program to sort them in ascending order !..
Interview question: I will give you a text file containing 0.1 billion QQ numbers. please use a program to sort it in ascending order !..
Could you please explain your ideas!
Other problems:
For example, the operating mechanism of Memcache. how does it work? what are its advantages and disadvantages!
Currently, a product with 100 pieces in stock requires flash sales. the number of flash sales in the flash sales process far exceeds the inventory. how can you handle this problem? what should I pay attention!
Let's talk about your insights on Mysql optimization, or how you design and optimize a database!
Do you have any experts? I think they are not doing well in the interview today. please give me some advice and I will discuss the following interview!
The younger brother was laid off just now. it was just Winter. it was really cool!
------ Solution --------------------
There is no good way to solve the sorting problem. Are there more specific restrictions, such as running time and memory?
If there is no limit on the direct sort function, the quick sorting method is used in it. Theoretically, the efficiency should be the highest. besides, native code is used, it is faster than simulating a sorting algorithm in php code.
Memcache uses the default process to open up a memory space to store key/value data. all requests and applications share the data. The advantage is that the access speed is fast and suitable for caching frequently read/write data. The disadvantage is that it occupies memory and can only be searched by key, and relational queries (SQL, etc.) cannot be performed ).
To ensure atomic operations, use a certain lock mechanism to prevent multiple requests from simultaneously operating on one data, resulting in inconsistent results with expectations.
Mysql database optimization mainly involves indexing and table sharding. in order to improve the performance, you can create indexes for all the fields to be sorted and retrieved, and improve the efficiency through horizontal or vertical table sharding.
------ Solution --------------------
The goal is definitely not to let you speculate, import the database, create indexes, and export the data, but you can mention it.
Traverse the file and write the number to the appropriate file by size... For example, 0.1 million is a number segment.
For example, 10,000 is written in 0th files and 100,000,001 is in the 1K file.
Sort the data of each file and splice the file
If the file size is large during sorting, we can estimate the number order of magnitude based on the file size .. If the number is small, you can select quick sort. otherwise,
Create an array of 0.1 million and traverse it again. arr [qqnum-I * 100000] + 1;
Traverse the array and incrementally write the number according to the array value.
The complexity is between O (n) and O (nlogn ).
------ Solution --------------------
This question is a bit familiar. the algorithm section seems to have discussed it, so I use bitmap to change the space for time.
In addition, the actual process may need to be segmented, such as 5-7 digits of qq direct bit hash, 7-10 digits of bit hash value + 1000000
PHP code
"; $ I ++ ;}?>
------ Solution --------------------
Discussion
This question is a bit familiar. the algorithm section seems to have discussed it, so I use bitmap to change the space for time.
In addition, the actual process may need to be segmented, such as 5-7 digits of qq direct bit hash, 7-10 digits of bit hash value + 1000000
PHP code
Set_time_limit (0 );
// 5-7 qq
$ S = '0 ';
$ S {9999999} = 1;
$ S {22334} = 1;
......
------ Solution --------------------
Discussion
It should be the same as the sort phone number in the programming Pearl River. 0.1 billion QQ numbers require 0.1 billion digits, which is about 11 MB.