面试有关问题:给你一个文本文件,里面存储了一亿个QQ号,请用程序将其由小到大排序,汗呀!
面试问题:给你一个文本文件,里面存储了一亿个QQ号,请用程序将其由小到大排序,汗呀!..
面试问题:给你一个文本文件,里面存储了一亿个QQ号,请用程序将其由小到大排序,汗呀!..
求高手讲解思路!
还有其它问题:
比如Memcache的运行机制,它的工作原理它有什么优缺点!
现有一个库存100件的产品要进行秒杀,在秒杀过程中的秒杀人数远远超过库存,请问你将如何处理,应该注意什么问题!
请谈谈你对Mysql的优化的见解,或者说如果让你设计一个数据库,你将怎样设计并优化!
有高手吗,今天面试都自己认为都答得不太理想,求指教,还有下面的面试!
小弟的刚刚被裁员,本来就冬天,真的好冷啊!
------解决方案--------------------
排序的问题想不出来什么好办法,有没有更具体的限制条件,比如运行时间和内存?
如果都不限制直接sort函数就行,里面是用的快速排序法(quicksort),理论上的效率应该是最高的,况且人家是native code,怎么也比php代码里模拟一个排序算法快。
memcache的运行机制是使用职守进程开辟一块内存空间用来保存key/value数据,所有的请求和应用都共用这些数据。优点是存取速度快,适合用来缓存频繁读写的数据。缺点是占用内存,同时只能通过key检索,无法进行关系查询(SQL等)。
要保证原子操作,使用一定的锁机制防止多个请求同时操作一个数据造成效果与预期不符。
mysql数据库优化主要是索引和分表,为了性能可以为所有需要排序和检索的字段建立索引,并通过水平或垂直分表方式提高效率。
------解决方案--------------------
目的肯定不是让你投机,导入数据库,建索引导出,不过可以提一下
遍历一遍,将号码按大小,写入合适的文件。。。比如约定10万一个号码段
比如10,000,写在第0个文件,100,000,001,属于第1K个文件里面
排序每一个文件数据,拼接文件
排序的时候,如果文件较大,这里根据文件大小,大概能估计号码数量级的。。如果号码量少,可选择快排,否则,
创建一个10万的数组,再次遍历,arr[qqnum-i*100000]+1;
遍历数组,依数组值,增量写入号码即可
复杂度是O(n),O(nlogn)之间
------解决方案--------------------
这面试题有点眼熟啊,算法板块貌似讨论过,所以我回答用bitmap,空间换时间。
而且实际要做可能需要分段处理,比如5-7位的qq直接bit hash,7-10位的bit hash值 + 1000000
- PHP code
<?php set_time_limit(0); //5-7位qq $s = '0'; $s{9999999} = 1; $s{22334} = 1; $s{375345} = 1; $i = 10000; while(isset($s{$i})) { if($s{$i} == 1) echo "QQ:".$i."<br/>"; $i++; } ?> <br><font color="#e78608">------解决方案--------------------</font><br>
------解决方案--------------------

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Hash operation //Assign values to fields in the hash table. Returns 1 on success and 0 on failure. If the hash table does not exist, the table will be created first and then the value will be assigned. If the field already exists, the old value will be overwritten. $ret=$redis->hSet('user','realname','jetwu');//Get the value of the specified field in the hash table. If the hash table does not exist, return false. $ret=$redis->hGet('user','rea

In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

Laravel is currently one of the most popular PHP web frameworks, providing developers with many powerful features and components, among which LaravelHash is one of them. LaravelHash is a PHP library for password hashing that can be used to keep passwords secure and make your application's user data more secure. In this article, we will learn how LaravelHash works and how to use it to hash and verify passwords. Prerequisite knowledge in learning Lara

The redis test code in this article is based on the following environment: Operating system: MacOS 64-bit version: Redis5.0.764bit Operating mode: standalonemode Redis bit operation reids bit operation is also called bit array operation and bitmap. It provides four commands: SETBIT, GETBIT, BITCOUNT, and BITTOP. For manipulating binary bit arrays. Let’s first look at a wave of basic operation examples SETBIT syntax: SETBITkeyoffsetvalue is: command key offset 0/1 The setbit command is used to write the binary bit setting value of the specified offset in the bit array. The offset starts counting from 0 and is only allowed Write 1 or 0,

CentOS is a Linux distribution that originated from RHEL and is compiled in accordance with the regulations of open source code. Moreover, it maintains functional compatibility with RHEL and is a free, open source operating system that users can use and modify without paying copyright fees. So does CentOS distinguish between 32-bit and 64-bit in Linux? Please see below for details. CentOS distinguishes between 32-bit and 64-bit! The main differences: CentOS32bit system is mainly released for PC; CentOS64bit system is mainly aimed at large-scale scientific computing; 64bitLinux system is mainly installed on 64bit hardware system; 32bit

With the rapid development of the Internet, more and more applications need to face a large number of concurrent requests. How to improve the concurrent processing capabilities of applications has become a problem that developers need to solve. Among them, using Memcache caching technology for concurrency optimization has become a relatively popular solution. Memcache is an efficient caching technology suitable for large-scale web applications, databases and distributed systems. Its characteristic is to store data in memory to achieve high-speed read and write operations. During the data access process of web applications,

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

PHP is a very popular programming language commonly used for server-side web application development. As the user scale of web applications continues to grow and the amount of data continues to increase, efficient data caching and sorting operations become more and more important. Memcache is a very useful tool in this situation. This article will introduce how to use Memcache to achieve efficient data caching and sorting operations in PHP development, and provide specific code examples. What is Memcache? Memcache is
