You are on page 1of 67

B-TREE

21521525 – Lý Văn Nhật Tiến


21522274 – Lê Nguyễn Hoàng Lâm
01 02 03
ỨNG DỤNG & QUIZ &
B TREE
B+TREE DEMO
B TREE 01
VẤN ĐỀ CỦA BINARY TREE ?

Khả năng mở rộng Mất cân bằng cây


Không hiệu quả với dữ liệu cực Gây trở ngại trong duyệt cây
lớn
TỔNG QUAN B TREE
B Tree là một cây tìm kiếm nhiều nhánh tự cân bằng.
Một Node B Tree có thể chứa nhiều khóa theo thứ tự.
Các node lá của B Tree phải cùng mức
CÁC TÍNH CHẤT
Khi sử dụng B tree, ta định trước một số nguyên gọi là bậc của cây

Mỗi node có tối đa node con Mỗi node có


và khóa​ tối thiểu khóa

Các khóa trong cây con thứ đều


Số node con bằng số khóa nhỏ hơn khóa i, các khóa trong
cộng với 1 (trừ node lá)​ cây con thứ đều lớn hơn khóa ​
Chọn như thế nào ?
● Khi m lớn, cây sẽ thấp hơn, có thể giúp việc tìm
kiếm hiểu quả hơn, các node tốn nhiều bộ nhớ hơn.​
● Nên chọn m phù hợp với disk block size, nghĩa là
để dữ liệu tối đa trên 1 node gần bằng với kích
thước 1 block.

NODE
DATA

DISK BLOCK
SIZE
ƯU NHƯỢC ĐIỂM

Đảm bảo độ phức tạp luôn là O(logn)


Có thể tốn bộ nhớ do sử dụng
cho các tác vụ cơ bản.
nhiều con trỏ.

B Tree tự cân bằng. Chậm hơn các cấu trúc tìm kiếm khác
(Hash table) với dữ liệu nhỏ.

Hiệu quả cao khi sử dụng lên lượng dữ liệu


Không thực hiện tốt range query.
cực lớn và các bộ nhớ điện tĩnh

Chiều cao cây thấp.


CÁC THAO TÁC

CHÈN TÌM KIẾM

DUYỆT CÂY XÓA


CHÈN NODE
Tạo cây BTtree [10, 20, 30, 40, 50]​

Bậc 5 (m = 5)​

Số khóa tối đa của một node = m -1 = 4

10 20 30 40 50
CHÈN NODE
Tạo cây BTtree [10, 20, 30, 40, 50]​

Bậc 5 (m = 5)​

Số khóa tối đa của một node = m -1 = 4

10 20 30 40 50
CHÈN NODE
Tạo cây BTtree [10, 20, 30, 40, 50]​

Bậc 5 (m = 5)​

Số khóa tối đa của một node = m -1 = 4

30

10 20 40 50
DUYỆT CÂY
● Duyệt qua và in ra tất cả khóa theo thứ tự
tăng dần​
● Nếu là lá thì in các khóa và kết thúc​
● Duyệt node con [0] rồi in khóa [0]​
● ...​
● Duyệt node con [m-1] rồi in khóa [m-1]​
● Duyệt node con [m]
TÌM KIẾM
● Bắt đầu từ gốc.
● Với mỗi node trung gian:

○ Nếu trong node này có khóa cần tìm, trả về kết quả.

○ Nếu không, duyệt xuống node con ngay trước khóa lớn hơn
đầu tiên.
● Nếu duyệt đến node lá mà không có khóa cần tìm, trả về
NULL.
TÌM KIẾM
Tìm node 50, 240.
XÓA

● Tìm kiếm phần tử đó.


● Xóa khóa tìm được và cân
bằng cây nếu số khóa nhỏ
hơn tối thiểu
CÂN BẰNG LẠI CÂY

● Node nhánh, rễ: ● Node lá:

○ Thiếu khóa: chuyền node con sang node bên cạnh, ○ Thiếu khóa: lấy khóa gần nhất
nếu không được thì lấy khóa gần nhất ở node con, của node cha
nếu không lấy được thì gộp 2 node con, nếu còn
thiếu thì tiếp tục lấy ở node cha ○ Thừa khóa: đẩy khóa ở giữa lên
node cha, tách làm 2
○ Thừa khóa: đẩy khóa ở giữa lên node cha, tách làm
2
ỨNG DỤNG &
B+TREE 02
B+ TREE

