SlideShare a Scribd company logo
1 of 5
Download to read offline
Given a newly created Binary Search Tree with the following numerical key input sequence
(from left to right): 9, 4, 12, 7, 5, 2, 20, 14, 11, 13, 19, 16, 17, 42, 24
a.) We are asked to add a function Position lowestKey(const Position& v) const to the class
SearchTree.
Function prototype: Position lowestKey(const Position& v);
input argument: position of the starting node in the binary search tree to calculate from. For the
whole tree this would be the position for the root of the tree.
return value: position of the node having the lowest key value.
i. Describe strategy with reasonings and examples to convince that it will work.
ii. Implement the function using C++ and show the source code listing.
b) We are also asked to add a function Position highestKey(const Position& v) const to the class
SearchTree.
Function prototype: Position highestKey(const Position& v) const;
input argument: position of the node in the binary search tree to calculate from. For the whole
tree this would be the position for the root of the tree.
return value: position of the node having the highest key value.
i. Describe strategy with reasonings and examples to convince that it will work.
ii. Implement the function using C++ and show the source code listing.
Solution
#include
#include
/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct node
{
int data;
struct node* left;
struct node* right;
};
/* Helper function that allocates a new node
with the given data and NULL left and right
pointers. */
struct node* newNode(int data)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;
return(node);
}
/* Give a binary search tree and a number,
inserts a new node with the given number in
the correct place in the tree. Returns the new
root pointer which the caller should then use
(the standard trick to avoid using reference
parameters). */
struct node* insert(struct node* node, int data)
{
/* 1. If the tree is empty, return a new,
single node */
if (node == NULL)
return(newNode(data));
else
{
/* 2. Otherwise, recur down the tree */
if (data <= node->data)
node->left = insert(node->left, data);
else
node->right = insert(node->right, data);
/* return the (unchanged) node pointer */
return node;
}
}
/* Given a non-empty binary search tree,
return the minimum data value found in that
tree. Note that the entire tree does not need
to be searched. */
int minValue(struct node* node) {
struct node* current = node;
/* loop down to find the leftmost leaf */
while (current->left != NULL) {
current = current->left;
}
return(current->data);
}
/* Driver program to test sameTree function*/
int main()
{
struct node* root = NULL;
root = insert(root, 4);
insert(root, 2);
insert(root, 1);
insert(root, 3);
insert(root, 6);
insert(root, 5);
printf(" Minimum value in BST is %d", minValue(root));
getchar();
return 0;
}
#include
#include
/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct node
{
int data;
struct node* left;
struct node* right;
};
/* Helper function that allocates a new node
with the given data and NULL left and right
pointers. */
struct node* newNode(int data)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;
return(node);
}
/* Give a binary search tree and a number,
inserts a new node with the given number in
the correct place in the tree. Returns the new
root pointer which the caller should then use
(the standard trick to avoid using reference
parameters). */
struct node* insert(struct node* node, int data)
{
/* 1. If the tree is empty, return a new,
single node */
if (node == NULL)
return(newNode(data));
else
{
/* 2. Otherwise, recur down the tree */
if (data <= node->data)
node->left = insert(node->left, data);
else
node->right = insert(node->right, data);
/* return the (unchanged) node pointer */
return node;
}
}
/* Given a non-empty binary search tree,
return the minimum data value found in that
tree. Note that the entire tree does not need
to be searched. */
int minValue(struct node* node) {
struct node* current = node;
/* loop down to find the leftmost leaf */
while (current->left != NULL) {
current = current->left;
}
return(current->data);
}
/* Driver program to test sameTree function*/
int main()
{
struct node* root = NULL;
root = insert(root, 4);
insert(root, 2);
insert(root, 1);
insert(root, 3);
insert(root, 6);
insert(root, 5);
printf(" Minimum value in BST is %d", minValue(root));
getchar();
return 0;
}

More Related Content

