The ant side

  1. What is the relationship between a binary search tree and a balanced binary tree, and what is the difference between a strongly balanced binary tree (AVL tree) and a weakly balanced binary tree (red-black tree)?
  2. Why MySQL uses B+ trees?
  3. How does HashMap resolve Hash conflicts?
  4. Differences between epoll and poll, and application scenarios
  5. What is the blocking queue used by FixedThreadPool?
  6. Difference between sychronized and ReentrantLock
  7. Sychronized spin lock, bias lock, lightweight lock, heavyweight lock, respectively introduced and related
  8. What are the problems with HTTP, encryption algorithms, possible problems with different encryption methods, and how does HTTPS ensure secure transmission?

Answer: (in order not to accumulate the length of the article, ensure the readability of the article, the article only listed part of the answer, need a friend, > help forward it, pay attention to add assistant Vx: Yunduoa2019 or scan the two-dimensional code below, follow the assistant guidance to obtain

1, binary search tree: also known as binary search tree, or binary sorting tree. The definition is also simple, either an empty tree, or a binary tree with the following properties:

(1) If the left subtree of any node is not empty, the values of all nodes in the left subtree are less than the values of its root node;

(2) If the right subtree of any node is not empty, the value of all nodes in the right subtree is greater than the value of its root node;

(3) The left and right subtrees of any node are binary search trees respectively;

(4) There are no nodes with equal key values.

Balanced binary tree: two important features are added to the binary search tree

(1) The absolute value of the height difference between the left and right subtrees cannot exceed 1;

(2) The left and right subtrees are also a balanced binary tree.

Red-black tree: Red-black tree is formed by adding a color attribute to each node in a common binary tree, which should meet the following five properties:

(1) The node is red or black;

(2) The root node is black;

(3) Each leaf node (NIL or empty node) is black;

(4) The two children of each red node are black (that is, there are no two consecutive red nodes);

(5) All paths from any node to each of its leaf nodes contain the same number of black nodes.

Difference: AVL tree needs to be balanced, but it takes too long to rotate, while red black tree is not as balanced as AVL tree, so the efficiency of insertion and deletion is higher than AVL tree, and THE efficiency of AVL tree is obviously higher than red black tree.

2. B tree:

(1) The keyword set is distributed in the whole tree;

(2) Any keyword appears and only appears in one node;

(3) The search may end at non-leaf nodes;

(4) Its search performance is equivalent to a binary search in the whole set of keywords;

B + tree:

(1) There are n keywords in the non-leaf nodes of n subtrees (N-1 in B-tree). These keywords do not store data, but are only used for indexes, and all data are stored in leaf nodes (b-tree stores data for each keyword);

(2) All leaf nodes contain information of all keywords and Pointers to records containing these keywords, and leaf nodes themselves are linked in large order according to the size of keywords;

(3) All non-leaf nodes can be regarded as index parts, which only contain the maximum (or minimum) keyword in the sub-tree;

(4) There are usually two head Pointers on the B + tree, one pointing to the root node and the other to the leaf node with the smallest keyword;

(5) The same number will appear repeatedly in different nodes, and the largest element of the root node is the largest element of the B + tree.

Query advantages of B+ tree over B tree:

(1) The middle node of the B+ tree does not hold data, so the disk page can hold more node elements and is “fatter”;

(2) B+ tree search must find the leaf node, B tree can not care about the element position as long as it matches, so B+ tree search is more stable (not slow);

(3) For range search, B+ trees only need to traverse the linked list of leaf nodes, while B trees need to traverse the middle order repeatedly.

3. Resolve Hash conflicts by introducing one-way linked lists. When a Hash conflict occurs, the new and old keys are compared. If they are equal, the new key overwrites the old one. If they are not equal, the new value is stored in the new Node, pointing to the old Node, forming a chain structure, or linked list.

When Hash conflicts occur frequently, the list length will be too long, resulting in low retrieval efficiency. Therefore, red-black tree is introduced after JDK1.8. When the list length is greater than 8, the list will be converted to red-black book to improve query performance.

Ant 2 face

  1. What are the broad categories of design patterns and are you familiar with them?
  2. The volatile keyword, how does it guarantee visibility, order?
  3. Java’s memory structure, what parts of the heap are divided into, and how old is the default age?
  4. How does ConcurrentHashMap keep threads safe? What’s the change in jdk1.8?
  5. Why is the ConcurrentHashMap underlying red-black tree?
  6. How to do MySQL optimization?
  7. Talk about OOM and how to deal with this situation. Have you used log analysis tool?

A. the b. the C. the D. the

2. Volatile ensures thread visibility and provides some order, but does not guarantee atomicity. Volatile is implemented using “memory barriers” underneath the JVM.

A look at the assembly code generated with and without the volatile keyword showed that the volatile keyword added a lock prefix.

The LOCK prefix directive actually acts as a memory barrier (also known as a memory fence) that provides three functions:

I. It ensures that instruction reordering does not place subsequent instructions in front of the memory barrier, nor does it place previous instructions behind the memory barrier; That is, by the time the memory barrier instruction is executed, all operations in front of it have been completed;

II. It forces changes to the cache to be written to main storage immediately.

III. If it is a write operation, it invalidates the corresponding cache line in other cpus.

3, Java memory structure: program counter, virtual machine stack, local method stack, heap, method area.

The Java VIRTUAL machine (JVM) divides the heap memory into several blocks based on the lifetime of objects. The blocks are generally divided into new generation, old generation, and permanent generation.

By default, when an object reaches the age of 15, when it has escaped 15 GC, it will be moved to the old age.

The ants on three sides

  1. Project introduction
  2. How do you ensure data consistency between Redis cache and database?
  3. Redis cache avalanche? The breakdown? Pass through me?
  4. What message-oriented middleware are you familiar with and have you done performance comparisons?

conclusion

A few days ago, ant gold is served to appear on the market successfully, once in Ali bury oneself in 996 programmer just finally “lucky report”.

How many of these interview questions can you answer? Is it really so difficult to enter Ali?

I have sorted out the complete answers here, and there are many big factory interview questions, technical classification interview questions for you to brush the question with sprint. Friends in need, > help forward it, add assistant Vx: Yunduoa2019 or scan the two-dimensional code below, follow the guidance of the assistant to obtain