Why we need to use circular implementation in queues?

Create a Java program that adds the numbers 1 through 50 to a stack called stack1.Then perform the following:

Finds all the odd numbers from stack1.Then, push them into a new stack named stack 2.

Find and print the prime numbers from stack2.

[Note: Provide a screenshot of your code output].

 

Question two

Consider the following initial state of a queue implemented using a circular array. Where F for “front” and B for “back” are shown on the queue.

 

              101 102  
              F B  

Answer the following:

Why we need to use circular implementation in queues?

How circular implementation works in queues?

Show the queue state after each of the following operations with updating F & B as needed:

enqueue(103)

                   
                   

enqueue(104)

                   
                   

dequeue

                   
                   

 

enqueue(105)

                   
                   

 

Question Three

Write the pre-order, in-order and post-order traversals of the following binary search tree:

Question Two

Draw the binary search tree if the pre-order traversals of that binary search tree is given as below:

Pre-order traversal: 7, 4, 2, 3, 6, 5, 12, 9, 8, 11, 19, 15, 20