当前位置:网站首页>[interview ordinary people vs Expert Series] understanding of B tree and B + tree
[interview ordinary people vs Expert Series] understanding of B tree and B + tree
2022-04-21 17:12:00 【Learn architecture from mic】
Data structure and algorithm problems , Troubled countless little friends .
Many small partners have a misunderstanding about data structure and algorithm , I don't think I use... In my work , Why do interviews ask , Asked can solve practical problems ?
Turing prize winner : Niklaus Wirth Said : Program = data structure + Algorithm , In other words, we are dealing with data structures all the time .
Just as Java Development , Due to the high maturity of the technical system , Makes most people think : The program should be equal to frame + SQL ah ?
Today, let's analyze a topic of data structure :”B Trees and B+ Trees “.
On this question , Let's take a look at the answers of ordinary people and experts !
Ordinary people
Um. . I think … Um. … Mysql It seems to use B+ Tree to index ! then …
master
In order to answer this question more clearly , I intend to answer from three aspects :
-
Learn about binary trees 、AVL Trees 、B The concept of tree
-
B Trees and B+ Tree application scenarios
-
B A tree is a multi-path balanced search tree .
Binary tree , Each node supports a tree structure of two branches , Compared with one-way linked list , One more branch .
Binary search tree , A rule is added to the binary tree , The value of all nodes in the left subtree is less than its root node , All child nodes of the right subtree are larger than its root node .

Skew tree problem will occur in binary search tree , Resulting in increased time complexity , Therefore, a balanced binary tree is introduced , It has all the characteristics of binary search tree , At the same time, a rule is added :” The absolute value of the height difference between its left and right subtrees shall not exceed 1“. Balanced binary trees will use left-handed 、 Right handed way to achieve balance .

and B A tree is a multi-path balanced search tree , It satisfies the rules of balanced binary tree , But it can have multiple subtrees , The number of subtrees depends on the number of keywords , For example, the root node in this figure has two keywords 3 and 5, Then the number of sub paths it can have = Key words +1.
Therefore, from this feature , When the same amount of data is stored , The height of balanced binary tree should be greater than B Trees .

B+ Trees , In fact B Enhancement based on tree , There are two big differences :
-
B The data is stored on the tree of each node , and B+ The data in the tree is stored in leaf nodes , And connect the data in the leaf node through a linked list .
-
B+ The number of sub paths of the tree is equal to the number of key words
This is B The storage structure of the tree , from B It can be seen from the tree that each node will store data .

-
This is B+ Trees ,B+ All the data of the tree is stored in the leaf node , And the data of leaf nodes is associated with a two-way linked list .

-
B Trees and B+ Trees , It is generally used in file system and database system , Used to reduce disk IO Performance loss .
With Mysql Medium InnoDB For example , When we go through select Statement to query a piece of data ,InnoDB Need to read data from disk , This process involves disks IO And random disk IO.

We know that disks IO The performance of is particularly low , Especially random disks IO.
because , disk IO It works by , First, the system will transfer the logical address of the data to the disk , The disk control circuit translates the logical address into the physical address according to the addressing logic , That is to determine which track the data to be read is on , Which sector? .
In order to read the data of this sector , You need to put the head on top of this sector , To achieve this , The disk will keep spinning , Rotate the target sector under the head , Make the head find the corresponding track , This involves seek events and rotation time .
Obviously , disk IO The performance overhead of this process is very large , Especially when there is a large amount of data to query .
So in InnoDB in , Simply build an index on the data stored on the disk block , Then put the index data and the disk address corresponding to the index column , With B+ Store... In the form of a tree .
As shown in the figure , When we need to query the target data , According to the index from B+ Find the target data in the tree , because B+ There are many branches , So only a few disks are needed IO You can find it .

-
Why B Trees or B+ The tree is used as the index structure ? as a result of AVL Trees are taller than trees B The height of the tree should be high , And height means disk IO The number of . So in order to reduce the number of disks IO The number of times , File system or database will adopt B Trees or B+ Trees .
So that's me right B Trees and B+ Understanding of trees !
summary
Data structure is very common in practical development , For example, array 、 Linked list 、 Double linked list 、 Red and black trees 、 Skip list 、B Trees 、B+ Trees 、 Line up, etc .
in my opinion , Data structure is one of the most important basic skills in programming .
Learned the sequence list and the chain list , We can know that sequential tables should be used in scenarios with more query operations , A linked list should be used in scenarios with many modification operations .
After learning the queue , I knew for FIFO In the scene , Queues should be used .
After learning the structure of trees , You will find the original scene of finding classes , It can also further improve query performance .
Basic skills determine the height you can reach in the technical post .
well , Ordinary people in this issue VS That's the end of the expert interview series , Remember to like your friends .
If you encounter some problems in scene class and scheme design class recently , Welcome to write to me , I'll give you an answer in the following content !
I am a Mic, A job 14 Year of Java The programmer , Let's see you in the next article .

版权声明
本文为[Learn architecture from mic]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211709002864.html
边栏推荐
- R语言使用dplyr包中的select函数基于数据列的索引数值删除dataframe中数据列
- The R language uses the plot function to visualize the data scatter diagram, and uses the BG parameter in the par function to customize the background color in the wireframe of the visual image
- 【微服务】微服务安全 - 如何保护您的微服务基础架构?
- 1044. Longest repeating substring
- 干货 | 实战演练基于加密接口测试测试用例设计
- . net treasure API: ihostedservice, background task execution
- Binary tree related creation or traversal
- R language uses qbern function to generate Bernoulli distribution (0-1 distribution) quantile function data, and uses plot function to visualize Bernoulli distribution
- R语言数据导出(数据保存、导出、持久化到本地指定目录文件)、使用xlsx包的write.xlsx函数将dataframe导出为excel文件xls格式、而非xlsx格式
- FastReport Business Graphics . NET
猜你喜欢
![[newcode] cattle team competition](/img/1f/e4bc0a246c4e6631a9201b067d07cd.png)
[newcode] cattle team competition

在阿里云上搭建个人博客(WordPress)

SSD_ RESNET aircraft and oil drum data set actual combat

pytorch index_ add_ Usage introduction

【newcode】牛牛组队竞赛

The first five chapters are thought maps

Priority of keyword execution of MySQL query statement

Quick MTF, lens image quality test application

把握住这5点!在职考研也能上岸!

Extensive reading of alexnet papers: landmark papers in the field of deep learning CV neurips2012
随机推荐
R language data export (data saving, export and persistence to local specified directory file), write using xlsx package Xlsx function exports dataframe to excel file XLS format instead of xlsx format
R语言使用grepl函数检查子字符串是否存在于指定的字符串中、字符串匹配,负责搜索给定字符串对象中是否包含特定表达式
Interpretation of a paper that points out the small errors in the classic RMS proof process
Win10 bridging network card enables QEMU virtual machine to access the network normally
【面试普通人VS高手系列】b树和b+树的理解
Vivado验证Vitis HLS生成的IP核
IO view command
1044. 最长重复子串
【栈】155. 最小栈
mysql设置某字段不能重复
Wx open launch web app style problem
(自用)远程调用时参数2个RequestParam注解
当你遇到技术难题之后的状态
[free] download 19860 yuan programming course materials on a platform, only once
LS - Al meaning of each field
建议提供大纲 - 一键展开功能
A simple and easy-to-use file upload scheme
关于内推想说的
BUUCTF WEB [GXYCTF2019]BabyUpload
30. 构造方法的重载



