SlideShare a Scribd company logo
B-Tree & R-Tree

Md. Shakil Ahmed
Senior Software Engineer
Astha it research & consultancy ltd.
Dhaka, Bangladesh
B-Tree
Why do we use B-trees
• It was difficult to access a large amount of
  data from the secondary memory
• Many of the algorithms were introduced to
  make our search very fast, to access the
  required data from the secondary memory
• B-trees are more effective and faster
• B-trees are used in many of the database
  management system
Definition of a B-tree
• A B-tree of order m is an m-way tree (i.e., a tree where each
  node may have up to m children) in which:
   1. the number of keys in each non-leaf node is one less than
       the number of its children and these keys partition the
       keys in the children in the fashion of a search tree
   2. all non-leaf nodes except the root have at least m / 2
       children
   3. the root is either a leaf node, or it has from two to m
       children
   The number m is large than or equal to 2.
Sample B tree
B-tree of order 5
  all internal nodes have at least ceil(5 / 2) = ceil(2.5) = 3 children
maximum number of children that a node can have is 5
Insertion
• B-tree of order 5:
CNGAHEKQMFWLTZDPRXYS

Order 5 means that a node can have a
 maximum of 5 children and 4 keys.
All nodes other than the root must have a
 minimum of 2 keys.
• C N G A Order this
  ACGN
• Inserting ACGN
Inserting H
Inserting E, K, and Q proceeds without
         requiring any splits:
Inserting M requires a split
The letters F, W, L, and T are then added without
               needing any split
Adding Z
Inserting D
Inserting s
DELETION (H)
Delete T
Delete R
Delete E
R-tree
• R-trees are tree data structures used for
  spatial access methods, for indexing multi-
  dimensional information such as
  geographical coordinates, rectangles or
  polygons.
R-Tree Motivation
                 y axis
            10                             m
                               g   h
             8                                         l
                                                   k
                  e f
             6
                                       i       j
                           d
             4
                    b              a
             2     c

                                                            x axis
             0         2           4   6       8           10



Range query: find the objects in a given range.
E.g. find all hotels in Boston.

No index: scan through all objects. Inefficient!
B+-tree: only cluster based on one dim. Inefficient!
21
R-Tree: Clustering by Proximity
                                 y axis
                        10                                               m
                                                  g    h
                         8                                                               l
                                                                                 k
                                      e f
                         6
                                                                    i        j
                                              d
                         4
                                      b
                                                  E3       a
                                                                   Minimum Bounding Rectangle (MBR)
                         2            c
                                                                                              x axis
                         0                2            4            6        8               10
                                                  Root
                                                      E             E
                                                       1             2

          E        E             E            E                                      E             E
           1        3             4            5                                      6             7       E
                                                                                                             2

     a    b    c             d            e                    f         g           h             i    j   k         l   m
     22                 E
E                        4                             E                                      E                  E
 3                                                      5                                      6                  7
y axis
                                                                R-Tree
                         10                                          m           E7
                                                  g     h
                             8                                                       l
                                                                E6
                                                        E5                   k
                                      e f
                             6            E4                     i       j
                                              d
                             4
                                      b
                                                  E3    a
                             2        c
                                                                                          x axis
                             0            2            4         6       8               10
                                              Root
                                                   E            E
                                                    1            2

          E        E             E            E                                  E             E
           1        3             4            5                                  6             7       E
                                                                                                         2

     a    b    c             d            e                 f        g           h             i    j   k         l   m
     23                 E                             E
E                        4                             5                                  E                  E
 3                                                                                         6                  7
y axis                            R-Tree
                        10                                              m
                                                  g    h
                         8                                                              l
                                                                                k
                                      e f                                           E2
                         6
                                                                   i        j
                                              d            E1
                         4
                                      b                    a
                         2            c
                                                                                             x axis
                         0                2            4           6        8               10
                                                  Root
                                                      E            E
                                                       1            2

          E        E             E            E                                     E             E
           1        3             4            5                                     6             7       E
                                                                                                            2

     a    b    c             d            e                    f        g           h             i    j   k         l   m
E                       E                              E                                     E                  E
 3   24                  4                              5                                     6                  7
y axis                          R-Tree
                    10                                            m
                                            g    h
                     8                                                            l
                                                                          k
                               e f                                            E
                     6                                                         2
                                                             i        j
                                        d            E1
                     4
                                b                    a
                     2          c
                                                                                       x axis
                     0              2            4           6        8               10
                                            Root
                                                E            E
                                                 1            2

          E    E         E              E                                     E             E
           1    3         4              5                                     6             7       E
                                                                                                      2

     a    b    c         d          e                    f        g           h             i    j   k         l   m
