B+ Tree Design

Introduction

B+Tree consists of root it may have n number of child nodes. Each child may have its child nodes.
If a node doesn’t have any child then we can consider that is the leaf.

  1. In B+Tree every node has one parent node (if it’s not a root node)
  2. Each Node may have n number of child nodes(if it’s not a leaf node)
  3. Each node has its properties

Use Case:

Take any corporate IT organization which has n number of employees,
each employee has its properties like id, name, salary, reporting id and reported persons We can assume sample employee data in DB

EMPID NAME DESIGNATION SALARY REPORTING_ID
1 SUBBU C.E.O 200000 NULL
2 RANGA MANAGER 200000 1
3 KIRAN MANAGER 333333 1
4 RAJU TEAM LEAD 2222222
5 MOHAN TEAM LEAD 11111112
6 CHANDRA TEAM LEAD 000000 2
7 KANTH DEVELOPER 7777777 4
8 MANI DEVELOPER 88888888 4
9 HARI DEVELOPER 66666666 5

We have to make it above raw data to B+ tree using java

when we run this application root node will have all employees info so it will display JSON data like the below

{
     "id": 1,
     "empName": "SUBBU",
     "salary": 200000,
     "designation": "C.E.O",
     "reportedEmployees": [
         {
             "id": 2,
             "empName": "RANGA",
             "salary": 200000,
             "designation": "MANAGER",
             "reportedEmployees": [
                 {
                     "id": 4,
                     "empName": "RAJU",
                     "salary": 222222,
                     "designation": "TEAM LEAD",
                     "reportedEmployees": [
                         {
                             "id": 7,
                             "empName": "KANTH",
                             "salary": 7777777,
                             "designation": "DEVELOPER"
                         },
                         {
                             "id": 8,
                             "empName": "MANI",
                             "salary": 88888888,
                             "designation": "DEVELOPER"
                         }
                     ]
                 },
                 {
                     "id": 5,
                     "empName": "MOHAN",
                     "salary": 1111111,
                     "designation": "TEAM LEAD",
                     "reportedEmployees": [
                         {
                             "id": 9,
                             "empName": "HARI",
                             "salary": 66666666,
                             "designation": "DEVELOPER"
                         }
                     ]
                 },
                 {
                     "id": 6,
                     "empName": "KANTH",
                     "salary": 11111111,
                     "designation": "DEVELOPER"
                 }
             ]
         },
         {
             "id": 3,
             "empName": "KIRAN",
             "salary": 333333,
             "designation": "MANAGER"
         }
     ]
 }

4 thoughts on “B+ Tree Design

Leave a reply to Raghu Cancel reply