B+ tree design
Hi friends, Today we can discuss about B+ tree design for this we can take one use case
If we take any corporate IT organization it has n number of employees
Each employee has its own properties like employee id, name, salary, reporting person
Each employee can reporting a person called reporting manager.
if an employee designation is C.E.O then he may not have reporting person.
If an employee is a manager then he need to monitor n number of employees under him.
The above data is called as herarchical data. we can represent herarchical data using b+ tree.
B+ Tree Introduction:
B+ Tree consist of root it may have n number of children’s. Each child may have its own children node
If a node doesn’t have any child is called as leaf node.
In B+ Tree every node has one parent node (if its not a root node)
Each tree has n number of child nodes(if its not a leaf node)
Each node has its own properties so we can say above design is B+ tree design
We can assume data for the above case
| EMP_ID | NAME | DESIGNATION | SALARY | REPORTING_PERSON |
| 1 | SUBBU | C.E.O | 200000 | NULL |
| 2 | RANGA | MANAGER | 200000 | SUBBU |
| 3 | KIRAN | MANAGER | 133333 | SUBBU |
| 4 | RAJU | TEAM LEAD | 122222 | RANGA |
| 5 | MOHAN | TEAM LEAD | 1111111 | RANGA |
| 6 | CHANDRA | TEAM LEAD | 100000 | RANGA |
| 7 | KANTH | DEVELOPER | 77777 | RAJU |
| 8 | MANI | DEVELOPER | 88888 | RAJU |
| 9 | HARI | DEVELOPER | 66666 | MOHAN |
If we want to represent above data using java then we can design a class which is similler to B+ tree design
package com.ranga.config; import java.util.ArrayList; import java.util.List; public class Employee { private String employeeId; private String empName; private Double salary; private String reportingPersonName; private List reportedEmployees = new ArrayList<>(); public String getEmployeeId() { return employeeId; } public void setEmployeeId(String employeeId) { this.employeeId = employeeId; } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName = empName; } public Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } public String getReportingPersonName() { return reportingPersonName; } public void setReportingPersonName(String reportingPersonName) { this.reportingPersonName = reportingPersonName; } public List<Employee> getReportedEmployees() { return reportedEmployees; } public void setReportedEmployees(List<Employee> reportedEmployees) { this.reportedEmployees = reportedEmployees; } }
package com.ranga.config; import java.util.Arrays; public class Main { public static void main(String[] args) { //HARI Employee hari=new Employee(); hari.setId(9); hari.setEmpName("HARI"); hari.setDesignation("DEVELOPER"); hari.setSalary(66666666.0); // MANI DEVELOPER 88888888 RAJU Employee mani=new Employee(); mani.setId(8); mani.setEmpName("MANI"); mani.setDesignation("DEVELOPER"); mani.setSalary(88888888.0); //7 KANTH DEVELOPER 7777777 RAJU Employee kanth=new Employee(); kanth.setId(7); kanth.setEmpName("KANTH"); kanth.setDesignation("DEVELOPER"); kanth.setSalary(7777777.0); // 6 CHANDRA TEAM LEAD 000000 RANGA Employee chandra=new Employee(); chandra.setId(6); chandra.setEmpName("KANTH"); chandra.setDesignation("DEVELOPER"); chandra.setSalary(11111111.0); // 5 MOHAN TEAM LEAD 1111111 RANGA Employee mohan=new Employee(); mohan.setId(5); mohan.setEmpName("MOHAN"); mohan.setDesignation("TEAM LEAD"); mohan.setSalary(1111111.0); mohan.setReportedEmployees(Arrays.asList(hari)); // 4 RAJU TEAM LEAD 222222 RANGA Employee raju=new Employee(); raju.setId(4); raju.setEmpName("RAJU"); raju.setDesignation("TEAM LEAD"); raju.setSalary(222222.0); raju.setReportedEmployees(Arrays.asList(kanth,mani)); //3 KIRAN MANAGER 333333 SUBBU Employee kiran=new Employee(); kiran.setId(4); kiran.setEmpName("KIRAN"); kiran.setDesignation("MANAGER"); kiran.setSalary(333333.0); // 2 RANGA MANAGER 200000 SUBBU Employee ranga =new Employee(); ranga.setEmpName("RANGA"); ranga.setDesignation("MANAGER"); ranga.setSalary(200000.0); ranga.setReportedEmployees(Arrays.asList(raju,mohan,chandra)); // 1 SUBBU C.E.O 200000 NULL Employee subbu =new Employee(); subbu.setEmpName("SUBBU"); subbu.setDesignation("C.E.O"); subbu.setSalary(200000.0); subbu.setReportedEmployees(Arrays.asList(ranga,kiran)); } }