Các khóa ở tầng ngay Các node lá có toàn bộ Các node lá liên kết với
trên tầng lá là khóa nhỏ các khóa trong cây nhau thành 1 danh sách
nhất của lá bên phải liên kết
CHÈN TRONG B+ TREE
Khi node lá đầy, tách node lá thành 2 tại vị trí và thêm
khóa thứ vào node cha. Nếu node cha đầy thì xử lí như B-
Tree
XÓA TRONG B+ TREE

● Khóa không có ở node cha: ● Khóa cần xóa có ở node cha:

○ Sau khi xóa, nếu cây cần cân bằng thì lấy một khóa ○ Xử lí tương tự nhưng khi xóa khóa
ở node bên cạnh, nếu không lấy được thì gộp node ở lá thì xóa luôn ở node cha chứa
hiện tại với node bên cạnh. khóa đó.

○ Các tầng trên xử lí như B-Tree. ○ Nếu node không ghép thì thêm tiếp
theo khóa đã xóa vào node cha
SO SÁNH VỚI B TREE

Độ bạt (fan-out) lớn hơn

Chiều cao của cây thấp hơn B-Tree


Cài đặt phức tạp hơn.

Cho phép trùng lặp khóa

Xử lý range query tốt hơn


ỨNG DỤNG

Trong quản lý file. Trong các hệ quản trị CSDL.


INDEXING TRONG DBMS

Indexing là sử dụng một cấu trúc dữ liệu để định vị


và truy cập nhanh nhất vào dữ liệu trong các bảng
database

Với mỗi khóa, index trỏ tới địa chỉ dữ liệu trong
một bảng
INDEXING

Indexing là sử dụng một cấu trúc dữ liệu để định vị


và truy cập nhanh nhất vào dữ liệu trong các bảng
database

Với mỗi khóa, index trỏ tới địa chỉ dữ liệu trong
một bảng
INDEXING TRONG DBMS
INDEXING TRONG DBMS
B TREE TRONG INDEXING

Tìm kiếm hiệu quả

Chèn và xóa nhanh

Linh hoạt khi tương tác với ổ đĩa

Xử lý range query tốt


B TREE INDEX .VS HASH INDEX

Có thể sử dụng cho toán từ tìm kiếm 1


khoảng giá trị như Chậm hơn vì phải qua nhiều node​.

Tối ưu hóa toán tử ORDER BY Xử lý query lẻ tốt hơn​.

Một phần của khóa cũng có thể được


sử dụng để tìm kiếm​

Xử lý range query tốt hơn


QUIZ &
DEMO 03
Do you have any questions?

THANK youremail@freepik.com
+91 620 421 83
yourcompany.com

S
CREDITS: This presentation template was created by Slidesgo, including
icons by Flaticon, and infographics & images by Freepik
Please keep this slide for attribution
ádccf?

Không hiệu quả với dữ liệu lớn

Mất cân bằng cây


UNDERSTANDING THE PROBLEM
MAR VENU
S S
Despite being red, Mars is a cold Venus has a beautiful name and is
place. It’s full of iron oxide dust, the second planet from the Sun. It’s
which gives the planet its reddish terribly hot, even hotter than
cast Mercury
OUR SOLUTIONS

MARS NEPTUNE
Despite being red, It’s the farthest planet
Mars is a cold place from the Sun

JUPITER SATURN
It’s the biggest planet in Saturn is the ringed
the Solar System one and a gas giant
MAIN COMPETITORS
NEPTUNE
It’s the farthest planet from
the Sun

MARS
Despite being red, Mars is
a cold place

VENUS
Venus is the second planet
from the Sun

SATURN
It’s composed mostly of
hydrogen and helium
MARKET RESEARCH

NEPTUNE
It’s the farthest planet
from the Sun

MERCURY
Mercury is the closest
planet to the Sun

SATURN
Saturn is composed of
hydrogen and helium
ANALYSIS
OUTREACH TOP RATED
VALUES

30% 80% 50%


Mars Mercury Saturn Neptune Venus
TARGET
GENDER AGE

20-39 80%
40-60 50%

500,000
75% Female
+
Employees
60% Male
A Picture Is Worth a
Thousand Words
AWESOME
WORDS
OUR PROCESS

