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

AVL Tree ใน JavaScript


AVL tree (ตั้งชื่อจากผู้คิดค้น Adelson-Velsky และ Landis) เป็น self-balancing binary search tree Self-balancing tree คือ tree ที่ทำ rotation ภายใน subtrees เพื่อให้สมดุลทั้งซ้ายและขวา

Tree แบบนี้มีประโยชน์อย่างยิ่งในกรณีที่ insertions ทำให้ tree หนักด้านใดด้านหนึ่ง Balanced trees ทำให้ lookup times ใกล้ O(log(n)) ในขณะที่ unbalanced tree เล็งไปทาง O(n)