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

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


B-Tree Query (Searching)

คล้าย BST Query

ตัวอย่าง

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

ค้นหา 66: Root 46 → 66 > 46 ไป Right Child มี [56, 81] 66 > 56 และ < 81 เข้า Subtree ระหว่าง 56-81 ถึง Leaf เจอ 66

อัลกอริทึม

BTreeSearch(root, key)
Input: Root, Key
Output: Value หรือ Null
x := Read root
if x index node:
    if object o with o→key = key: return o→val
    find child x→child[i] containing key
    return BTreeSearch(x→child[i], key)
else:
    if object o with o→key = key: return o→val
    else return null
end if