You are on page 1of 2

SCS 1201

Data Structures and Algorithms

Tutorial 03

1. Write a pseudo code algorithm to Implement a Stack using Queue(s)


• Describe how the pseudo code algorithm works. You may use suitable diagram(s)
to answer the question
• Convert the above pseudo-code into c code.
• Prove the validity of your program using test data and test results

2. Describe how the following set of operations work on the code written by you above. You
may use a suitable diagram to illustrate the answer.

1. Push(‘a’)
2. Push(‘b’)
3. Push(‘c’)
4. Pop
5. Push(‘d’)
6. Pop
7. Pop
8. Pop
9. Push(‘e’)

3. Write a pseudo code algorithm to reverse a set of numbers stored in a queue(s).


Note: You may use a stack as an intermediate container.

• Convert the above pseudo code algorithm into a C program


• Using the above C program written by you, generate the following outputs using
the given inputs.

Input: Q = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Output: Q = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
Input: [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
4. Given an efficient circular array-based queue (Q) capable of holding 10 objects. Show the

final contents of the Q after the following code segment is executed:


Int k
for (k = 1; k ≤ 7; k++)
{
Q.enqueue(k);
}
for ( k = 1; k ≤ 7; k++)
{
Q.enqueue(Q.dequeue());
}

5. Consider the following Pseudo Algorithm.

Begin
Initialize Stacks S1 and S2
Push all inputs into Stack S1

Procedure P () {
While (! s1.isempty ())
Push S2 (Pop S1 ())
}
While (! s2.isempty ())
Print (pop S2 ())
End

a. What is the pseudo code above intended to do?


b. If the following values were inserted into the above pseudo code, what would be
the final output? Values are: 34, 12,18,23,55,11,9

6. Write a pseudo code algorithm and c program to generate binary numbers between 0 to
n using a queue

7. Write an algorithm to insert an element into a queue?

8. What are the two problems associated with the linear queue?
9. Write an algorithm to delete an element from a circular queue.

10. Write a pseudo code algorithm to Implement a Queue using two Stacks.

You might also like