SlideShare a Scribd company logo
1 of 6
Download to read offline
B-tree insertion (Draw node) Show the results of inserting the keys 23, 98, 55, 37, 30, 47, 35,
15, 10, 75, 3, 53, 1, 33, 5, 28, 25, 90, 95, 56, 8, and 9 in order into an empty B-tree of order 5.
That is, each internal node in this B-tree other than the root must have at least 3 and at most 5
children (or at least 2 and at most 4 keys).
Solution
/*
* C++ Program to Implement B-Tree
*/
#include
#include
#include
using namespace std;
struct BTreeNode
{
int *data;
BTreeNode **child_ptr;
bool leaf;
int n;
}*root = NULL, *np = NULL, *x = NULL;
BTreeNode * init()
{
int i;
np = new BTreeNode;
np->data = new int[5];
np->child_ptr = new BTreeNode *[6];
np->leaf = true;
np->n = 0;
for (i = 0; i < 6; i++)
{
np->child_ptr[i] = NULL;
}
return np;
}
void traverse(BTreeNode *p)
{
cout<n; i++)
{
if (p->leaf == false)
{
traverse(p->child_ptr[i]);
}
cout << " " << p->data[i];
}
if (p->leaf == false)
{
traverse(p->child_ptr[i]);
}
cout< p[j])
{
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
}
int split_child(BTreeNode *x, int i)
{
int j, mid;
BTreeNode *np1, *np3, *y;
np3 = init();
np3->leaf = true;
if (i == -1)
{
mid = x->data[2];
x->data[2] = 0;
x->n--;
np1 = init();
np1->leaf = false;
x->leaf = true;
for (j = 3; j < 5; j++)
{
np3->data[j - 3] = x->data[j];
np3->child_ptr[j - 3] = x->child_ptr[j];
np3->n++;
x->data[j] = 0;
x->n--;
}
for (j = 0; j < 6; j++)
{
x->child_ptr[j] = NULL;
}
np1->data[0] = mid;
np1->child_ptr[np1->n] = x;
np1->child_ptr[np1->n + 1] = np3;
np1->n++;
root = np1;
}
else
{
y = x->child_ptr[i];
mid = y->data[2];
y->data[2] = 0;
y->n--;
for (j = 3; j < 5; j++)
{
np3->data[j - 3] = y->data[j];
np3->n++;
y->data[j] = 0;
y->n--;
}
x->child_ptr[i + 1] = y;
x->child_ptr[i + 1] = np3;
}
return mid;
}
void insert(int a)
{
int i, temp;
x = root;
if (x == NULL)
{
root = init();
x = root;
}
else
{
if (x->leaf == true && x->n == 5)
{
temp = split_child(x, -1);
x = root;
for (i = 0; i < (x->n); i++)
{
if ((a > x->data[i]) && (a < x->data[i + 1]))
{
i++;
break;
}
else if (a < x->data[0])
{
break;
}
else
{
continue;
}
}
x = x->child_ptr[i];
}
else
{
while (x->leaf == false)
{
for (i = 0; i < (x->n); i++)
{
if ((a > x->data[i]) && (a < x->data[i + 1]))
{
i++;
break;
}
else if (a < x->data[0])
{
break;
}
else
{
continue;
}
}
if ((x->child_ptr[i])->n == 5)
{
temp = split_child(x, i);
x->data[x->n] = temp;
x->n++;
continue;
}
else
{
x = x->child_ptr[i];
}
}
}
}
x->data[x->n] = a;
sort(x->data, x->n);
x->n++;
}
int main()
{
int i, n, t;
cout<<"enter the no of elements to be inserted ";
cin>>n;
for(i = 0; i < n; i++)
{
cout<<"enter the element ";
cin>>t;
insert(t);
}
cout<<"traversal of constructed tree ";
traverse(root);
getch();
}

More Related Content

Similar to B-tree insertion (Draw node) Show the results of inserting the keys .pdf

Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptxSanthiya S
 
Singly linked list program in data structure - Vtech
Singly linked list program in data structure - VtechSingly linked list program in data structure - Vtech
Singly linked list program in data structure - VtechVtech Academy of Computers
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」Ken'ichi Matsui
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxarjurakibulhasanrrr7
 
Binary search tree.pptx
Binary search tree.pptxBinary search tree.pptx
Binary search tree.pptxSanthiya S
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracingSamsil Arefin
 
Struktur data (alokasi memory)
Struktur data (alokasi memory)Struktur data (alokasi memory)
Struktur data (alokasi memory)Abbedul Thembock
 
Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.university of Gujrat, pakistan
 
Please help fill in the missing code below in order for it run correct.docx
Please help fill in the missing code below in order for it run correct.docxPlease help fill in the missing code below in order for it run correct.docx
Please help fill in the missing code below in order for it run correct.docxmadalynbb3ja
 

Similar to B-tree insertion (Draw node) Show the results of inserting the keys .pdf (20)

Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
C arrays
C arraysC arrays
C arrays
 
Singly linked list program in data structure - Vtech
Singly linked list program in data structure - VtechSingly linked list program in data structure - Vtech
Singly linked list program in data structure - Vtech
 
Chapter5.pptx
Chapter5.pptxChapter5.pptx
Chapter5.pptx
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Array
ArrayArray
Array
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
C programs
C programsC programs
C programs
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
Binary search tree.pptx
Binary search tree.pptxBinary search tree.pptx
Binary search tree.pptx
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 
Struktur data (alokasi memory)
Struktur data (alokasi memory)Struktur data (alokasi memory)
Struktur data (alokasi memory)
 
Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.
 
Arrays
ArraysArrays
Arrays
 
Please help fill in the missing code below in order for it run correct.docx
Please help fill in the missing code below in order for it run correct.docxPlease help fill in the missing code below in order for it run correct.docx
Please help fill in the missing code below in order for it run correct.docx
 
Exp3
Exp3Exp3
Exp3
 

More from mayorothenguyenhob69

If the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdfIf the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdfmayorothenguyenhob69
 
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdfHow would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdfmayorothenguyenhob69
 
How could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdfHow could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdfmayorothenguyenhob69
 
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdfHow Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdfmayorothenguyenhob69
 
Far from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdfFar from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdfmayorothenguyenhob69
 
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdfE1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdfmayorothenguyenhob69
 
Do differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdfDo differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdfmayorothenguyenhob69
 
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdfDefine the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdfmayorothenguyenhob69
 
Describe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdfDescribe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdfmayorothenguyenhob69
 
Compare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdfCompare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdfmayorothenguyenhob69
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
 
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdfmayorothenguyenhob69
 
Which methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdfWhich methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdfmayorothenguyenhob69
 
Which of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdfWhich of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdfmayorothenguyenhob69
 
What are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdfWhat are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdfmayorothenguyenhob69
 
What are some differences between the xylem and the phloem Solu.pdf
What are some differences between the xylem and the phloem  Solu.pdfWhat are some differences between the xylem and the phloem  Solu.pdf
What are some differences between the xylem and the phloem Solu.pdfmayorothenguyenhob69
 
Two families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdfTwo families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdfmayorothenguyenhob69
 
Two populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdfTwo populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdfmayorothenguyenhob69
 
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdfmayorothenguyenhob69
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 

More from mayorothenguyenhob69 (20)

If the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdfIf the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdf
 
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdfHow would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
 
How could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdfHow could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdf
 
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdfHow Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
 
Far from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdfFar from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdf
 
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdfE1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
 
Do differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdfDo differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdf
 
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdfDefine the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
 
Describe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdfDescribe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdf
 
Compare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdfCompare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdf
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
 
Which methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdfWhich methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdf
 
Which of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdfWhich of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdf
 
What are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdfWhat are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdf
 
