2019年_BATJ大厂面试题总结-小米篇

1.hashmap说一下,线程安全吗,树化的临界值为什么是8?

网上主流的答案:
红黑树的平均查找长度是log(n),如果长度为8,平均查找长度为log(8)=3,链表的平均查找长度为n/2,当长度为8时,平均查找长度为8/2=4,红黑树的查找效率更高,这才有转换成树的必要;
链表长度如果是小于等于6,6/2=3,而log(6)=2.6,虽然速度也很快的,但是转化为树结构和生成树的时间并不会太短
这个答案是从查找效率的角度解释的,这种解释虽然有一定的合理性,但并不是设计者真正的想法

真正的原因——JDK设计者的解释
摘自HashMap源码的Implementation notes.

 * Because TreeNodes are about twice the size of regular nodes, we
 * use them only when bins contain enough nodes to warrant use
 * (see TREEIFY_THRESHOLD). And when they become too small (due to
 * removal or resizing) they are converted back to plain bins.  In
 * usages with well-distributed user hashCodes, tree bins are
 * rarely used.  Ideally, under random hashCodes, the frequency of
 * nodes in bins follows a Poisson distribution
 * (http://en.wikipedia.org/wiki/Poisson_distribution) with a
 * parameter of about 0.5 on average for the default resizing
 * threshold of 0.75, although with a large variance because of
 * resizing granularity. Ignoring variance, the expected
 * occurrences of list size k are (exp(-0.5) * pow(0.5, k) /
 * factorial(k)). The first values are:
 *
 * 0:    0.60653066
 * 1:    0.30326533
 * 2:    0.07581633
 * 3:    0.01263606
 * 4:    0.00157952
 * 5:    0.00015795
 * 6:    0.00001316
 * 7:    0.00000094
 * 8:    0.00000006
 * more: less than 1 in ten million

上面的内容:当hashCode离散性很好的时候,树型bin用到的概率非常小,因为数据均匀分布在每个bin中,几乎不会有bin中链表长度会达到阈值(树华门槛)。但是在随机hashCode下,离散性可能会变差,然而JDK又不能阻止用户实现这种不好的hash算法,因此就可能导致不均匀的数据分布。不过理想情况下随机hashCode算法下所有bin中节点的分布频率会遵循泊松分布,我们可以看到,一个bin中链表长度达到8个元素的概率为0.00000006,几乎是不可能事件。所以,之所以选择8,不是拍拍屁股决定的,而是根据概率统计决定的。由此可见,发展30年的Java每一项改动和优化都是非常严谨和科学的。

2.hashtable 并发性能

答案:https://www.cnblogs.com/shunyang/p/4318652.html

3.hashtable 的底层数据结构

答案:https://blog.csdn.net/chen_changying/article/details/80117862

4.jvm垃圾回收算法

CSDN:https://blog.csdn.net/wangxiaotongfan/article/details/82389881
博客园:https://www.cnblogs.com/aspirant/p/8662690.html

5.jvm如何加载一个类到内存

CSDN:https://blog.csdn.net/m0_38075425/article/details/81627349
博客园:https://www.cnblogs.com/shan1393/p/8996954.html

6.Redis 的数据结构?Redis 快的原因?Redis 用于项目中你怎么解决的高并发抢购?Redis 的分布式锁?redis有哪些数据类型,持久化机制

答案:史上以来最详细的Redis高质量面试题

7.RPC框架从启动流程开始到整个调用过程

CSDN答案:https://blog.csdn.net/zjx86320/article/details/51019050
搜狐答案:https://www.sohu.com/a/233125706_505800

8.treeset 的数据结构

博客园:https://www.cnblogs.com/jdemarryme/p/9369060.html
简书: https://www.jianshu.com/p/c99be3b202bf
CSND: https://blog.csdn.net/wufeiova/article/details/92567566

9.分布式下全局唯一编号实现方式有哪些?

简书:https://www.jianshu.com/p/9d7ebe37215e
博客园:https://www.cnblogs.com/Tiancheng-Duan/p/10962704.html
CSDN:https://blog.csdn.net/u010398771/article/details/79765836

10.手撕链表合并,用归并

博客园:https://www.cnblogs.com/whtmomo/p/11515106.html
CSDN: https://blog.csdn.net/qq_42391248/article/details/86370703

11.索引的实现,叶子结点存的是哪些数据

看到MySQL会为主键生成一棵树,叶子节点保存了主键对应的行数据。

叶子节点相当于是存储(关键字)数据的数据层。

次级索引叶子节点保存了主键的值。

12.项目中的图片存在哪里的,用过图床吗

答案:https://blog.csdn.net/czh500/article/details/84033190
GitHub项目:https://github.com/souyunku/Picture-Bed

13.打印出一个二叉树每一层结点的平均值

参考:https://www.cnblogs.com/-Lei/archive/2013/02/25/2928629.html

发布了55 篇原创文章 · 获赞 92 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43107323/article/details/104722784