Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class for implementing a simple binary search tree capable of storing nu

ID: 3569795 • Letter: W

Question

Write a class for implementing a simple binary search tree capable of storing numbers. The

class should have member functions

void insert(double x)

bool search(double x)

void inorder(vector & v )

The insert function should not use recursion directly, or indirectly by calling a recursive

function. The search function should work by calling a private recursive member function

bool search(double x, BtreeNode *t)

The inorder function is passed an initially empty vector v: it ?lls v with the inorder list of

numbers stored in the binary search tree. Demonstrate the operation of the class using a

suitable driver program.

Design and implement the following member functions for the binary search tree you created in Part 1 or the IntBinaryTree class.

Tree Size

Modify the binary search tree created in the previous programming challenge to add a

member function that returns the number of items (nodes) stored in the tree.

int size()

Leaf Counter

Modify the binary search tree to add a member function that counts and returns the number of leaf nodes in the tree.

int leafCount()

Tree Height

Modify the binary search tree by adding a member function that computes and returns the height of the tree. The height of the tree is the number of levels it contains.

int height()

Tree Width (Optional)

Modify the binary search tree created in the preceding programming challenges by adding

a member function that computes the width of the tree.

int width()

The width of a tree is the largest number of nodes at the same level.

Tree Copy Constructor (Optional)

Design and implement a copy constructor for the binary search tree.

Example Output:

Enter 5 numbers:

?5

?8

?3

?12

?9

Here is a sorted list of what you entered:

3 5 8 9 12

Enter a value to add to the new tree:

7

Here is a traversal of the new tree:

3 5 7 8 9 12

Here is a traversal of the old tree:

3 5 8 9 12

Press any key to continue . . .

Explanation / Answer

A=0;
x=0;
n=input('How many variables=');
disp('Enter the coefficients along with constants For instance if x+y+3z=-5 then enter 1 1 3 -5 each number followed by an enter not space');
for i=1:n
   for j=1:n+1
       A(i,j)=input('');
   end
end
%pivoting
for i=1:n-1
   for j=i+1:n
       if abs(A(j,i))>abs(A(i,i))
           T=A(j,:);
           A(j,:)=A(i,:);
           A(i,:)=T;
       end
   end
end
disp('After pivoting');
disp(A);
for k=1:n-1
   for i=k+1:n
       m=A(i,k)/A(k,k);
       for j=k:n+1
           A(i,j)=A(i,j)-m*A(k,j);
       end
   end
end
disp('Triangularize Form ');
disp(A);
           
if A(n,n)==0
   disp('No unique solution');
end
   x(n)=A(n,n+1)/A(n,n);
   for j=n-1:-1:1
       sum=0;
   for i=1:n
       sprintf('x%.0f=%.10f',i,x(i))
   end
       

       for i=1:n-j
           sum=sum+A(j,n+1-i)*x(n+1-i);
       end
       x(j)=(A(j,n+1)-sum)/A(j,j);
   end   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote