You are on page 1of 12

Topic: Stacks Worksheet No.

Work sheet No. 1


STACK implementation using Array

Name: ____________________ Reg.No.: ______________________ Date: ____________

Fill up the following

Stack is an ______________________[1] data type with a bounded (predefined) capacity. It is a simple

data structure that allows _______________ [2] and _____________________ [3] elements in a

particular order. Every time an element is added, it goes on the _____________ [4] of the stack.

Complete the structure

_______________() [7]

__________________ [5]

____________() [6]

Stack Data Structure


List any four features of Stack

8.________________________________________________________________________________________

__________________________________________________________________________________________

9.________________________________________________________________________________________

__________________________________________________________________________________________

10._______________________________________________________________________________________

__________________________________________________________________________________________

11._______________________________________________________________________________________

__________________________________________________________________________________________

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 1

State the Applications of Stack

12

13

14

Complete the following


#define size 5
struct stack
{
int s[__________]; [15]
int ___________; [16]
}st;
17. Stack is using _______________principle with the help of a variable 'top'.
18. Initially top is set to ______________________.
Match the following
19 Top++; Stack is Full
stack[top] = value;
20 top == -1 POP()
21 i=top; Delete()
repeat till stack empty
stack[i];
top--;
22 Top==size-1 Peek()
23 stack[top]; Stack is empty
top--;
Create()
STACK()
POP()
PUSH()

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 1

24. void push(int data)

if(_____________________)

cout << "stack overflow\n Cannot enter new data";

return;

_____________;

stack[___________]=data;

25. int pop()

int tempVar;

if(_______________________)

cout << "stack is underflow (Empty)";

return(-1);

tempVar = stack[top];

______________;

return tempVar;

□□□□□□□

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 2

Work sheet No. 2

STACK implementation using Linked List

Name: ____________________ Reg.No.: ______________________ Date: ____________

1. Stack implemented using linked list works for __________________ size of data.
2. In linked list implementation of a stack, every new element is inserted as ___________
element.
3. The next field of the first element in linked list implementation of a stack must be
always __________
4. PUSH 25, 32, 50 and 99 and fill up the following

5. Pop() will return


Top

6. Pop(), Pop(), Push 75 will return Top

7. Pop() Push 54, Push 34 will return Top

Top

8. node *stack_list::push(node *top, int item)


{
node *tmp;
tmp = new (struct node);
tmp->info = __________;

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 2

tmp->link = _____________;
top = _________;
return ___________;
}
9. node *stack_list::pop(node *top)
{
node *tmp;
if (top == NULL)
cout<<"_______________ "<<endl;
else
{
tmp = top;
cout<<"Element Popped: "<<tmp->info<<endl;
top =_______________;
free(tmp);
}
Return______________;
}
10. void stack_list::traverse(node *top)
{
node *ptr;
ptr = top;
if (________________)
cout<<"Stack is empty"<<endl;
else
{
cout<<"Stack elements :"<<endl;
while (_________________)
{
cout<<ptr->info<<endl;
ptr =________________;
}
}
}

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 2

11. Word Search

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 3

Work sheet No. 3

Applications of STACK – Infix to Postfix – Evaluation of Postfix

Name: ____________________ Reg.No.: ______________________ Date: ____________

1. What is the infix expression of the given prefix expression: +A*BC

a. A*B+C b. A+B*C c. (A+B)*C d. A*(B+C)

2. What is the infix expression of the given postfix expression: ABC*+

a. A*B+C b. A+B*C c. (A+B)*C d. A*(B+C)

3. The infix expression of the given Postfix expression: AB+C* is ____________________

4. The postfix expression of the given Infix expression: A+B*C is ___________________

5. The postfix expression of the given Infix expression: (A+B)*C is AB*C+. State True or False _______

6. What is the postfix expression of the given Infix expression: A+(B-C)*D$(E*F)

