Unbalances balanced avl tree
allevo opened this issue · comments
Describe the bug
When the results are already sorted, the avl tree is not balanced at all.
To Reproduce
const numbers = [
[ 7288, 0.4166666666666667 ],
[ 19172, 0.4791666666666667 ],
[ 5025, 0.5526315789473685 ],
[ 9148, 0.5625 ],
[ 10806, 0.6097560975609756 ]
]
const tree = create(0, [])
for (const [id, number] of numbers) {
insert(tree, number, [id])
}
console.log(JSON.stringify(tree, null, 2))
console.log('isBalanced', isBalanced(tree))
})
Expected behavior
The tree should be balanced.
Environment Info
node: v20.8.1
Affected areas
Data Insertion
Additional context
No response