E                   E                            E                                     E                  E
 3   25              4                            5                                     6                  7
Range query (given range Q)

Start at root.
1. If current node is non-leaf, for each
   entry <E, ptr>, if box E overlaps Q,
   search subtree identified by ptr.
2. If current node is leaf, for every object in
  the leaf page, report if contained in Q.
y axis          Range Query
                    10                                            m
                                            g    h
                     8                                                            l
                                                                          k
                               e f                                            E
                     6                                                         2
                                                             i        j
                                        d            E1
                     4
                                b                    a
                     2          c
                                                                                       x axis
                     0              2            4           6        8               10
                                            Root
                                                E            E
                                                 1            2

          E    E         E              E                                     E             E
           1    3         4              5                                     6             7       E
                                                                                                      2

     a    b    c         d          e                    f        g           h             i    j   k         l   m
E                   E                            E                                     E                  E
 3   27              4                            5                                     6                  7
y axis          Range Query
                    10                                            m
                                            g    h
                     8                                                            l
                                                                          k
                               e f                                            E
                     6                                                         2
                                                             i        j
                                        d            E1
                     4
                                b                    a
                     2          c
                                                                                       x axis
                     0              2            4           6        8               10
                                            Root
                                                E            E
                                                 1            2

          E    E         E              E                                     E             E
           1    3         4              5                                     6             7       E
                                                                                                      2

     a    b    c         d          e                    f        g           h             i    j   k         l   m
E                   E                            E                                     E                  E
 3   28              4                            5                                     6                  7
Aggregation Query
     • Given a range, find some aggregate value
       of objects in this range.
     • COUNT, SUM, AVG, MIN, MAX
     • E.g. find the total number of hotels in
       Massachusetts.
     •   Straightforward approach: reduce to a range query.



     •   Better approach: along with each index entry, store aggregate of the
         sub-tree.



29
Aggregation Query
                            y axis
                   10                                        m
                                           g    h
                      8                                                      l
                                                                     k
                              e f                                        E
                      6                                                   2
                                                         i       j
                                       d            E1
                      4
                               b                 a
                      2        c
                                                                                  x axis
                      0            2            4        6       8               10
                                           Root
                                               E :8      E :5
                                                1         2

          E    E :3       E :2 E :3                                      E :3          E :2
           1    3          4    5                                         6             7         E
                                                                                                   2

     a    b    c        d          e                 f       g           h             i      j   k         l   m
E                  E                            E                                 E                    E
 3   30             4                            5                                 6                    7
Aggregation Query
                             y axis
                    10                                        m
                                            g    h
                       8                                                      l
                                                                      k
                               e f                                        E
                       6                                                   2
                                                          i       j
                                        d            E1
                       4
                                b                 a
Subtree pruned!2                c
                                                                                   x axis
                       0            2            4        6       8               10
                                            Root
                                                E :8      E :5
                                                 1         2

           E    E :3       E :2 E :3                                      E :3          E :2
            1    3          4    5                                         6             7         E
                                                                                                    2

      a    b    c        d          e                 f       g           h             i      j   k         l   m
 E                  E                            E                                 E                    E
  3   31             4                            5                                 6                    7
Insert object o
• Start at root and go down to “best-fit” leaf L.
  – Go to child whose box needs least enlargement
    to cover B; resolve ties by going to smallest area
    child.
• If best-fit leaf L has space, insert entry and
  stop. Otherwise, split L into L1 and L2.
  – Adjust entry for L in its parent so that the box
    now covers (only) L1.
  – Add an entry (in the parent node of L) for L2.
    (This could cause the parent node to recursively
    split.)
E.g. 1: no split, no enlargement
                             y axis
                    10                                            m                                  insert o
                                            g    h
                     8                                                            l
                                                                          k
                               e f                                            E
                     6                                                         2
                                                             i        j
                                        d            E1
                     4
                                b                    a
                     2          c
                                                                                       x axis
                     0              2            4           6        8               10
                                            Root
                                                E            E
                                                 1            2

          E    E         E              E                                     E             E
           1    3         4              5                                     6             7       E
                                                                                                      2

     a    b    c         d          e                    f        g           h             i    j   k         l   m   o
E                   E                            E                                     E                  E
 3   33              4                            5                                     6                  7
E.g. 2: no split, but enlargement
                              y axis
                     10                                            m                                  insert o
                                             g    h
                      8                                                            l
                                                                           k
                                e f                                            E
                      6                                                         2
                                                              i        j
                                         d            E1
                      4
                                 b                    a
                      2          c
                                                                                        x axis
                      0              2            4           6        8               10
                                             Root
                                                 E            E
                                                  1            2

           E    E         E              E                                     E             E
            1    3         4              5                                     6             7       E
                                                                                                       2

     a    b     c         d          e                    f        g           h             i    j   k         l   m   o
E                    E                            E                                     E                  E
 3   34               4                            5                                     6                  7
E.g. 2: no split, but enlargement
                              y axis
                     10                                            m                                  insert o
                                             g    h
                      8                                                            l
                                                                           k
                                e f                                            E
                      6                                                         2
                                                              i        j
                                         d            E1
                      4
                                 b                    a
                      2          c
                                                                                        x axis
                      0              2            4           6        8               10
                                             Root
                                                 E            E
                                                  1            2

           E    E         E              E                                     E             E
            1    3         4              5                                     6             7       E
                                                                                                       2

     a    b     c         d          e                    f        g           h             i    j   k         l   m   o
E                    E                            E                                     E                  E
 3   35               4                            5                                     6                  7
y axis              E.g. 3: split
                    10                                            m
                                            g    h
                     8                                                            l
                                                                          k
                               e f                                            E
                     6                                                         2
                                                             i        j
                                        d            E1
                     4
                                b                    a                                               insert o
                     2          c
                                                                                       x axis
                     0              2            4           6        8               10
                                            Root
                                                E            E
                                                 1            2

          E    E         E              E                                     E             E
           1    3         4              5                                     6             7       E
                                                                                                      2

     a    b    c         d          e                    f        g           h             i    j    k   o          l   m
E                   E                            E                                     E                        E
 3   36              4                            5                                     6                        7
y axis              E.g. 3: split
                    10                                            m
                                            g    h
                     8                                                            l
                                                                  o       k
                               e f                                            E
                     6                                                         2
                                                             i        j
                                        d            E1
                     4
                                b                    a
                     2          c
                                                                                       x axis
                     0              2            4           6        8               10
                                            Root
                                                E            E
                                                 1            2

          E    E         E              E                                     E             E    E’
           1    3         4              5                                     6             7    6   E
                                                                                                       2

     a    b    c         d          e                    f        g           h             i    o         j   k        l   m
E                   E                            E                                     E                           E
 3   37              4                            5                                     6                           7
Thanks!

More Related Content

What's hot

Project for Student Result System
Project for Student Result SystemProject for Student Result System
Project for Student Result System
KuMaR AnAnD
 
Partitioning
PartitioningPartitioning
Partitioning
Reema Gajjar
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
IMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSIS
IMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSISIMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSIS
IMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSIS
Shivam Porwal
 
Hashing
HashingHashing
Hashing
Amar Jukuntla
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization emailharmeet
 
Employee Management System
Employee Management SystemEmployee Management System
Employee Management System
Monotheist Sakib
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
Hema Kashyap
 
Database security
Database securityDatabase security
Database security
Software Engineering
 
Advanced Trees
Advanced TreesAdvanced Trees
Advanced Trees
Selvaraj Seerangan
 
Pattern matching
Pattern matchingPattern matching
Pattern matchingshravs_188
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examplesmua99
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
Dexter Paul Gumahad
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
SVijaylakshmi
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
Umme habiba
 

What's hot (20)

Project for Student Result System
Project for Student Result SystemProject for Student Result System
Project for Student Result System
 
Partitioning
PartitioningPartitioning
Partitioning
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
Anomalies in database
Anomalies in databaseAnomalies in database
Anomalies in database
 
IMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSIS
IMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSISIMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSIS
IMAGE STEGANOGRAPHY JAVA PROJECT SYNOPSIS
 
Hashing
HashingHashing
Hashing
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
 
Employee Management System
Employee Management SystemEmployee Management System
Employee Management System
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
 
Database security
Database securityDatabase security
Database security
 
Advanced Trees
Advanced TreesAdvanced Trees
Advanced Trees
 
Pattern matching
Pattern matchingPattern matching
Pattern matching
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
 
Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
Linked list
Linked listLinked list
Linked list
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 

Similar to B-tree & R-tree

Double patterning (4/20 update)
Double patterning (4/20 update)Double patterning (4/20 update)
Double patterning (4/20 update)Danny Luk
 
1600 Tapered Timber Assem
1600 Tapered Timber Assem1600 Tapered Timber Assem
1600 Tapered Timber Assem
pberlad
 
