Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible combination after few insertions (2-3 tree) #1

Open
wortelus opened this issue Nov 22, 2022 · 3 comments
Open

Impossible combination after few insertions (2-3 tree) #1

wortelus opened this issue Nov 22, 2022 · 3 comments

Comments

@wortelus
Copy link

wortelus commented Nov 22, 2022

	minimumItemsInNode := 1
	tree := NewTree(minimumItemsInNode)

	for i := 1; i < 100; i++ {
		value := strconv.Itoa(i)
		tree.Put(value, value)
		tree.Find(value)
	}

used while creating B-tree of 2-3 structure, creates impossible combination of
6
| \ \
(3), (5, 8), (7)
Is there something I am missing? This should be contradicted even while it has 1 element at the root (6).
Is there an inner constraint for "ignoring" childs without removing the references? That was my guess shot.

@amit-davidson
Copy link
Owner

Hey @wortelus :)
I'm not sure how you got to the tree you mention from the code you added.

  1. How did you create the 2-3 tree?
  2. And how did you remove items? What was your starting tree?

@wortelus
Copy link
Author

Hi :) thanks for the quick response!

If I understand your code correctly, 2-3 tree should be created by setting minimumItemsInNode := 1 in NewTree(minimumItemsInNode), as 2-3 tree has minimum key count of 1 and max key count of 2.

After that I just looped by putting the values 1..2..3..4 etc. by Put, as you can see in my code attachment
I didn't remove any items, I just noticed in debugging, that there is at the second layer on right of root impossible combination on inner node with value "6", containing 3 other nodes as children, with values of (3), (5, 8), (7) in the memory.

I did not find out why would that be :/

@amit-davidson
Copy link
Owner

I'll take a look at it and let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants