-
Notifications
You must be signed in to change notification settings - Fork 272
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
Add m-ary trees #101
Comments
Hi, can I start working on this issue as a part of RGSoC20? |
Hi, @vibhu18116 Please start by designing an API for m-ary trees. Please let us know if you face any problem/queries. |
Thank you for allowing me to work on this. I believe the API design would closely follow that of binary trees. Hence these are a few APIs I think should form a basis:
This would initialise a new m-ary tree. m_value will be used to determine the maximum value of m (the number of children of a node), default to 2 (binary tree in that case). array_flag can be set to indicate that an array implementation is required and it can remain 0 for pointer implementation. Rest of the parameters will be same as binary tree implementation.
The above four will behave in the same way as in the binary tree. Implementation of the
Kindly check if these APIs work. |
IMO, using only array based implementation will be better here as pointers are somewhat unsafe, so avoid them where ever possible. Instead of Can you please explain the use of the values returned by
IMO, just You may refer, https://github.com/codezonediitj/pydatastructs/blob/master/pydatastructs/trees/binary_trees.py while implementing the above APIs. |
Note that m-ary tree is not a search tree, so we don't need to worry about the manner in which nodes are stored. We need a creative way to avoid the exponential space complexity of array based implementation. May be a new type of node inheriting |
I thought I would update the names of functions as suggested. |
I checked this implementation, but a lot of functions like insert, delete are not implemented, probably because they depend on comparision key. Since the insert, delete API would follow the same pattern, should I first implement them? |
Actually, binary trees are quite abstract, hence their insert and delete operations are left unimplemented. What logic should be followed while making insertions to a binary tree? Both the operations are well defined for binary search trees. |
I get your point. I will try to come up with actual implementation and try to create a PR in a day or two for m-ary tree. |
Can I keep If a concrete implementation is required, then should I modify the m-ary tree itself or create a new binary tree with nodes of type TreeNode? Currently, I have made a new node type extending TreeNode as suggested earlier which form nodes of m-ary tree. |
We can keep it as abstraction in m-ary tree but a concrete implementation can be added in m-ary search tree.
IMO, a new tree should returned. |
Added M_aryTreeNode for use in M_ary tree and an implementation for M_ary Tree. The work is in reference with issue codezonediitj#101.
I created a PR. However, the Travis checks failed due to some trailing whitespaces. Can you please guide how do I ensure there are no trailing white spaces? Also can you review the code once to see if it is the desired implementation? |
It's time to make a PR for |
Okay. I will start work on it soon :) |
And I hope you are working on your RGSoC application. The deadline is 30th March according to the latest information I have. |
Yes. I will start working on application as well. |
I was looking through MArySearchTree on the link you referenced earlier. However, I don't see a determinate way of insertion. Say, if the nodes can have 4 children, and root has currently 3 only as a data item, then on trying to insert 5, it can become a part of the root, or go in a child node to the right of 3. Can you clarify this point once? |
I see, the current implementation in
Some research is needed. |
I think adding a method to insert a value in the node in Does this work? |
How it will help in having multiple keys in the node? |
So, the node can store the (data, key) as a tuple in a dynamically sized array which can grow up to (m-1) size where m is the maximum number of children a node can have. The information about the children nodes is already stored in the children array. |
Here's what I have thought of, MAryTreeNode
The |
This works. But the array could have been subjected to binary search to search a particular element in that node. However, this won't be possible in the linked list implementation. So, what is your opinion about this? |
Well, the maximum size of the key_list won't be very large so, O(log(m)) or O(m) will not make much of a difference. Over optimisation can be avoided here. If |
Though if you are aware of any use case where |
I didn't find any specifics about the node size in different applications. So, if you say, I can proceed with a linked list. |
Sure, feel free to proceed. |
@czgdp1807 I hope this tree has already been implemented why not close this one! |
Description of the problem
Adding m-ary trees will be a nice idea. May be a array based(allows printing the trees) or pointer(better space utilisation) or both would be better.
Example of the problem
References/Other comments
.. [1] https://en.wikipedia.org/wiki/M-ary_tree
The text was updated successfully, but these errors were encountered: