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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章