Create a binary search tree from the following: 43, 5, 2, 54, 64, 23, 6, 48, 30 and write its preorder, inorder and postorder traversal. (Needs to be in C#)
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
using System;
/* Class containing left and
right child of current
node and key value*/
class Node
{
public int key;
public Node left, right;
public Node(int item)
{
key = item;
left = right = null;
}
}
class BinaryTree
{
// Root of Binary Tree
Node root;
BinaryTree()
{
root = null;
}
/* Given a binary tree, print
its nodes according to the
"bottom-up" postorder traversal. */
void printPostorder(Node node)
{
if (node == null)
return;
// first recur on left subtree
printPostorder(node.left);
// then recur on right subtree
printPostorder(node.right);
// now deal with the node
Console.Write(node.key + " ");
}
/* Given a binary tree, print
its nodes in inorder*/
void printInorder(Node node)
{
if (node == null)
return;
/* first recur on left child */
printInorder(node.left);
/* then print the data of node */
Console.Write(node.key + " ");
/* now recur on right child */
printInorder(node.right);
}
/* Given a binary tree, print
its nodes in preorder*/
void printPreorder(Node node)
{
if (node == null)
return;
/* first print data of node */
Console.Write(node.key + " ");
/* then recur on left sutree */
printPreorder(node.left);
/* now recur on right subtree */
printPreorder(node.right);
}
// Wrappers over above recursive functions
void printPostorder() {printPostorder(root);}
void printInorder() {printInorder(root);}
void printPreorder() {printPreorder(root);}
// Driver Code
static public void Main(String []args)
{
BinaryTree tree = new BinaryTree();
tree.root = new Node(43);
tree.root.left = new Node(5);
tree.root.right = new Node(54);
tree.root.left.left = new Node(2);
tree.root.right.right = new Node(64);
tree.root.right.left = new Node(23);
tree.root.left.right = new Node(6);
tree.root.right.right.left = new Node(48);
tree.root.left.right.right = new Node(30);
Console.WriteLine("Preorder traversal " +
"of binary tree is ");
tree.printPreorder();
Console.WriteLine("\nInorder traversal " +
"of binary tree is ");
tree.printInorder();
Console.WriteLine("\nPostorder traversal " +
"of binary tree is ");
tree.printPostorder();
}
}
Kindly revert for any queries
Thanks.
Create a binary search tree from the following: 43, 5, 2, 54, 64, 23, 6, 48,...
Create a binary search tree from the following: 43, 5, 2, 54, 64, 23, 6, 48, 30? (needs to be in C#)
a) Create a binary search tree with the 4 2 2 0 1 4 5 9 7 1 5 3 6 number. b) Provide the Preorder, Inorder and Postorder traversal of tree obtained in part (a). Show all the steps.
LANGUAGE: C++ Write a class to create the binary tree (insert, delete, search, exit) and display the output using inorder, preorder and postorder tree traversal methods.
Create a binary search tree with the following data (insert them in the order in which it is indicated data: 15, 3, 9, 2, 5, 38, 14, 96, 7, 26, 56, 76, 23 Once you finish with the insertions, return it to Inorder, Preorder and Postorder.
c++, data structures Given the following Binary Tree: tree 56 47 69 22 49 59 11 29 62 I 23 30 61 64 1. Show the order in which the nodes in the tree are processed by inorder traversal, postorder traversal, and preorder traversal. 2. Show how the tree would look like after deletion of 29, 59 and 47 3. Show how the original tree would look after the insertion of nodes containing 63, 77,76, 48, 9, and 10 (in...
Binary Search tree Implementation of a BST class that include the following operations: - Insertion, Search, Deletion - Traversals: Inorder, Preorder, Postorder using c++
Can someone help with these two problems? The following binary tree contains the characters 'A' through 'G' in its nodes. List the nodes in the order that they are visited by: A preorder traversal. An inorder traversal. A postorder traversal. The binary tree in Problem 2 is a Binary Search Tree since for every node, all elements stored in the left subtree of the node are smaller than the element in the node and all elements stored in the right...
in python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree You will also need to implement a Node class. This class will not be tested, but is needed to implement the BST. Your BST must implement the following methods. You are free to implement additional helper methods. It is recommended you create your own helper methods Constructor: Creates an Empty Tree String Method: Returns the string "Empty Tree" for an empty tree. Otherwise, returns...
Question 25 3 pts Add the following values (in the order provided) to a binary search tree and provide the values in the order you would get if you did an inorder traversal of the tree. Values: 6, 3, 7,4,9,1,0, 8, 5, 2 Question 26 3 pts Add the following values (in the order provided) to a binary search tree and provide the values in the order you would get if you did an postorder traversal of your tree. Values:...
A Binary Search Tree is a binary tree where nodes are ordered in the following way: each node contains one key (also known as data) the keys in the left subtree are less than the key in its parent node the keys in the right subtree are greater than the key in its parent node duplicate keys are not allowed Create a Binary Search Tree inserting the following list of numbers in order from left to right. 10, 6, 4, 8, 18, 15, 21 Please type...