The document describes two algorithms:
1. A preorder traversal algorithm that takes a binary tree root node as input and returns the preorder file format string of the tree. It uses recursion to traverse the left and right child nodes.
2. An algorithm that takes a preorder string as input and constructs the corresponding binary tree. It uses recursion and a Node class to build the tree from the preorder traversal order. Both algorithms use recursion and traversal techniques for binary trees.
The document describes two algorithms:
1. A preorder traversal algorithm that takes a binary tree root node as input and returns the preorder file format string of the tree. It uses recursion to traverse the left and right child nodes.
2. An algorithm that takes a preorder string as input and constructs the corresponding binary tree. It uses recursion and a Node class to build the tree from the preorder traversal order. Both algorithms use recursion and traversal techniques for binary trees.
The document describes two algorithms:
1. A preorder traversal algorithm that takes a binary tree root node as input and returns the preorder file format string of the tree. It uses recursion to traverse the left and right child nodes.
2. An algorithm that takes a preorder string as input and constructs the corresponding binary tree. It uses recursion and a Node class to build the tree from the preorder traversal order. Both algorithms use recursion and traversal techniques for binary trees.
BSE 3B Enroll: 02-131212-078 a) Design an algorithm which gives the preorder file format of a binary tree given a pointer to the root of a binary tree. Consider the binary tree has nodes with fields "data", "left_child", and "right_child". { Step 1: Start. Step 2: Declare a String variable Data. Step 3: Create a method PreOrder(node pointer). Step 4: Call method PreOrder(node pointer). Step 5: If pointer.Data is equal to null then store “.” In Data, Else if pointer.Data in not equal to null then store pointer.Data in Data. Step 6: Call method PreOrder(pointer.Left_Child) using recursion. Step 7: Call method PreOrder(pointer.Right_Child) using recursion. Step 8: End. }
b) Design an algorithm which takes a preorder file format of a binary
tree and produces the binary tree. Use recursive approach. { STEP 1: Start. STEP 2: Create a Node class that has a variable data. STEP 3: Create Node left, right and initialize them with null. STEP 4: Create a BinaryTree class and create a Node root an/d initialize with null. STEP 5: Create a function printPreorder(Node node). STEP 6: IF node = null THEN print “.” and return. STEP 7: Print the data containing in the node. STEP 8: Call function printPreorder(node.left) using recursion. STEP 9: Call function printPreorder(node.right) using recursion. STEP 10: Create a function printPreorder() and has printPreorder(root) in the body. STEP 11: End. }