Similar to Given a newly created Binary Search Tree with the following numerica.pdf

Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfajayadinathcomputers
 
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxAssg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxfestockton
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
 
DS UNIT5_BINARY TREES.docx
DS UNIT5_BINARY TREES.docxDS UNIT5_BINARY TREES.docx
DS UNIT5_BINARY TREES.docxVeerannaKotagi1
 
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docxAssg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docxfestockton
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
Lecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptLecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptDrBashirMSaad
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.pptMuhammadShafi89
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdfWrite the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdffathimalinks
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfadityastores21
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
Required to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdframbagra74
 
BSTNode.Java Node class used for implementing the BST. .pdf
BSTNode.Java   Node class used for implementing the BST. .pdfBSTNode.Java   Node class used for implementing the BST. .pdf
BSTNode.Java Node class used for implementing the BST. .pdfinfo189835
 

Similar to Given a newly created Binary Search Tree with the following numerica.pdf (20)

Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxAssg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
DS UNIT5_BINARY TREES.docx
DS UNIT5_BINARY TREES.docxDS UNIT5_BINARY TREES.docx
DS UNIT5_BINARY TREES.docx
 
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docxAssg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Lecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptLecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.ppt
 
Linked list
Linked listLinked list
Linked list
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.ppt
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdfWrite the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Required to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docx
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
 
BSTNode.Java Node class used for implementing the BST. .pdf
BSTNode.Java   Node class used for implementing the BST. .pdfBSTNode.Java   Node class used for implementing the BST. .pdf
BSTNode.Java Node class used for implementing the BST. .pdf
 

More from hadpadrrajeshh

Gather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdfGather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdfhadpadrrajeshh
 
Determine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdfDetermine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdfhadpadrrajeshh
 
Describe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfDescribe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfhadpadrrajeshh
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfhadpadrrajeshh
 
A speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdfA speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdfhadpadrrajeshh
 
A recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdfA recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdfhadpadrrajeshh
 
choice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdfchoice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdfhadpadrrajeshh
 
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdfhadpadrrajeshh
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfhadpadrrajeshh
 
Where should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdfWhere should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdfhadpadrrajeshh
 
What is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdfWhat is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdfhadpadrrajeshh
 
What is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdfWhat is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdfhadpadrrajeshh
 
What is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdfWhat is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdfhadpadrrajeshh
 
What are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdfWhat are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdfhadpadrrajeshh
 
The “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdfThe “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdfhadpadrrajeshh
 
The three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdfThe three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdfhadpadrrajeshh
 
The project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdfThe project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdfhadpadrrajeshh
 
The positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdfThe positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdfhadpadrrajeshh
 
The local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdfThe local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdfhadpadrrajeshh
 
how are musical sounds produced Explain your reasoning.Solution.pdf
how are musical sounds produced Explain your reasoning.Solution.pdfhow are musical sounds produced Explain your reasoning.Solution.pdf
how are musical sounds produced Explain your reasoning.Solution.pdfhadpadrrajeshh
 

More from hadpadrrajeshh (20)

Gather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdfGather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdf
 
Determine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdfDetermine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdf
 
Describe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfDescribe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdf
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
A speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdfA speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdf
 
A recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdfA recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdf
 
choice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdfchoice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdf
 
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdf
 
Where should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdfWhere should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdf
 
What is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdfWhat is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdf
 
What is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdfWhat is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdf
 
What is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdfWhat is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdf
 
What are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdfWhat are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdf
 
The “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdfThe “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdf
 
The three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdfThe three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdf
 
The project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdfThe project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdf
 
The positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdfThe positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdf
 
The local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdfThe local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdf
 
how are musical sounds produced Explain your reasoning.Solution.pdf
how are musical sounds produced Explain your reasoning.Solution.pdfhow are musical sounds produced Explain your reasoning.Solution.pdf
how are musical sounds produced Explain your reasoning.Solution.pdf
 