1600 Tapered Timber Assem
1600 Tapered Timber Assem1600 Tapered Timber Assem
1600 Tapered Timber Assem
pberlad
 
Equifax (automated credit report user guide)
Equifax (automated credit report user guide)Equifax (automated credit report user guide)
Equifax (automated credit report user guide)
Leo Lee
 
Worked examples projects unit 1
Worked examples projects unit 1Worked examples projects unit 1
Worked examples projects unit 1Sameer Alam
 
Folding Table Standard - Assembly Instructions Rev. 05
Folding Table Standard - Assembly Instructions Rev. 05Folding Table Standard - Assembly Instructions Rev. 05
Folding Table Standard - Assembly Instructions Rev. 05
Renzo Lisei
 
Basic shapes
Basic shapesBasic shapes
Basic shapes
Tatyana Remayeva
 
Crucigrama nombres
Crucigrama nombresCrucigrama nombres
Crucigrama nombreslucipicareta
 

Similar to B-tree & R-tree (10)

Double patterning (4/20 update)
Double patterning (4/20 update)Double patterning (4/20 update)
Double patterning (4/20 update)
 
1600 Tapered Timber Assem
1600 Tapered Timber Assem1600 Tapered Timber Assem
1600 Tapered Timber Assem
 
1600 Tapered Timber Assem
1600 Tapered Timber Assem1600 Tapered Timber Assem
1600 Tapered Timber Assem
 
Equifax (automated credit report user guide)
Equifax (automated credit report user guide)Equifax (automated credit report user guide)
Equifax (automated credit report user guide)
 
Worked examples projects unit 1
Worked examples projects unit 1Worked examples projects unit 1
Worked examples projects unit 1
 
Day 6 graphing review
Day 6 graphing reviewDay 6 graphing review
Day 6 graphing review
 
Folding Table Standard - Assembly Instructions Rev. 05
Folding Table Standard - Assembly Instructions Rev. 05Folding Table Standard - Assembly Instructions Rev. 05
Folding Table Standard - Assembly Instructions Rev. 05
 
Geom9-5
Geom9-5Geom9-5
Geom9-5
 
Basic shapes
Basic shapesBasic shapes
Basic shapes
 
Crucigrama nombres
Crucigrama nombresCrucigrama nombres
Crucigrama nombres
 

More from Shakil Ahmed

Algorithm
AlgorithmAlgorithm
Algorithm
Shakil Ahmed
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
Shakil Ahmed
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
Shakil Ahmed
 
Observer pattern
Observer patternObserver pattern
Observer pattern
Shakil Ahmed
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
Shakil Ahmed
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
Shakil Ahmed
 
Facade pattern
Facade patternFacade pattern
Facade pattern
Shakil Ahmed
 
Composite pattern
Composite patternComposite pattern
Composite pattern
Shakil Ahmed
 
Command pattern
Command patternCommand pattern
Command pattern
Shakil Ahmed
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
Shakil Ahmed
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
Shakil Ahmed
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
Shakil Ahmed
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
Shakil Ahmed
 
iOS 5
iOS 5iOS 5
Ios development
Ios developmentIos development
Ios development
Shakil Ahmed
 
Graph
GraphGraph
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
Shakil Ahmed
 
Segment tree
Segment treeSegment tree
Segment tree
Shakil Ahmed
 
Tree & bst
Tree & bstTree & bst
Tree & bst
Shakil Ahmed
 

More from Shakil Ahmed (20)

Algorithm
AlgorithmAlgorithm
Algorithm
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Command pattern
Command patternCommand pattern
Command pattern
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
iOS 5
iOS 5iOS 5
iOS 5
 
Ios development
Ios developmentIos development
Ios development
 
Graph
GraphGraph
Graph
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Segment tree
Segment treeSegment tree
Segment tree
 
Tree & bst
Tree & bstTree & bst
Tree & bst
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 

