0% found this document useful (0 votes)
45 views3 pages

Sheet1,2 Stack Queue

The document discusses data structures and algorithms. It covers topics like stacks, queues, and their applications. It provides examples and problems related to implementing operations on stacks and queues using arrays and linked lists.

Uploaded by

demro channel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

Sheet1,2 Stack Queue

The document discusses data structures and algorithms. It covers topics like stacks, queues, and their applications. It provides examples and problems related to implementing operations on stacks and queues using arrays and linked lists.

Uploaded by

demro channel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Benha University Electrical Engineering Department

Benha Faculty of Engineering Data Structures and Algorithms


(E1324)

Sheet (1,2) Stack and Queue


1- What is Data Structure? Explain.
2- Describe the types of Data Structures?
3- What are the scenarios in which an element can be inserted into the circular queue?
4- Consider the undo and redo operations or forward and back operations on a
browser. While it is likely more obvious that operations to undo or pages to go back
to may be stored using a stack, what is the behaviour of the redo or page forward
operations? How is it related to being a stack? Are there times at which the redo

Figure 1. The undo/redo buttons of an editing application and the back/forward


buttons of a web browser.
5- Given the following C++ fragment, what is the state of the stack (recording the
opening delimiters—(, [, {, <—that have not yet been matched) at the end of this
fragment?

1
6- Evaluate the following expressions:
123+*45*6++
123+*45*+6+
12+3*45*6++
7- Trace the following code. (You may refer to the header file of the queue
implementation.) User input is the following sequence of numbers: 4 5 67 89 21 3 0
76.
int main(){
Queue q;
int i;
cin>> i;
while (i != 0)
{ if (i < 35)
q.enQueue(i);
cin>>i; }
while (!q.isEmpty())
{ q.deQueue();
cout<<i<<endl;}}

8- Given the following queue (array implementation), containing the numbers 4, 3,


6, 8 and 9.

i) What are the values of front and rear?


ii) Given this queue, suppose we call Dequeue twice and Enqueue once. What would
be the new values of front and rear?
iii) How many elements can this queue hold?
9- Consider the following sequence of stack operations: push(d), push(h), pop(),
push(f), push(s), pop(), pop(), push(m).
(a) Assume the stack is initially empty, what is the sequence of popped values, and
what is the final state of the stack? (Identify which end is the top of the stack.)
(b) Suppose you were to replace the push and pop operations with enqueue and dequeue
respectively. What would be the sequence of dequeued values, and what would be the
final state of the queue? (Identify which end is the front of the queue.)
10- Use a stack to test for balanced parentheses, when scanning the following
expressions. Your solution should show the state of the stack each time it is
modified. The “state of the stack” must indicate which is the top element. Only
consider the parentheses [,],(,),{,} . Ignore the variables and operators.
(a) [ a + { b / ( c - d ) + e / (f + g ) } - h ]
(b) [ a { b + [ c ( d + e ) - f ] + g }

2
11- Suppose you have a stack in which the values 1 through 5 must be pushed on the
stack in that order, but that an item on the stack can be popped at any time. Give a
sequence of push and pop operations such that the values are popped in the
following order:
(a) 2, 4, 5, 3, 1
(b) 1, 5, 4, 2, 3
(c) 1, 3, 5, 4, 2 It might not be possible in each case.

12- (a) Suppose you have three stacks s1, s2, s2 with starting configuration shown on
the left, and finishing condition shown on the right. Give a sequence of push and
pop operations that take you from start to finish. For example, to pop the top
element of s1 and push it onto s3, you would write s3.push ( s1.pop()).
(b) Same question, but now suppose the finish configuration on s3 is BDAC (with B
on top) ?

13- Consider the following sequence of stack commands:


push(a), push(b), push(c), pop(), push(d), push(e), pop(), pop(), pop(), pop().
(a) What is the order in which the elements are popped? (Give a list and indicate
which was popped first.)
(b) Change the position of the pop() commands in the above sequence so that the
items are popped in the following order: b,d,c,a,e.

You might also like