Git Product home page Git Product logo

b_and_bplus_tree's Introduction

image

b_and_bplus_tree's People

Contributors

ashwin-op avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

b_and_bplus_tree's Issues

A problem about node split

In the file 'B-Tree.py'.
There are some code problem.
Details are as follows.
In function '_splitChild(self, x, i)',

t = self.t
        y = x.children[i]
        z = Node(y.leaf)
        x.children.insert(i + 1, z)
        x.keys.insert(i, y.keys[t - 1])
        z.keys = y.keys[t: (2 * t) - 1]
        y.keys = y.keys[0: t - 1]
        if not y.leaf:
            z.children = y.children[t: 2 * t]
            y.children = y.children[0: t - 1]

In my view, the correct version is:
z.keys = y.keys[t:(2t)-1]; y.keys = y.keys[0:t-2]
z.children=y.children[t:2
t];y.children=y.children[0:t-1]

hi,i download your code and debug in my laptop,but i face IndexError: list index out of range

`def main():
B = BTree(2) ------ i changed

# Insert
customNo = 20   ------  i changed
for i in range(1,customNo+1):
    B.insert((i, randint(i, 5 * i)))
B.printTree(B.root)
print()

`

when i run,i get the following error:
`E:\workspace\PycharmProjects\B_and_Bplus_Tree\venv\Scripts\python.exe E:/workspace/PycharmProjects/B_and_Bplus_Tree/B-Tree.py
Level 0 --> 1: (8, 31)
Level 1 --> 1: (4, 10)
Level 2 --> 1: (2, 6)
Level 3 --> 1: (1, 4)
Level 1 --> 1: (12, 30)
Level 2 --> 1: (10, 19)
Level 3 --> 1: (9, 22)
Level 2 --> 3: (14, 32) (16, 42) (18, 25)
Level 3 --> 1: (13, 14)
Level 3 --> 1: (15, 27)
Level 3 --> 1: (17, 58)
Level 3 --> 2: (19, 76) (20, 71)

Key 12 deleted!
Traceback (most recent call last):
File "E:/workspace/PycharmProjects/B_and_Bplus_Tree/B-Tree.py", line 313, in
main()
File "E:/workspace/PycharmProjects/B_and_Bplus_Tree/B-Tree.py", line 298, in main
B.delete(B.root, (toDelete,))
File "E:/workspace/PycharmProjects/B_and_Bplus_Tree/B-Tree.py", line 156, in delete
self.delete(x.children[i], k)
IndexError: list index out of range

Process finished with exit code 1
`

Error in B-tree

There is a typo in the realization of B-tree.
It's necessary to change in file B-Tree.py in function _deletePredecessor line #193 from

return x.pop()

to

return x.keys.pop()

Since argument x is not a list of keys, it is an object-node that contains a list of keys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.