a. ABCDEF-*$*+ b. ABC-DE*F$*+ c. AB-CDEF$**+ d. ABC-DEF*$*+

7. What is the postfix expression of the given Infix expression (A+B*C)$((A+B)*C)

a. ABCABC*++*$ b. ABC+*AB+C*$ c. ABC*+AB+C*$ d. AB+C*AB+C*$

8 what is the Prefix expression of the given Infix expression: A+B*C

a. +AB*C b. +*ABC c. *+ABC d. +A*BC

9. What is the Prefix expression of the given Infix expression: (A+B)*C

a. *+ABC b. +A*BC c. +AB*C d. +*ABC

10. What is the Prefix expression of the given Infix expression: A+(B-C)*D$(E*F)

a. +*-$*ABCDEF b. A+*-BCD$*EF c. +*-ABC$*DEF d. +A*-BC$D*EF

11. Consider the following infix expression. ((A+B)*C-(D-E))^(F+G) Note: ^ denotes the power.

Equivalent postfix and prefix expressions are respectively __________________, ____________________

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 3

12. Evaluate the following postfix expression if A = 2, B = 4, C = 6, D=1, and E=0:


AB+C/BE↑*DA+2↑+BCE*+A/−

13. Evaluate the following postfix expression. All numbers are single digits.
246+*5/32↑42-*+

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 4

Work sheet No. 4

Application of STACK – Balancing symbols

Name: ____________________ Reg.No.: ______________________ Date: ____________

1. Whenever we see a opening parenthesis, we ____________ it on stack.

2. For closing parenthesis, check the _____________of the stack, if it corresponding opening
parenthesis, _____________it from the top of the stack.

3. If parenthesis at the top is not corresponding opening parenthesis, return ____________.

4. After processing entire string, check if stack is ___________________. If the stack is empty,
return ____________. else ______________.

5. Complete the blanks

int evalPostfix(char postfix[], int size) {


stack<int> s;
int i = 0;
char ch;
int val;
while (i < size)
{
ch = postfix[i];
if (isdigit(ch))
s.push(ch-'0');
else
{
int op1 = __________________;
____________
int op2 = s.top();
s.pop();
val = eval(op1, op2, ch);
_________(val);
}
____________;
}

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No. 4

6. for the given input trace the stack contents and operations ( ( ) ( ( ) ) )
Input Input Operation Stack Symbol
(()(( ))) ( (

()(( ))) (

)(( ))) ) (

(( ))) ( PUSH
( ))) (
))) ) (
)) ) POP (
) )

7. Solve the following

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No.5

Work sheet No. 5

Recursion – Towers of Hanoi

Name: ____________________ Reg.No.: ______________________ Date: ____________

1. Whenever a function calls another function or itself as callee, the caller function
transfers execution control to ______________. This is called _____________.
2. F(n)

F(n-1) ○

F(n-2)

a?

○ b?

c? d?

3. The ________________________keeps the information about local variables, formal


parameters, return address and all information passed to _________________function.

4. Tower of Hanoi, is a mathematical puzzle which consists of ___________ towers and


more than one rings
5. List the rules of Tower of Hanoi

1
2
3

Mrs. Selva Mary. G 15CS201J- Data Structures


Topic: Stacks Worksheet No.5

6. Tower of hanoi puzzle with n disks can be solved in minimum ____________ steps.
7. If we have 2 disks −

• First we move the (Smaller / larger) disk to aux peg

• Then we move the (Smaller / larger) disk to destination peg

• And finally, we move the (Smaller / larger) from aux to destination peg.

8. Fill up the blanks

Procedure Hanoi(disk, source, dest, aux)

IF disk == 0, THEN

move disk from source to dest

ELSE

Hanoi(disk - 1,__________,___________, _________) // Step 1

move disk from source to dest // Step 2

Hanoi(disk - 1,__________, __________, _________) // Step 3

END IF

END Procedure

Mrs. Selva Mary. G 15CS201J- Data Structures

You might also like