What are some differences between the xylem and the phloem Solu.pdf
What are some differences between the xylem and the phloem  Solu.pdfWhat are some differences between the xylem and the phloem  Solu.pdf
What are some differences between the xylem and the phloem Solu.pdf
 
Two families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdfTwo families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdf
 
Two populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdfTwo populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdf
 
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 

Recently uploaded

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

B-tree insertion (Draw node) Show the results of inserting the keys .pdf

  • 1. B-tree insertion (Draw node) Show the results of inserting the keys 23, 98, 55, 37, 30, 47, 35, 15, 10, 75, 3, 53, 1, 33, 5, 28, 25, 90, 95, 56, 8, and 9 in order into an empty B-tree of order 5. That is, each internal node in this B-tree other than the root must have at least 3 and at most 5 children (or at least 2 and at most 4 keys). Solution /* * C++ Program to Implement B-Tree */ #include #include #include using namespace std; struct BTreeNode { int *data; BTreeNode **child_ptr; bool leaf; int n; }*root = NULL, *np = NULL, *x = NULL; BTreeNode * init() { int i; np = new BTreeNode; np->data = new int[5]; np->child_ptr = new BTreeNode *[6]; np->leaf = true; np->n = 0; for (i = 0; i < 6; i++) { np->child_ptr[i] = NULL; } return np; }
  • 2. void traverse(BTreeNode *p) { cout<n; i++) { if (p->leaf == false) { traverse(p->child_ptr[i]); } cout << " " << p->data[i]; } if (p->leaf == false) { traverse(p->child_ptr[i]); } cout< p[j]) { temp = p[i]; p[i] = p[j]; p[j] = temp; } } } } int split_child(BTreeNode *x, int i) { int j, mid; BTreeNode *np1, *np3, *y; np3 = init(); np3->leaf = true; if (i == -1) { mid = x->data[2]; x->data[2] = 0; x->n--; np1 = init(); np1->leaf = false;
  • 3. x->leaf = true; for (j = 3; j < 5; j++) { np3->data[j - 3] = x->data[j]; np3->child_ptr[j - 3] = x->child_ptr[j]; np3->n++; x->data[j] = 0; x->n--; } for (j = 0; j < 6; j++) { x->child_ptr[j] = NULL; } np1->data[0] = mid; np1->child_ptr[np1->n] = x; np1->child_ptr[np1->n + 1] = np3; np1->n++; root = np1; } else { y = x->child_ptr[i]; mid = y->data[2]; y->data[2] = 0; y->n--; for (j = 3; j < 5; j++) { np3->data[j - 3] = y->data[j]; np3->n++; y->data[j] = 0; y->n--; } x->child_ptr[i + 1] = y; x->child_ptr[i + 1] = np3; } return mid;
  • 4. } void insert(int a) { int i, temp; x = root; if (x == NULL) { root = init(); x = root; } else { if (x->leaf == true && x->n == 5) { temp = split_child(x, -1); x = root; for (i = 0; i < (x->n); i++) { if ((a > x->data[i]) && (a < x->data[i + 1])) { i++; break; } else if (a < x->data[0]) { break; } else { continue; } } x = x->child_ptr[i]; } else {
  • 5. while (x->leaf == false) { for (i = 0; i < (x->n); i++) { if ((a > x->data[i]) && (a < x->data[i + 1])) { i++; break; } else if (a < x->data[0]) { break; } else { continue; } } if ((x->child_ptr[i])->n == 5) { temp = split_child(x, i); x->data[x->n] = temp; x->n++; continue; } else { x = x->child_ptr[i]; } } } } x->data[x->n] = a; sort(x->data, x->n); x->n++; }
  • 6. int main() { int i, n, t; cout<<"enter the no of elements to be inserted "; cin>>n; for(i = 0; i < n; i++) { cout<<"enter the element "; cin>>t; insert(t); } cout<<"traversal of constructed tree "; traverse(root); getch(); }