# Question 1: Non-recursive In-order traverse of a binary tree Using Stack is the obvious way to traverse tree without recursion. Below is an algorithm for traversing binary tree using stack. See this for step wise step execution of the algorithm. Let us consider the below tree for example Write a non-recursive application for the in-order traverse for a binary tree. Question 2: Level order traverse of a binary tree (breadth first traversal) Level order traversal of the above tree is 1 2 3 4 5. We can use a FIFO queue to implement the level order tranversal of a binary tree. For each node, first the node is visited and then it’s child nodes are put in a FIFO queue. Notes: For both question, you can use the Binary Tree class and the Node class defined in the book, you can also define your own Node class and Binary Tree class. Requirements: Submit the repl.it links of the two programs Please note that you need to submit two repl.it links. You can copy and paste the two links in a .txt/.docx file and upload the file. You can also submit the second link as comments in the assignment submission.

In order to fulfill the requirements of this assignment, two programs need to be submitted: one for a non-recursive in-order traversal of a binary tree using a stack, and another for a level order traversal of a binary tree using a FIFO queue. To accomplish this, we can make use of the Binary Tree class and Node class provided in the book or create our own versions of these classes.

For the first program, the non-recursive in-order traversal using a stack, we can employ the following algorithm:

1. Create an empty stack.

2. Initialize a current node as the root of the binary tree.

3. Repeat steps 4 to 6 until the stack becomes empty or the current node becomes null.

4. If the current node exists, push it onto the stack and move to its left child.

5. If the current node is null, but the stack is not empty, pop the top of the stack, print its value, and set the current node to its right child.

6. Go to step 4.

7. End.

By implementing this algorithm, we will be able to traverse the binary tree in non-recursive in-order fashion using a stack. Here is an example of a binary tree:

1

/

2 3

/

4 5

To demonstrate the implementation of the algorithm, let’s suppose this tree is represented by the Binary Tree class provided in the book. The resulting program would be:

// import the necessary classes

public class Main {

public static void main(String[] args) {

BinaryTree tree = new BinaryTree();

// construct the binary tree using the provided Node class or custom Node class

tree.nonRecursiveInOrderTraversal();

}

}

class BinaryTree {

// define the class variables and methods

public void nonRecursiveInOrderTraversal() {

// implement the algorithm for non-recursive in-order traversal using a stack

}

}

class Node {

// define the class variables and methods

}

By completing and running this program, we will obtain the desired non-recursive in-order traversal of the binary tree using a stack.

For the second program, the level order traversal using a FIFO queue, we can follow this algorithm:

1. Create an empty queue.

2. Initialize a current node as the root of the binary tree.

3. Repeat steps 4 to 5 until the queue becomes empty or the current node becomes null.

4. If the current node exists, enqueue it into the queue and print its value.

5. If the current node is not null, dequeue a node from the queue, set the current node to it, and go to step 4.

6. End.

Again, let’s assume that the binary tree is represented by the Binary Tree class and Node class provided in the book. The resulting program would be similar to the previous one, with the main method and BinaryTree class modified accordingly to perform the level order traversal using a FIFO queue.

By creating this second program and running it, the desired level order traversal of the binary tree using a FIFO queue will be obtained.

Both programs can be submitted as repl.it links, which can be generated by copying the source code of each program, pasting it into the repl.it online IDE, and sharing the provided link.

### Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.

Click Here to Make an Order Click Here to Hire a Writer