Despite being red, Saturn is composed of


Mars is a cold place hydrogen and helium
MARS SATURN
DAY 02 DAY 04

DAY 01 JUPITER DAY 03 NEPTUNE


It’s the biggest planet in It’s the farthest planet
the Solar System from the Sun
OUR CONSULTANTS
HELENA
PATTERSON
You can replace the image on the
screen with your own

JANE DOE
You can replace the image on the
screen with your own
“This is a quote. Words full of
wisdom that someone important
said and can make the reader get
inspired.”

—SOMEONE
FAMOUS
OUR PARTNERS

Despite being red,


Venus has an extremely Mars is actually a cold
poisonous atmosphere place
VENUS MARS

SATURN MERCURY
Saturn is composed Mercury is the
mostly of hydrogen closest planet to the
and helium Sun
TESTIMONIALS

“Mercury is the closest planet “Venus has a beautiful name “Jupiter is a gas giant and the
to the Sun and the smallest of and is the second planet from biggest planet in the Solar
them all” the Sun” System”
—HENRY
—RYAN DIXON —ALIYA FARLEY McKANE

“Saturn is composed mostly “The Sun is the star at the “Neptune is the fourth-largest
of hydrogen and helium” center of the Solar System” planet in the Solar System”

—BILLY BROOKS —LUCY JADE —ROSE CLARK


4,498,300,00
0
Big numbers catch your
audience’s attention
AWARDS

DATE REASON DESCRIPTION

It’s the closest planet to the Sun


MERCURY 2010 Jupiter
and the smallest one

Despite being red, Mars is


MARS 2012 Neptune
actually a cold place

It has a nice name and is the


VENUS 2016 Saturn
second planet from the Sun
UPCOMING GOALS

JUPITER SATURN NEPTUNE


JUNE 2 OCTOBER 14 JANUARY 23

It’s the biggest planet Saturn is composed Neptune is the farthest


in the Solar System mostly of hydrogen planet from the Sun
and helium
SNEAK PEEK

You can replace the images on these screens


with your own work
ALTERNATIVE
RESOURCES
RESOURCES

Did you like the resources on this template? Get


them for free at our other websites.

VECTORS PHOTOS

● Abstract pixel rain blue background ● Female colleagues discussing work at office
● Dashboard element collection ● Close-up confident adult woman posing
● Red and blue neon fingerprint background ● Portrait of beautiful adult woman smiling
● Dashboard element collection template
Instructions for use
In order to use this template, you must credit Slidesgo by keeping the Thanks slide.

You are allowed to:


- Modify this template.
- Use it for both personal and commercial projects.

You are not allowed to:


- Sublicense, sell or rent any of Slidesgo Content (or a modified version of Slidesgo Content).
- Distribute Slidesgo Content unless it has been expressly authorized by Slidesgo.
- Include Slidesgo Content in an online or offline database or file.
- Offer Slidesgo templates (or modified versions of Slidesgo templates) for download.
- Acquire the copyright of Slidesgo Content.

For more information about editing slides, please read our FAQs or visit Slidesgo School:
https://slidesgo.com/faqs and https://slidesgo.com/slidesgo-school
Fonts & colors used
This presentation has been made using the following fonts:

Share Tech
(https://fonts.google.com/specimen/Share+Tech)

Maven Pro
(https://fonts.google.com/specimen/Maven+Pro)

#002845 #e898ac #00cfcc #ff9973


Use our editable graphic resources...
You can easily resize these resources without losing quality. To change the color, just ungroup the resource
and click on the object you want to change. Then, click on the paint bucket and select the color you want.
Group the resource again when you’re done.
JANUARY FEBRUARY MARCH APRIL MAY JUNE

PHASE 1

Task 1

Task 2

PHASE 2

Task 1

Task 2

JANUARY FEBRUARY MARCH APRIL

PHASE
1

Task 1

Task 2
...and our sets of editable icons
You can resize these icons without losing quality.
You can change the stroke and fill color; just select the icon and click on the paint bucket/pen.
In Google Slides, you can also use Flaticon’s extension, allowing you to customize and add even more icons.
Educational Icons Medical Icons
Business Icons Teamwork Icons
Help & Support Icons Avatar Icons
Creative Process Icons Performing Arts Icons
Nature Icons
SEO & Marketing Icons

You might also like