Comments (9)
Because the closest book I had on how to do BTrees used it ;)
from btree.
And it's my favorite :D
from btree.
I believe I got most of my stuff from https://en.wikipedia.org/wiki/Introduction_to_Algorithms
I'd also check out http://assets.en.oreilly.com/1/event/36/How%20TokuDB%20Fractal%20Tree%20Databases%20Work%20Presentation.pdf and https://en.wikipedia.org/wiki/Fractal_tree_index
from btree.
I believe this is actually working as intended.
In this BTree implementation, the tree makes a single pass down the tree to find/remove the node. All redistribution is done on the way down, none on the way up. Also, while traversing the tree, we only have a view of the current node and its direct children. Given that constraint, at each node we traverse we must assume the worst case about our children's children (that they have the least number of nodes they could possibly have) and act accordingly.
While in your case, the leaf node did have enough elements, the root node doesn't know that (it only sees itself and its children, not its children's children. Consider this case:
NODE:[11]
NODE:[5 8]
NODE:[1 2]
NODE:[6 7]
NODE:[9 10]
NODE:[14 17]
NODE:[12 13]
NODE:[15 16]
NODE:[18 19 20]
The root here says "my child has 2, and its child may have none to spare". So, it performs a merge before traversing down. By merging first, it knows that, should the child not have enough, its parent will have a spare value to give.
In short, we use option 2 of https://en.wikipedia.org/wiki/B-tree#Deletion: "Do a single pass down the tree, but before entering (visiting) a node, restructure the tree so that once the key to be deleted is encountered, it can be deleted without triggering the need for any further restructuring"
I believe that, had we implemented option 1 ("Locate and delete the item, then restructure the tree to retain its invariants"), the tree would behave as you expect and would not have rebalanced after the deletion of 1.
from btree.
Thanks for clarifying the assumptions. This implementation, by design, takes a proactive tree restructure approach during deletion to save one extra pass, instead of the reactive approach which aims to reduce unnecessary restructure operations. Agree to close the issue as "Working as Designed".
from btree.
Hey, why was the single pass strategy used instead of the other popular one?
from btree.
The Btree I implemented in C++ is designed to be used as a "disk btree" to be used at scale in my data management system... which implementation would you recommend that I use?
from btree.
I think single-pass is better for disk, but you could also look at fractal trees and the like that are even better for disk purposes.
from btree.
Okay, thanks... may I know which book you read?
from btree.
Related Issues (20)
- Can it be done if I want to insert pair instead of int? HOT 1
- Q: how do I delete a range? HOT 6
- deleteMin appears to be O(n); not O(log(n)) as expected from a balanced binary tree. HOT 2
- Read traversal and COW HOT 1
- only one goroutine put and some other goroutines get , Is it safe ? HOT 1
- Tagged releases
- panic: runtime error: index out of range using Ascend iterator HOT 3
- Marshaling btree on disk
- Question on iteration HOT 8
- "t2" declared but "out" returned
- Bounds issue in insertAt HOT 3
- Go modules giving issues while importing kubernetes/cli-runtime
- Worked unexpected in go rountine? HOT 1
- What is the meaning of `copyOnWriteContext`? HOT 1
- Generic approach HOT 4
- should call Less() fewer times when iterating HOT 1
- BTree Iterators
- is it b-tree or b+tree? HOT 1
- is it b plus tree?? HOT 1
- stack overflow while deleting a key from the tree
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from btree.