B-tree & R-tree

  • 1. B-Tree & R-Tree Md. Shakil Ahmed Senior Software Engineer Astha it research & consultancy ltd. Dhaka, Bangladesh
  • 3. Why do we use B-trees • It was difficult to access a large amount of data from the secondary memory • Many of the algorithms were introduced to make our search very fast, to access the required data from the secondary memory • B-trees are more effective and faster • B-trees are used in many of the database management system
  • 4. Definition of a B-tree • A B-tree of order m is an m-way tree (i.e., a tree where each node may have up to m children) in which: 1. the number of keys in each non-leaf node is one less than the number of its children and these keys partition the keys in the children in the fashion of a search tree 2. all non-leaf nodes except the root have at least m / 2 children 3. the root is either a leaf node, or it has from two to m children The number m is large than or equal to 2.
  • 6. B-tree of order 5 all internal nodes have at least ceil(5 / 2) = ceil(2.5) = 3 children maximum number of children that a node can have is 5
  • 7. Insertion • B-tree of order 5: CNGAHEKQMFWLTZDPRXYS Order 5 means that a node can have a maximum of 5 children and 4 keys. All nodes other than the root must have a minimum of 2 keys.
  • 8. • C N G A Order this ACGN • Inserting ACGN
  • 10. Inserting E, K, and Q proceeds without requiring any splits:
  • 12. The letters F, W, L, and T are then added without needing any split
  • 20. R-tree • R-trees are tree data structures used for spatial access methods, for indexing multi- dimensional information such as geographical coordinates, rectangles or polygons.
  • 21. R-Tree Motivation y axis 10 m g h 8 l k e f 6 i j d 4 b a 2 c x axis 0 2 4 6 8 10 Range query: find the objects in a given range. E.g. find all hotels in Boston. No index: scan through all objects. Inefficient! B+-tree: only cluster based on one dim. Inefficient! 21
  • 22. R-Tree: Clustering by Proximity y axis 10 m g h 8 l k e f 6 i j d 4 b E3 a Minimum Bounding Rectangle (MBR) 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m 22 E E 4 E E E 3 5 6 7
  • 23. y axis R-Tree 10 m E7 g h 8 l E6 E5 k e f 6 E4 i j d 4 b E3 a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m 23 E E E 4 5 E E 3 6 7
  • 24. y axis R-Tree 10 m g h 8 l k e f E2 6 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m E E E E E 3 24 4 5 6 7
  • 25. y axis R-Tree 10 m g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m E E E E E 3 25 4 5 6 7
  • 26. Range query (given range Q) Start at root. 1. If current node is non-leaf, for each entry <E, ptr>, if box E overlaps Q, search subtree identified by ptr. 2. If current node is leaf, for every object in the leaf page, report if contained in Q.
  • 27. y axis Range Query 10 m g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m E E E E E 3 27 4 5 6 7
  • 28. y axis Range Query 10 m g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m E E E E E 3 28 4 5 6 7
  • 29. Aggregation Query • Given a range, find some aggregate value of objects in this range. • COUNT, SUM, AVG, MIN, MAX • E.g. find the total number of hotels in Massachusetts. • Straightforward approach: reduce to a range query. • Better approach: along with each index entry, store aggregate of the sub-tree. 29
  • 30. Aggregation Query y axis 10 m g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E :8 E :5 1 2 E E :3 E :2 E :3 E :3 E :2 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m E E E E E 3 30 4 5 6 7
  • 31. Aggregation Query y axis 10 m g h 8 l k e f E 6 2 i j d E1 4 b a Subtree pruned!2 c x axis 0 2 4 6 8 10 Root E :8 E :5 1 2 E E :3 E :2 E :3 E :3 E :2 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m E E E E E 3 31 4 5 6 7
  • 32. Insert object o • Start at root and go down to “best-fit” leaf L. – Go to child whose box needs least enlargement to cover B; resolve ties by going to smallest area child. • If best-fit leaf L has space, insert entry and stop. Otherwise, split L into L1 and L2. – Adjust entry for L in its parent so that the box now covers (only) L1. – Add an entry (in the parent node of L) for L2. (This could cause the parent node to recursively split.)
  • 33. E.g. 1: no split, no enlargement y axis 10 m insert o g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m o E E E E E 3 33 4 5 6 7
  • 34. E.g. 2: no split, but enlargement y axis 10 m insert o g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m o E E E E E 3 34 4 5 6 7
  • 35. E.g. 2: no split, but enlargement y axis 10 m insert o g h 8 l k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k l m o E E E E E 3 35 4 5 6 7
  • 36. y axis E.g. 3: split 10 m g h 8 l k e f E 6 2 i j d E1 4 b a insert o 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E 1 3 4 5 6 7 E 2 a b c d e f g h i j k o l m E E E E E 3 36 4 5 6 7
  • 37. y axis E.g. 3: split 10 m g h 8 l o k e f E 6 2 i j d E1 4 b a 2 c x axis 0 2 4 6 8 10 Root E E 1 2 E E E E E E E’ 1 3 4 5 6 7 6 E 2 a b c d e f g h i o j k l m E E E E E 3 37 4 5 6 7