Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

B+ Tree Query ในโครงสร้างข้อมูล


B+ Tree Query (Searching)

คล้าย B-Tree Query รองรับ Range Query

ตัวอย่าง B+ Tree

B+ Tree Query ในโครงสร้างข้อมูล

การค้นหา

คล้าย BST: ค้นหา 63 เริ่ม Root 63 > 60 แต่ < 75 ไป Right Child ของ 60 ได้ 63 แต่เป็น Internal Node ไม่ใช่ Data จริง ต้องไป Right Child อีกครั้ง ที่ Leaf Level จะเจอ 63 เป็น Record จริง

Range Query 63 ถึง 78: หา Leaf ของ 63 แล้วเดิน Linked Leaf Nodes หา จนกว่าจะถึง 78 ไม่ต้อง Backtrack

อัลกอริทึม

BPlusTreeSearch(root, key)
Input: Root, Key to find
Output: Value หรือ Null
Apply binary search on records
if found: return record
else if leaf and not found: return null