Recently uploaded

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
 
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
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
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
 
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
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 

Recently uploaded (20)

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
 
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
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
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...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 

Given a newly created Binary Search Tree with the following numerica.pdf

  • 1. Given a newly created Binary Search Tree with the following numerical key input sequence (from left to right): 9, 4, 12, 7, 5, 2, 20, 14, 11, 13, 19, 16, 17, 42, 24 a.) We are asked to add a function Position lowestKey(const Position& v) const to the class SearchTree. Function prototype: Position lowestKey(const Position& v); input argument: position of the starting node in the binary search tree to calculate from. For the whole tree this would be the position for the root of the tree. return value: position of the node having the lowest key value. i. Describe strategy with reasonings and examples to convince that it will work. ii. Implement the function using C++ and show the source code listing. b) We are also asked to add a function Position highestKey(const Position& v) const to the class SearchTree. Function prototype: Position highestKey(const Position& v) const; input argument: position of the node in the binary search tree to calculate from. For the whole tree this would be the position for the root of the tree. return value: position of the node having the highest key value. i. Describe strategy with reasonings and examples to convince that it will work. ii. Implement the function using C++ and show the source code listing. Solution #include #include /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; /* Helper function that allocates a new node with the given data and NULL left and right pointers. */ struct node* newNode(int data)
  • 2. { struct node* node = (struct node*) malloc(sizeof(struct node)); node->data = data; node->left = NULL; node->right = NULL; return(node); } /* Give a binary search tree and a number, inserts a new node with the given number in the correct place in the tree. Returns the new root pointer which the caller should then use (the standard trick to avoid using reference parameters). */ struct node* insert(struct node* node, int data) { /* 1. If the tree is empty, return a new, single node */ if (node == NULL) return(newNode(data)); else { /* 2. Otherwise, recur down the tree */ if (data <= node->data) node->left = insert(node->left, data); else node->right = insert(node->right, data); /* return the (unchanged) node pointer */ return node; } } /* Given a non-empty binary search tree, return the minimum data value found in that tree. Note that the entire tree does not need
  • 3. to be searched. */ int minValue(struct node* node) { struct node* current = node; /* loop down to find the leftmost leaf */ while (current->left != NULL) { current = current->left; } return(current->data); } /* Driver program to test sameTree function*/ int main() { struct node* root = NULL; root = insert(root, 4); insert(root, 2); insert(root, 1); insert(root, 3); insert(root, 6); insert(root, 5); printf(" Minimum value in BST is %d", minValue(root)); getchar(); return 0; } #include #include /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; /* Helper function that allocates a new node with the given data and NULL left and right pointers. */
  • 4. struct node* newNode(int data) { struct node* node = (struct node*) malloc(sizeof(struct node)); node->data = data; node->left = NULL; node->right = NULL; return(node); } /* Give a binary search tree and a number, inserts a new node with the given number in the correct place in the tree. Returns the new root pointer which the caller should then use (the standard trick to avoid using reference parameters). */ struct node* insert(struct node* node, int data) { /* 1. If the tree is empty, return a new, single node */ if (node == NULL) return(newNode(data)); else { /* 2. Otherwise, recur down the tree */ if (data <= node->data) node->left = insert(node->left, data); else node->right = insert(node->right, data); /* return the (unchanged) node pointer */ return node; } } /* Given a non-empty binary search tree, return the minimum data value found in that
  • 5. tree. Note that the entire tree does not need to be searched. */ int minValue(struct node* node) { struct node* current = node; /* loop down to find the leftmost leaf */ while (current->left != NULL) { current = current->left; } return(current->data); } /* Driver program to test sameTree function*/ int main() { struct node* root = NULL; root = insert(root, 4); insert(root, 2); insert(root, 1); insert(root, 3); insert(root, 6); insert(root, 5); printf(" Minimum value in BST is %d", minValue(root)); getchar(); return 0; }